How to use the nornir.core.configuration.Config function in nornir

To help you get started, we’ve selected a few nornir examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nornir-automation / nornir / tests / core / test_configuration.py View on Github external
def test_configuration_empty(self):
        config = Config(
            os.path.join(dir_path, "empty.yaml"), user_defined={"asd": "qwe"}
        )
        assert config.user_defined["asd"] == "qwe"
        assert config.num_workers == 20
        assert not config.raise_on_error
        assert (
            config.inventory.plugin == "nornir.plugins.inventory.simple.SimpleInventory"
        )
        assert config.inventory.get_plugin() == SimpleInventory
github nornir-automation / nornir / tests / core / test_configuration.py View on Github external
def test_configuration_normal(self):
        config = Config(os.path.join(dir_path, "config.yaml"))
        assert config.num_workers == 10
        assert not config.raise_on_error
        assert config.inventory.plugin == "something"
github nornir-automation / nornir / tests / core / test_configuration.py View on Github external
def test_configuration_bool_env(self):
        os.environ["NORNIR_RAISE_ON_ERROR"] = "0"
        config = Config()
        assert config.num_workers == 20
        assert not config.raise_on_error
github nornir-automation / nornir / tests / core / test_configuration.py View on Github external
def test_configuration_normal_override_argument(self):
        config = Config(
            os.path.join(dir_path, "config.yaml"), num_workers=20, raise_on_error=True
        )
        assert config.num_workers == 20
        assert config.raise_on_error
github nornir-automation / nornir / tests / core / test_configuration.py View on Github external
def test_configuration_normal_override_env(self):
        os.environ["NORNIR_NUM_WORKERS"] = "30"
        os.environ["NORNIR_RAISE_ON_ERROR"] = "1"
        os.environ["NORNIR_SSH_CONFIG_FILE"] = "/user/ssh_config"
        config = Config()
        assert config.num_workers == 30
        assert config.raise_on_error
        assert config.ssh.config_file == "/user/ssh_config"
        os.environ.pop("NORNIR_NUM_WORKERS")
        os.environ.pop("NORNIR_RAISE_ON_ERROR")
        os.environ.pop("NORNIR_SSH_CONFIG_FILE")
github nornir-automation / nornir / tests / core / deserializer / test_configuration.py View on Github external
def test_deserialize_basic(self):
        c = ConfigDeserializer.deserialize(
            core={"num_workers": 30},
            user_defined={"my_opt": True},
            logging={"file": "", "level": "info"},
            ssh={"config_file": "~/.ssh/alt_config"},
            inventory={"plugin": "nornir.plugins.inventory.ansible.AnsibleInventory"},
        )
        assert isinstance(c, Config)

        assert c.core.num_workers == 30
        assert not c.core.raise_on_error
        assert c.user_defined == {"my_opt": True}

        assert c.logging.level == logging.INFO
        assert c.logging.file == ""
        assert c.logging.format == DEFAULT_LOG_FORMAT
        assert not c.logging.to_console
        assert c.logging.loggers == ["nornir"]

        assert c.ssh.config_file == "~/.ssh/alt_config"

        assert c.inventory.plugin == AnsibleInventory
        assert c.inventory.options == {}
        assert c.inventory.transform_function is None
github nornir-automation / nornir / nornir / core / __init__.py View on Github external
def __init__(
        self, inventory: Inventory, config: Config = None, data: GlobalState = None
    ) -> None:
        self.data = data if data is not None else GlobalState()

        self.inventory = inventory

        self.config = config or Config()
github nornir-automation / nornir / nornir / core / deserializer / configuration.py View on Github external
inventory=InventoryConfig(
                __config_settings__=__config_settings__.pop("inventory", {}),
                **kwargs.pop("inventory", {}),
            ),
            logging=LoggingConfig(
                __config_settings__=__config_settings__.pop("logging", {}),
                **kwargs.pop("logging", {}),
            ),
            jinja2=Jinja2Config(
                __config_settings__=__config_settings__.pop("jinja2", {}),
                **kwargs.pop("jinja2", {}),
            ),
            __config_settings__=__config_settings__,
            **kwargs,
        )
        return configuration.Config(
            core=CoreConfig.deserialize(**c.core.dict()),
            inventory=InventoryConfig.deserialize(**c.inventory.dict()),
            ssh=SSHConfig.deserialize(**c.ssh.dict()),
            logging=LoggingConfig.deserialize(**c.logging.dict()),
            jinja2=Jinja2Config.deserialize(**c.jinja2.dict()),
            user_defined=c.user_defined,
        )