napalm_yang/base.py
def add_model(self, model, force=False):
        """
        Add a model.

        The model will be asssigned to a class attribute with the YANG name of the model.

        Args:
            model (PybindBase): Model to add.
            force (bool): If not set, verify the model is in SUPPORTED_MODELS

        Examples:

            >>> import napalm_yang
            >>> config = napalm_yang.base.Root()
            >>> config.add_model(napalm_yang.models.openconfig_interfaces)
            >>> config.interfaces
            <pyangbind.lib.yangtypes.YANGBaseClass object at 0x10bef6680>
        """
        if isinstance(model, str):
            self._load_model(model)
            return

        try:
            model = model()
        except Exception:
            pass

        if model._yang_name not in [a[0] for a in SUPPORTED_MODELS] and not force:
            raise ValueError(
                "Only models in SUPPORTED_MODELS can be added without `force=True`"
            )

        for k, v in model:
            self._elements[k] = v
            setattr(self, k, v)
def add_model(self, model, force=False):
        """
        Add a model.

        The model will be asssigned to a class attribute with the YANG name of the model.

        Args:
            model (PybindBase): Model to add.
            force (bool): If not set, verify the model is in SUPPORTED_MODELS

        Examples:

            >>> import napalm_yang
            >>> config = napalm_yang.base.Root()
            >>> config.add_model(napalm_yang.models.openconfig_interfaces)
            >>> config.interfaces
            <pyangbind.lib.yangtypes.YANGBaseClass object at 0x10bef6680>
        """
        if isinstance(model, str):
            self._load_model(model)
            return

        try:
            model = model()
        except Exception:
            pass

        if model._yang_name not in [a[0] for a in SUPPORTED_MODELS] and not force:
            raise ValueError(
                "Only models in SUPPORTED_MODELS can be added without `force=True`"
            )

        for k, v in model:
            self._elements[k] = v
            setattr(self, k, v)
Add a model.

        The model will be asssigned to a class attribute with the YANG name of the model.

        Args:
            model (PybindBase): Model to add.
            force (bool): If not set, verify the model is in SUPPORTED_MODELS

        Examples:

            >>> import napalm_yang
            >>> config = napalm_yang.base.Root()
            >>> config.add_model(napalm_yang.models.openconfig_interfaces)
            >>> config.interfaces
            <pyangbind.lib.yangtypes.YANGBaseClass object at 0x10bef6680>