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, )
def __init__(self, inventory, config=None, logger=None, data=None): self.data = data if data is not None else GlobalState() self.logger = logger or logging.getLogger(__name__) self.inventory = inventory self.config = config or Config()
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()
def InitNornir( config_file: str = "", dry_run: bool = False, configure_logging: Optional[bool] = None, **kwargs: Dict[str, 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 """ register_default_connection_plugins() if callable(kwargs.get("inventory", {}).get("plugin", "")): kwargs["inventory"]["plugin"] = cls_to_string(kwargs["inventory"]["plugin"]) if callable(kwargs.get("inventory", {}).get("transform_function", "")): kwargs["inventory"]["transform_function"] = cls_to_string( kwargs["inventory"]["transform_function"] ) conf = Config.load_from_file(config_file, **kwargs) data = GlobalState(dry_run=dry_run) if configure_logging is not None: msg = ( "'configure_logging' argument is deprecated, please use " "'logging.enabled' parameter in the configuration instead: " "https://nornir.readthedocs.io/en/stable/configuration/index.html" ) warnings.warn(msg, DeprecationWarning) if conf.logging.enabled is None: if configure_logging is not None: conf.logging.enabled = configure_logging else: conf.logging.enabled = True conf.logging.configure() inv = conf.inventory.plugin.deserialize( transform_function=conf.inventory.transform_function, transform_function_options=conf.inventory.transform_function_options, config=conf, **conf.inventory.options, ) return Nornir(inventory=inv, config=conf, data=data)
def __init__( self, inventory: Inventory, config: Config = None, data: GlobalState = None, processors: Optional[Processors] = None, ) -> None: self.data = data if data is not None else GlobalState() self.inventory = inventory self.config = config or Config() self.processors = processors or Processors()
def InitNornir(config_file="", dry_run=False, configure_logging=True, **kwargs): """ Arguments: config_file(str): Path to the configuration file (optional) dry_run(bool): Whether to simulate changes or not **kwargs: Extra information to pass to the :obj:`nornir.core.configuration.Config` object Returns: :obj:`nornir.core.Nornir`: fully instantiated and configured """ register_default_connection_plugins() if callable(kwargs.get("inventory", {}).get("plugin", "")): kwargs["inventory"]["plugin"] = cls_to_string( kwargs["inventory"]["plugin"]) if callable(kwargs.get("inventory", {}).get("transform_function", "")): kwargs["inventory"]["transform_function"] = cls_to_string( kwargs["inventory"]["transform_function"]) conf = Config.load_from_file(config_file, **kwargs) data = GlobalState(dry_run=dry_run) if configure_logging: conf.logging.configure() inv = conf.inventory.plugin.deserialize( transform_function=conf.inventory.transform_function, config=conf, **conf.inventory.options, ) return Nornir(inventory=inv, config=conf, data=data)
import os import pytest from nornir import InitNornir from nornir.core.state import GlobalState global_data = GlobalState(dry_run=True) @pytest.fixture(scope="function", autouse=True) def nornir(): """Initializes nornir""" dir_path = os.path.dirname(os.path.realpath(__file__)) nornir = InitNornir( inventory={ "options": { "host_file": "{}/inventory_data/hosts.yaml".format(dir_path), "group_file": "{}/inventory_data/groups.yaml".format(dir_path), "defaults_file": "{}/inventory_data/defaults.yaml".format(dir_path), } }, dry_run=True, ) nornir.data = global_data return nornir