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:
- 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:
- 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:
- 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:
remote_hosts (
spicerack.remote.RemoteHosts
) -- the intance from where to create the host instance, must have only one host.spicerack_instance (
spicerack.Spicerack
) -- the spicerack instance to pass to the Host constructor.
- Return type:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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.