netbox

Netbox module.

class spicerack.netbox.Netbox(url: str, token: str, *, dry_run: bool = True)[source]

Class which wraps Netbox API operations.

Create Netbox instance.

Parameters
  • url (str) -- The Netbox top level URL (with scheme and port if necessary)

  • token (str) -- A Netbox API token

  • dry_run (bool, optional) -- set to False to cause writes to Netbox to occur

property api

Getter for the Netbox API property.

Todo

When feasible expose instead higher level functionalities.

Returns

the Netbox API instance.

Return type

pynetbox.api

fetch_host_detail(hostname: str) → Dict[source]

Return a dict containing details about the host.

Parameters

hostname (str) -- the name of the host to retrieve.

Returns

data about the host

Return type

dict

Raises
fetch_host_status(hostname: str)str[source]

Return the current status of a host as a string.

Parameters

hostname (str) -- the name of the host status

Returns

the normalized status name

Return type

str

Raises
put_host_status(hostname: str, status: str)None[source]

Set the device status.

Note

This method does not operate on virtual machines since they are updated automatically from Ganeti into Netbox.

Parameters
  • hostname (str) -- the name of the host to operate on

  • status (str) -- A status label or name

Raises
exception spicerack.netbox.NetboxAPIError[source]

Usually a wrapper for pynetbox.RequestError, errors that occur when accessing the API.

exception spicerack.netbox.NetboxError[source]

General errors raised by this module.

exception spicerack.netbox.NetboxHostNotFoundError[source]

Raised when a host is not found for an operation.