Provide an interface for manipulating DHCP configuration snippets for our dynamic/temporary DHCP system.

exception spicerack.dhcp.DHCPError[source]

Bases: spicerack.exceptions.SpicerackError

Base class for DHCP object errors.

exception spicerack.dhcp.DHCPRestartError[source]

Bases: spicerack.dhcp.DHCPError

Raised when the includes generator on target machine returns non-zero.

class spicerack.dhcp.DHCP(hosts: spicerack.remote.RemoteHosts)[source]

Bases: object

A class which provides tools for manipulating DHCP configuration snippets by data center.

Create a DHCP instance.


hosts (spicerack.remote.RemoteHosts) -- The target datacenter's install servers.

config(dhcp_config: spicerack.dhcp.DHCPConfiguration) Iterator[None][source]

A context manager to perform actions while the given DHCP config is valid.


dhcp_config (spicerack.dhcp.DHCPConfiguration) -- The DHCP configuration to use.

push_configuration(configuration: spicerack.dhcp.DHCPConfiguration) None[source]

Push a specified file with specified content to DHCP server and call refresh_dhcp.


configuration (spicerack.dhcp.DHCPConfiguration) -- An instance which provides content and filename for a configuration.

refresh_dhcp() None[source]

Regenerate includes on target data center and restart DHCP, or raise if failure at any stage.

remove_configuration(configuration: spicerack.dhcp.DHCPConfiguration, force: bool = False) None[source]

Remove configuration from target DHCP server then call refresh_dhcp.

This will fail if contents do not match unless force is True.

  • configuration (spicerack.dhcp.DHCPConfiguration) -- An instance which provides content and filename for a configuration.

  • force (bool, default False) -- If set to True, will remove filename regardless.

class spicerack.dhcp.DHCPConfMgmt(datacenter: str, serial: str, fqdn: str, ip_address: ipaddress.IPv4Address)[source]

Bases: spicerack.dhcp.DHCPConfiguration

A configuration for management network DHCP entries.

  • datacenter (str) -- the name of the Datacenter the host is.

  • serial (str) -- the vendor serial of the host.

  • fqdn (str) -- the management console FQDN to use for this host.

  • ip_address (ipaddress.IPv4Address) -- the IP address to give the management interface.

property filename: str

Return the filename that corresponds to this configuration.

class spicerack.dhcp.DHCPConfOpt82(hostname: str, fqdn: str, switch_hostname: str, switch_iface: str, vlan: str, ttys: int = 1, distro: Optional[str] = None)[source]

Bases: spicerack.dhcp.DHCPConfiguration

A configuration generator for host installation DHCP entries.

  • hostname (str) -- the hostname to generate the DHCP matching block for.

  • fqdn (str) -- the FQDN of the same host.

  • switch_hostname (str) -- the hostname of the switch the host is connected to.

  • switch_iface (str) -- the name of the switch interface the host is connected to.

  • vlan (str) -- the name of the VLAN the host is configured for.

  • ttys (int) -- which ttyS to use for this host, accepted values are 0 and 1.

  • distro (str, optional) -- the codename of the Debian distribution to use for the PXE installer, if different from the default distribution configured by Puppet globally.

property filename: str

Return the proposed filename based on this configuration.

class spicerack.dhcp.DHCPConfiguration[source]

Bases: abc.ABC

abstract An abstract class which defines the interface for the DHCP configuration generators.

abstract property filename: str

Return a string of the proposed filename for this configuration, from the automation directory.

spicerack.dhcp.DHCP_TARGET_PATH = '/etc/dhcp/automation'

The path to the top of the DHCPd automation directory.



spicerack.dhcp.MGMT_HOSTNAME_RE = '\\.mgmt\\.{dc}\\.wmnet'

A regular expression when formatted with a dc parameter will match a management hostname.