nornir.core.inventory

class nornir.core.inventory.BaseAttributes(hostname: str | None = None, port: int | None = None, username: str | None = None, password: str | None = None, platform: str | None = None)
dict() dict[str, Any]
hostname
password
platform
port
classmethod schema() dict[str, Any]
username
class nornir.core.inventory.ConnectionOptions(hostname: str | None = None, port: int | None = None, username: str | None = None, password: str | None = None, platform: str | None = None, extras: dict[str, Any] | None = None)
dict() dict[str, Any]
extras
classmethod schema() dict[str, Any]
class nornir.core.inventory.Defaults(hostname: str | None = None, port: int | None = None, username: str | None = None, password: str | None = None, platform: str | None = None, data: dict[str, Any] | None = None, connection_options: dict[str, nornir.core.inventory.ConnectionOptions] | None = None)
connection_options
data
dict() dict[str, Any]
classmethod schema() dict[str, Any]
class nornir.core.inventory.FilterObj(*args, **kwargs)
class nornir.core.inventory.Group(name: str, hostname: str | None = None, port: int | None = None, username: str | None = None, password: str | None = None, platform: str | None = None, groups: ParentGroups | None = None, data: dict[str, Any] | None = None, connection_options: dict[str, nornir.core.inventory.ConnectionOptions] | None = None, defaults: Defaults | None = None)
connections: dict[str, nornir.core.plugins.connections.ConnectionPlugin]
defaults
name
class nornir.core.inventory.Groups
class nornir.core.inventory.Host(name: str, hostname: str | None = None, port: int | None = None, username: str | None = None, password: str | None = None, platform: str | None = None, groups: ParentGroups | None = None, data: dict[str, Any] | None = None, connection_options: dict[str, nornir.core.inventory.ConnectionOptions] | None = None, defaults: Defaults | None = None)
close_connection(connection: str) None

Close the connection.

Raises:

nornir.core.exceptions.ConnectionNotOpen – no connection of the given type is open

close_connections() None
connections: dict[str, nornir.core.plugins.connections.ConnectionPlugin]
defaults
dict() dict[str, Any]
extended_data() dict[str, Any]

Return the data associated with the object including inherited data.

Returns:

The data of the object merged with the data inherited from its groups and from the defaults.

get(item: str, default: Any = None) Any

Return the value item from the host or hosts group variables.

Parameters:
  • item (str) – The variable to get

  • default (any) – Return value if item not found

Returns:

The value of item, or default if it could not be found.

get_connection(connection: str, configuration: Config) Any

Return an established connection of the given type.

The function of this method is twofold:

  1. If an existing connection is already established for the given type return it

  2. If none exists, establish a new connection of that type with default parameters and return it

Parameters:
  • connection – Name of the connection, for instance, netmiko, paramiko, napalm…

  • configuration – Configuration to pass to the connection plugin

Returns:

An already established connection

Raises:

AttributeError – if it’s unknown how to establish a connection for the given type

get_connection_parameters(connection: str | None = None) ConnectionOptions
has_parent_group(group: str | Group) bool

Return whether the object is a child of the Group group.

Returns:

True if the object is a child of group, False otherwise.

items() ItemsView[str, Any]

Return all the data accessible from a device.

This includes the data inherited from the parent groups.

Returns:

A view of the available key/value pairs.

keys() KeysView[str]

Return the keys of the attribute data and of the parent(s) groups.

Returns:

A view of the available keys.

name
open_connection(connection: str, configuration: Config, hostname: str | None = None, username: str | None = None, password: str | None = None, port: int | None = None, platform: str | None = None, extras: builtins.dict[str, Any] | None = None, default_to_host_attributes: bool = True) ConnectionPlugin

Open a new connection.

If default_to_host_attributes is set to True arguments will default to host attributes if not specified.

Returns:

The newly opened connection

Raises:
classmethod schema() dict[str, Any]
values() ValuesView[Any]

Return the values of the attribute data and of the parent(s) groups.

Returns:

A view of the available values.

class nornir.core.inventory.Hosts
class nornir.core.inventory.Inventory(hosts: Hosts, groups: Groups | None = None, defaults: Defaults | None = None, transform_function: TransformFunction | None = None, transform_function_options: dict[str, Any] | None = None)
children_of_group(group: str | Group) set[nornir.core.inventory.Host]

Return the set of hosts that belong to a group.

This includes the hosts that belong to it indirectly via inheritance.

Returns:

The hosts that belong to group.

defaults
dict() dict[str, Any]

Return a serialized dictionary of the inventory.

Returns:

The hosts, groups and defaults of the inventory serialized as dictionaries.

filter(filter_obj: FilterObj | None = None, filter_func: FilterObj | None = None, **kwargs: Any) Inventory
groups
hosts
classmethod schema() dict[str, Any]

Return the schema of a serialized inventory.

Returns:

The schema of the hosts, groups and defaults of an inventory.

class nornir.core.inventory.InventoryElement(hostname: str | None = None, port: int | None = None, username: str | None = None, password: str | None = None, platform: str | None = None, groups: ParentGroups | None = None, data: dict[str, Any] | None = None, connection_options: dict[str, nornir.core.inventory.ConnectionOptions] | None = None)
connection_options
data
dict() dict[str, Any]
extended_groups() list[nornir.core.inventory.Group]

Return the groups this host belongs to by virtue of inheritance.

This list is ordered based on the inheritance rules and groups are not duplicated. For instance, given a host with the following groups:

hostA:
groups:
  • group_a

  • group_b

group_a:
groups:
  • group_1

  • group_2

group_b:
groups:
  • group_2

  • group_3

group_1:
groups:
  • group_X

this will return [group_a, group_1, group_X, group_2, group_b, group_3]

Returns:

The groups this host belongs to, directly or through inheritance.

groups
classmethod schema() dict[str, Any]
class nornir.core.inventory.ParentGroups(iterable=(), /)
add(group: Group) None

Add the ParentGroup.

The group will only be appended if it does not exist.

Parameters:

group – Parent Group object to add

Returns:

None

class nornir.core.inventory.TransformFunction(*args, **kwargs)