def InitNornir(
    config_file: str = "",
    dry_run: bool = False,
    **kwargs: Any,
) -> Nornir:
    """
    Arguments:
        config_file(str): Path to the configuration file (optional)
        dry_run(bool): Whether to simulate changes or not
        configure_logging: Whether to configure logging or not. This argument is being
            deprecated. Please use logging.enabled parameter in the configuration
            instead.
        **kwargs: Extra information to pass to the
            :obj:`nornir.core.configuration.Config` object

    Returns:
        :obj:`nornir.core.Nornir`: fully instantiated and configured
    """
    ConnectionPluginRegister.auto_register()

    if config_file:
        config = Config.from_file(config_file, **kwargs)
    else:
        config = Config.from_dict(**kwargs)

    data = GlobalState(dry_run=dry_run)

    config.logging.configure()

    return Nornir(
        inventory=load_inventory(config),
        runner=load_runner(config),
        config=config,
        data=data,
    )
Example #2
0
 def test_order_of_resolution_code_is_higher_than_env(self):
     os.environ["NORNIR_CORE_RAISE_ON_ERROR"] = "0"
     config = Config.from_file(os.path.join(dir_path, "config.yaml"),
                               core={"raise_on_error": True})
     os.environ.pop("NORNIR_CORE_RAISE_ON_ERROR")
     assert config.core.raise_on_error is True
Example #3
0
 def test_get_user_defined_from_file(self):
     config = Config.from_file(os.path.join(dir_path, "config.yaml"))
     assert config.user_defined["asd"] == "qwe"
Example #4
0
 def test_configuration_file_override_argument(self):
     config = Config.from_file(
         os.path.join(dir_path, "config.yaml"),
         core={"raise_on_error": True},
     )
     assert config.core.raise_on_error