netbox

Netbox module.

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

Bases: object

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 device_status_choices

Return the dictionary of device status choices.

Returns

the device status choices, keyed by label, with the value as the field value.

Return type

dict

Raises
fetch_host(hostname: str) → pynetbox.core.response.Record[source]

Fetch a host (dcim.devices) object

Parameters

hostname (str) -- the name of the host to fetch

Returns

the host object from the API

Return type

pynetbox.core.response.Record

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

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

  • status (str) -- A status name, from the keys on .device_status_choices

Raises
exception spicerack.netbox.NetboxAPIError[source]

Bases: spicerack.netbox.NetboxError

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

exception spicerack.netbox.NetboxError[source]

Bases: spicerack.exceptions.SpicerackError

General errors raised by this module.