napalm_yang/base.py
def load_dict(self, data, overwrite=False, auto_load_model=True):
        """
        Load a dictionary into the model.

        Args:
            data(dict): Dictionary to load
            overwrite(bool): Whether the data present in the model should be overwritten by the
                data in the dict or not.
            auto_load_model(bool): If set to true models will be loaded as they are needed

        Examples:

            >>> vlans_dict = {
            >>>     "vlans": { "vlan": { 100: {
            >>>                             "config": {
            >>>                                 "vlan_id": 100, "name": "production"}},
            >>>                          200: {
            >>>                             "config": {
            >>>                                 "vlan_id": 200, "name": "dev"}}}}}
            >>> config.load_dict(vlans_dict)
            >>> print(config.vlans.vlan.keys())
            ... [200, 100]
            >>> print(100, config.vlans.vlan[100].config.name)
            ... (100, u'production')
            >>> print(200, config.vlans.vlan[200].config.name)
            ... (200, u'dev')
        """
        for k, v in data.items():
            if k not in self._elements.keys() and not auto_load_model:
                raise AttributeError("Model {} is not loaded".format(k))

            elif k not in self._elements.keys() and auto_load_model:
                self._load_model(k)

            attr = getattr(self, k)
            _load_dict(attr, v)
def load_dict(self, data, overwrite=False, auto_load_model=True):
        """
        Load a dictionary into the model.

        Args:
            data(dict): Dictionary to load
            overwrite(bool): Whether the data present in the model should be overwritten by the
                data in the dict or not.
            auto_load_model(bool): If set to true models will be loaded as they are needed

        Examples:

            >>> vlans_dict = {
            >>>     "vlans": { "vlan": { 100: {
            >>>                             "config": {
            >>>                                 "vlan_id": 100, "name": "production"}},
            >>>                          200: {
            >>>                             "config": {
            >>>                                 "vlan_id": 200, "name": "dev"}}}}}
            >>> config.load_dict(vlans_dict)
            >>> print(config.vlans.vlan.keys())
            ... [200, 100]
            >>> print(100, config.vlans.vlan[100].config.name)
            ... (100, u'production')
            >>> print(200, config.vlans.vlan[200].config.name)
            ... (200, u'dev')
        """
        for k, v in data.items():
            if k not in self._elements.keys() and not auto_load_model:
                raise AttributeError("Model {} is not loaded".format(k))

            elif k not in self._elements.keys() and auto_load_model:
                self._load_model(k)

            attr = getattr(self, k)
            _load_dict(attr, v)
Load a dictionary into the model.

        Args:
            data(dict): Dictionary to load
            overwrite(bool): Whether the data present in the model should be overwritten by the
                data in the dict or not.
            auto_load_model(bool): If set to true models will be loaded as they are needed

        Examples:

            >>> vlans_dict = {
            >>>     "vlans": { "vlan": { 100: {
            >>>                             "config": {
            >>>                                 "vlan_id": 100, "name": "production"}},
            >>>                          200: {
            >>>                             "config": {
            >>>                                 "vlan_id": 200, "name": "dev"}}}}}
            >>> config.load_dict(vlans_dict)
            >>> print(config.vlans.vlan.keys())
            ... [200, 100]
            >>> print(100, config.vlans.vlan[100].config.name)
            ... (100, u'production')
            >>> print(200, config.vlans.vlan[200].config.name)
            ... (200, u'dev')