dhcp

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, *, dry_run: bool = True)[source]

Bases: object

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

Create a DHCP instance.

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

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

Parameters

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.

Parameters

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.

Parameters
  • 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.DHCPConfMac(hostname: str, ipv4: ipaddress.IPv4Address, mac: str, ttys: int, distro: str)[source]

Bases: spicerack.dhcp.DHCPConfiguration

A configuration generator for host installation DHCP entries via MAC address.

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

  • ipv4 (ipaddress.IPv4Address) -- the IPv4 to be assigned to the host.

  • mac (str) -- the MAC address of the host's interface.

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

  • distro (str) -- the codename of the Debian distribution to use for the PXE installer.

property filename: str

Return the proposed filename based on this configuration.

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

Bases: spicerack.dhcp.DHCPConfiguration

A configuration for management network DHCP entries.

Parameters
  • 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.

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

property filename: str

Return the filename that corresponds to this configuration.

Returns

the filename.

Return type

str

property lserial: str

Return the serial as lowercase.

Returns

the serial.

Return type

str

class spicerack.dhcp.DHCPConfOpt82(hostname: str, ipv4: ipaddress.IPv4Address, switch_hostname: str, switch_iface: str, vlan: str, ttys: int, distro: str)[source]

Bases: spicerack.dhcp.DHCPConfiguration

A configuration generator for host installation DHCP entries via DHCP Option 82.

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

  • ipv4 (ipaddress.IPv4Address) -- the IPv4 to be assigned to the 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) -- the codename of the Debian distribution to use for the PXE installer.

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.

Type

str

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

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

Type

str