nornir.core.inventory

class nornir.core.inventory.BaseAttributes(hostname: Optional[str] = None, port: Optional[int] = None, username: Optional[str] = None, password: Optional[str] = None, platform: Optional[str] = None)

  • dict() → Dict[str, Any]

  • hostname

  • password

  • platform

  • port

  • classmethod schema() → Dict[str, Any]

  • username

class nornir.core.inventory.ConnectionOptions(hostname: Optional[str] = None, port: Optional[int] = None, username: Optional[str] = None, password: Optional[str] = None, platform: Optional[str] = None, extras: Optional[Dict[str, Any]] = None)

  • dict() → Dict[str, Any]

  • extras

  • classmethod schema() → Dict[str, Any]

class nornir.core.inventory.Defaults(hostname: Optional[str] = None, port: Optional[int] = None, username: Optional[str] = None, password: Optional[str] = None, platform: Optional[str] = None, data: Optional[Dict[str, Any]] = None, connection_options: Optional[Dict[str, nornir.core.inventory.ConnectionOptions]] = None)

  • connection_options

  • data

  • dict() → Dict[str, Any]

  • classmethod schema() → Dict[str, Any]

class nornir.core.inventory.Group(name: str, hostname: Optional[str] = None, port: Optional[int] = None, username: Optional[str] = None, password: Optional[str] = None, platform: Optional[str] = None, groups: Optional[nornir.core.inventory.ParentGroups] = None, data: Optional[Dict[str, Any]] = None, connection_options: Optional[Dict[str, nornir.core.inventory.ConnectionOptions]] = None, defaults: Optional[nornir.core.inventory.Defaults] = None)

class nornir.core.inventory.Groups

class nornir.core.inventory.Host(name: str, hostname: Optional[str] = None, port: Optional[int] = None, username: Optional[str] = None, password: Optional[str] = None, platform: Optional[str] = None, groups: Optional[nornir.core.inventory.ParentGroups] = None, data: Optional[Dict[str, Any]] = None, connection_options: Optional[Dict[str, nornir.core.inventory.ConnectionOptions]] = None, defaults: Optional[nornir.core.inventory.Defaults] = None)

  • close_connection(connection: str) → None

    Close the connection

  • close_connections() → None

  • connections

  • defaults

  • dict() → Dict[str, Any]

  • extended_data() → Dict[str, Any]

    Returns the data associated with the object including inherited data

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

    Returns 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
  • get_connection(connection: str, configuration: nornir.core.configuration.Config) → Any

    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
    Raises:AttributeError – if it’s unknown how to establish a connection for the given type
    Parameters:connection – Name of the connection, for instance, netmiko, paramiko, napalm…
    Returns:An already established connection
  • get_connection_parameters(connection: Optional[str] = None) → nornir.core.inventory.ConnectionOptions

  • has_parent_group(group: Union[str, Group]) → bool

    Returns whether the object is a child of the Group group

  • items() → ItemsView[str, Any]

    Returns all the data accessible from a device, including the one inherited from parent groups

  • keys() → KeysView[str]

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

  • name

  • open_connection(connection: str, configuration: nornir.core.configuration.Config, hostname: Optional[str] = None, username: Optional[str] = None, password: Optional[str] = None, port: Optional[int] = None, platform: Optional[str] = None, extras: Optional[Dict[str, Any]] = None, default_to_host_attributes: bool = True) → nornir.core.plugins.connections.ConnectionPlugin

    Open a new connection.

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

    Raises:AttributeError – if it’s unknown how to establish a connection for the given type
    Returns:An already established connection
  • classmethod schema() → Dict[str, Any]

  • values() → ValuesView[Any]

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

class nornir.core.inventory.Hosts

class nornir.core.inventory.Inventory(hosts: nornir.core.inventory.Hosts, groups: Optional[nornir.core.inventory.Groups] = None, defaults: Optional[nornir.core.inventory.Defaults] = None, transform_function: Callable[[nornir.core.inventory.Host, Any], None] = None, transform_function_options: Optional[Dict[str, Any]] = None)

  • children_of_group(group: Union[str, nornir.core.inventory.Group]) → Set[nornir.core.inventory.Host]

    Returns set of hosts that belongs to a group including those that belong indirectly via inheritance

  • defaults

  • dict() → Dict[str, Any]

    Return serialized dictionary of inventory

  • filter(filter_obj: Callable[[nornir.core.inventory.Host, Any], bool] = None, filter_func: Callable[[nornir.core.inventory.Host, Any], bool] = None, \*kwargs*) → nornir.core.inventory.Inventory

  • groups

  • hosts

  • classmethod schema() → Dict[str, Any]

    Return serialized dictionary of inventory

class nornir.core.inventory.InventoryElement(hostname: Optional[str] = None, port: Optional[int] = None, username: Optional[str] = None, password: Optional[str] = None, platform: Optional[str] = None, groups: Optional[nornir.core.inventory.ParentGroups] = None, data: Optional[Dict[str, Any]] = None, connection_options: Optional[Dict[str, nornir.core.inventory.ConnectionOptions]] = None)

  • connection_options

  • data

  • dict() → Dict[str, Any]

  • extended_groups() → List[nornir.core.inventory.Group]

    Returns 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]

  • groups

  • classmethod schema() → Dict[str, Any]

class nornir.core.inventory.ParentGroups

  • add(group: nornir.core.inventory.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