dhcp
Provide an interface for manipulating DHCP configuration snippets for our dynamic/temporary DHCP system.
- exception spicerack.dhcp.DHCPError[source]
Bases:
SpicerackError
Base class for DHCP object errors.
- exception spicerack.dhcp.DHCPRestartError[source]
Bases:
DHCPError
Raised when the includes generator on target machine returns non-zero.
- class spicerack.dhcp.DHCP(hosts: spicerack.remote.RemoteHosts, *, datacenter: str, lock: spicerack.locking.Lock | spicerack.locking.NoLock, 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:
hosts (
spicerack.remote.RemoteHosts
) -- the target datacenter's install servers.datacenter (
str
) -- the datacenter name.lock (
typing.Union
[spicerack.locking.Lock
,spicerack.locking.NoLock
]) -- the locking instance to use to acquire locks around delicate operations.dry_run (
bool
, default:True
) -- whether this is a DRY-RUN.
- config(dhcp_config: spicerack.dhcp.DHCPConfiguration) collections.abc.Iterator[None] [source]
A context manager to perform actions while the given DHCP config is active.
- Parameters:
dhcp_config (
spicerack.dhcp.DHCPConfiguration
) -- The DHCP configuration to use.- Return type:
- 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.- Return type:
- 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.
- Return type:
- class spicerack.dhcp.DHCPConfMac(hostname: str, ipv4: ipaddress.IPv4Address, mac: str, ttys: int, distro: str, media_type: str = 'installer', dhcp_filename: str = '', dhcp_options: dict[str, str] = <factory>, _template: str = '\\n host {s.hostname} {{\\n hardware ethernet {s.mac};\\n fixed-address {s.ipv4};{s.rendered_dhcp_filename}{s.rendered_dhcp_options}\\n }}\\n ') None [source]
Bases:
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 PXEdhcp (installer (empty string or None is allowed and removes the related)
config). (default options from the)
media_type (
str
, default:'installer'
) -- The media type to use e.g. installer, installer-11.0, rescuedhcp_filename (
str
, default:''
) -- the DHCP filename option to set.dhcp_options (
dict
[str
,str
], default:<factory>
) -- a dictionary of DHCP option settings to use.
- class spicerack.dhcp.DHCPConfMgmt(datacenter: str, serial: str, manufacturer: str, fqdn: str, ipv4: ipaddress.IPv4Address, _template: str = '\\n class "{s.fqdn}" {{\\n match if (lcase(option host-name) = "{s.hostname}");\\n }}\\n pool {{\\n allow members of "{s.fqdn}";\\n range {s.ipv4} {s.ipv4};\\n }}\\n ') None [source]
Bases:
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.manufacturer (
str
) -- the name of the manufacturer.fqdn (
str
) -- the management console FQDN to use for this host.ipv4 (
ipaddress.IPv4Address
) -- the IP address to give the management interface.
- class spicerack.dhcp.DHCPConfOpt82(hostname: str, ipv4: ipaddress.IPv4Address, switch_hostname: str, switch_iface: str, vlan: str, ttys: int, distro: str, media_type: str = 'installer', dhcp_filename: str = '', dhcp_filename_exclude_vendor: str = '', dhcp_options: dict[str, str] = <factory>, _template: str = '\\n host {s.hostname} {{\\n host-identifier option agent.circuit-id "{s.switch_hostname}:{s.switch_iface}:{s.vlan}";\\n fixed-address {s.ipv4};{s.rendered_dhcp_filename}{s.rendered_dhcp_options}\\n }}\\n ') None [source]
Bases:
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 PXEdhcp (installer (empty string or None is allowed and removes the related)
config). (default options from the)
media_type (
str
, default:'installer'
) -- the media type to use e.g.installer
,installer-11.0
,rescue
.dhcp_filename (
str
, default:''
) -- the DHCP filename option to set.dhcp_filename_exclude_vendor (
str
, default:''
) -- vendor to exclude from sending over the filename, e.g. d-idhcp_options (
dict
[str
,str
], default:<factory>
) -- a dictionary of DHCP option settings to use.
- class spicerack.dhcp.DHCPConfiguration[source]
Bases:
ABC
abstract
An abstract class which defines the interface for the DHCP configuration generators.