hosts

Hosts module.

exception spicerack.hosts.HostError[source]

Bases: SpicerackError

Custom exception class for errors related to the Host instance.

class spicerack.hosts.Host(name: str, spicerack_instance: spicerack.Spicerack, *, netbox_read_write: bool = False) None[source]

Bases: object

A class to represent a host across various services.

The class ensures that the host exists in our source of truth (Netbox) and exposes various services that will have the host as target for easy of use when managing a single host.

Initialize the instance.

Parameters:
  • name (str) -- the short hostname of the host.

  • spicerack_instance (spicerack.Spicerack) -- the spicerack instance.

  • netbox_read_write (bool, default: False) -- whether the Netbox related operation should be performed with a read-write token (True) or a read-only one (False).

Raises:

spicerack.netbox.NetboxError -- if unable to find the host in Netbox or load its data.

alerting() spicerack.alerting.AlertingHosts[source]

Get an instance to manage both Alertmanager and Icinga alerts for this host.

Examples

>>> with host.alerting.downtimed(reason, duration=duration):
...     # do something
Return type:

spicerack.alerting.AlertingHosts

Returns:

the alerting hosts instance.

alertmanager() spicerack.alertmanager.AlertmanagerHosts[source]

Get an instance to manage Alertmanager alerts for this host.

Examples

>>> with host.alertmanager.downtimed(reason, duration=duration):
...     # do something
Return type:

spicerack.alertmanager.AlertmanagerHosts

Returns:

the Alertmanager hosts instance.

apt_get() spicerack.apt.AptGetHosts[source]

Get an instance to manage Debian packages on the host via apt-get.

Examples

>>> host.apt_get.update()
Return type:

spicerack.apt.AptGetHosts

Returns:

the apt-get instance.

classmethod from_remote(remote_hosts: spicerack.remote.RemoteHosts, spicerack_instance: spicerack.Spicerack) spicerack.hosts.Host[source]

Initialize the Host instance from a RemoteHosts instance.

Parameters:
Return type:

spicerack.hosts.Host

Returns:

the Host instance.

Raises:

spicerack.hosts.HostError -- if the remote hosts doesn't have a single host.

icinga() spicerack.icinga.IcingaHosts[source]

Get an instance to manage Icinga alerts for this host.

Examples

>>> with host.icinga.downtimed(reason, duration=duration):
...     # do something
Return type:

spicerack.icinga.IcingaHosts

Returns:

the Icinga hosts instance.

ipmi() spicerack.ipmi.Ipmi[source]

Get an instance to manage the host using IPMI on the management interface of the host.

Examples

>>> host.ipmi.power_status()
'on'
Return type:

spicerack.ipmi.Ipmi

Returns:

the ipmi instance.

Raises:

spicerack.hosts.HostError -- if the host is a Virtual Machine.

mysql() spicerack.mysql.MysqlRemoteHosts[source]

Get an instance to manage Mysql/Mariadb on the host.

There is no check that the host has a Mysql/Mariadb server when calling this property. The Mysql/Mariadb specific features will fail if the host doesn't have a server installed/running.

Examples

>>> host.mysql.run_query(query)
Return type:

spicerack.mysql.MysqlRemoteHosts

Returns:

the mysql remote hosts instance.

netbox() spicerack.netbox.NetboxServer[source]

Get an instance with all the Netbox data of the host.

Examples

>>> host.netbox.status
'active'
Return type:

spicerack.netbox.NetboxServer

Returns:

the netbox server instance.

puppet() spicerack.puppet.PuppetHosts[source]

Get an instance to manage Puppet on the host.

Examples

>>> host.puppet.run()
Return type:

spicerack.puppet.PuppetHosts

Returns:

the Puppet hosts instance.

redfish() spicerack.redfish.Redfish[source]

Get an instance to manage the host using Redfish on the management interface of the host.

Examples

>>> host.redfish.check_connection()
Return type:

spicerack.redfish.Redfish

Returns:

the Redfish instance.

Raises:

spicerack.SpicerackError -- if the host is a Virtual Machine or the manufacturer is not supported.

remote() spicerack.remote.RemoteHosts[source]

Get an instance to execute ssh commands on the host. It ensures that the host is present in PuppetDB.

Examples

>>> host.remote.run_sync('command')
Return type:

spicerack.remote.RemoteHosts

Returns:

the remote hosts instance.

property fqdn: str

The fully qualified domain name (FQDN) of the host.

Examples

>>> host.fqdn
'example1001.eqiad.wmnet'
Returns:

the FQDN as defined in Netbox.

property hostname: str

The short hostname of the host.

Examples

>>> host.hostname
'example1001'
Returns:

the hostname as reported on Netbox.

property mgmt_fqdn: str

The fully qualified domain name (FQDN) of the management interface of the host.

Examples

>>> host.mgmt_fqdn
'example1001.mgmt.eqiad.wmnet'
Returns:

the FQDN of the management interface as defined in Netbox.