Core¶
InitNornir¶
-
init_nornir.
InitNornir
(dry_run: bool = False, configure_logging: Optional[bool] = None, **kwargs) → nornir.core.Nornir¶ Parameters: - 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
nornir.core.configuration.Config
object
Returns: fully instantiated and configured
Return type:
Nornir¶
-
class
nornir.core.
Nornir
(inventory: nornir.core.inventory.Inventory, config: nornir.core.configuration.Config = None, data: nornir.core.state.GlobalState = None, processors: Optional[nornir.core.processor.Processors] = None)¶ This is the main object to work with. It contains the inventory and it serves as task dispatcher.
Parameters: - inventory (
nornir.core.inventory.Inventory
) – Inventory to work with - data (GlobalState) – shared data amongst different iterations of nornir
- dry_run (
bool
) – Whether if we are testing the changes or not - config (
nornir.core.configuration.Config
) – Configuration object
-
inventory
¶ Inventory to work with
Type: nornir.core.inventory.Inventory
-
data
¶ shared data amongst different iterations of nornir
Type: nornir.core.GlobalState
-
dry_run
¶ Whether if we are testing the changes or not
Type: bool
-
config
¶ Configuration parameters
Type: nornir.core.configuration.Config
-
close_connections
(on_good=True, on_failed=False)¶
-
dict
()¶ Return a dictionary representing the object.
-
filter
(*args, **kwargs)¶ See
nornir.core.inventory.Inventory.filter()
Returns: A new object with same configuration as self
but filtered inventory.Return type: Nornir
-
classmethod
get_validators
()¶
-
run
(task, num_workers=None, raise_on_error=None, on_good=True, on_failed=False, **kwargs)¶ Run task over all the hosts in the inventory.
Parameters: - task (
callable
) – function or callable that will be run against each device in the inventory - num_workers (
int
) – Override for how many hosts to run in parallel for this task - raise_on_error (
bool
) – Override raise_on_error behavior - on_good (
bool
) – Whether to run or not this task on hosts marked as good - on_failed (
bool
) – Whether to run or not this task on hosts marked as failed - **kwargs – additional argument to pass to
task
when calling it
Raises: nornir.core.exceptions.NornirExecutionError
– if at least a task fails and self.config.core.raise_on_error is set toTrue
Returns: results of each execution
Return type: - task (
-
state
¶
-
classmethod
validate
(v)¶
-
with_processors
(processors: List[nornir.core.processor.Processor]) → nornir.core.Nornir¶ Given a list of Processor objects return a copy of the nornir object with the processors assigned to the copy. The orinal object is left unmodified.
- inventory (
Data¶
-
class
nornir.core.state.
GlobalState
(dry_run: bool = False, failed_hosts: Set[str] = None)¶ This class is just a placeholder to share data amongst different versions of Nornir after running
filter
multiple times.-
failed_hosts
¶ Hosts that have failed to run a task properly
-
dict
() → Dict[str, Any]¶ Return a dictionary representing the object.
-
recover_host
(host: str) → None¶ Remove
host
from list of failed hosts.
-
reset_failed_hosts
() → None¶ Reset failed hosts and make all hosts available for future tasks.
-