netbox

Netbox module.

class homer.netbox.BaseNetboxData(api: pynetbox.core.api.Api, base_paths: dict[str, str])[source]

Bases: UserDict

Base class to gather data dynamically from Netbox.

Initialize the dictionary.

Parameters:
  • api (pynetbox.core.api.Api) -- the Netbox API instance.

  • base_paths (dict[str, str]) -- The path to the public and private directories.

class homer.netbox.BaseNetboxDeviceData(api: pynetbox.core.api.Api, base_paths: dict[str, str], device: homer.devices.Device)[source]

Bases: BaseNetboxData

Base class to gather device-specific data dynamically from Netbox.

Initialize the dictionary.

Parameters:
  • api (pynetbox.core.api.Api) -- the Netbox API instance.

  • base_paths (dict[str, str]) -- The path to the public and private directories.

  • device (homer.devices.Device) -- the device for which to gather the data.

fetch_device_interfaces() dict[source]

Fetch interfaces from Netbox.

Return type:

dict

Returns:

the interfaces dictionary.

class homer.netbox.NetboxData(api: pynetbox.core.api.Api, base_paths: dict[str, str])[source]

Bases: BaseNetboxData

Dynamic dictionary to gather the required generic data from Netbox.

Initialize the dictionary.

Parameters:
  • api (pynetbox.core.api.Api) -- the Netbox API instance.

  • base_paths (dict[str, str]) -- The path to the public and private directories.

class homer.netbox.NetboxDeviceData(api: pynetbox.core.api.Api, base_paths: dict[str, str], device: homer.devices.Device)[source]

Bases: BaseNetboxDeviceData

Dynamic dictionary to gather the required device-specific data from Netbox.

Initialize the dictionary.

Parameters:
  • api (pynetbox.core.api.Api) -- the Netbox API instance.

  • base_paths (dict[str, str]) -- The path to the public and private directories.

  • device (homer.devices.Device) -- the device for which to gather the data.

class homer.netbox.NetboxInventory(api: pynetbox.core.api.Api, device_roles: Sequence[str], device_statuses: Sequence[str])[source]

Bases: object

Use Netbox as inventory to gather the list of devices to manage.

Initialize the instance.

Parameters:
  • api (pynetbox.core.api.Api) -- the Netbox API instance.

  • config -- Homer's configuration section about Netbox

  • device_roles (typing.Sequence[str]) -- a sequence of Netbox device role slug strings to filter the devices.

  • device_statuses (typing.Sequence[str]) -- a sequence of Netbox device status label or value strings to filter the devices.

get_devices() Dict[str, Dict[str, str]][source]

Get the devices based on role, status and virtual chassis membership.

Return type:

typing.Dict[str, typing.Dict[str, str]]

Returns:

A dictionary with the device FQDN as keys and a metadata dictionary as value.

homer.netbox.get_gql_query(name: str) str[source]

Get one of the GraphQL query provided by Homer.

Parameters:

name (str) -- the name of the query file without extension.

Return type:

str

Returns:

the query as string.

homer.netbox.gql_execute(api: pynetbox.core.api.Api, query: str, variables: dict | None = None) dict[str, Any][source]

Parse the query into a gql query, execute and return the results.

Parameters:
  • api (pynetbox.core.api.Api) -- the Netbox API instance.

  • query (str) -- a string representing the gql query.

  • variables (typing.Optional[dict], default: None) -- A list of variables to send.

Raises:

homer.exceptions.HomerError -- if failed to query Netbox or no data was returned.

Return type:

dict[str, typing.Any]

Results:

The results of the query.