2020-11-13 21:11:56 +00:00
|
|
|
defaults = {
|
|
|
|
'apt': {
|
|
|
|
'packages': {
|
2020-11-13 22:30:21 +00:00
|
|
|
'isc-dhcp-server': {},
|
2020-11-13 21:11:56 +00:00
|
|
|
},
|
|
|
|
},
|
2021-01-17 08:12:32 +00:00
|
|
|
'bash_aliases': {
|
|
|
|
'leases': 'sudo dhcp-lease-list',
|
|
|
|
},
|
2020-11-13 21:11:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-07 17:44:38 +00:00
|
|
|
@metadata_reactor.provides(
|
|
|
|
'dhcpd/fixed_allocations',
|
|
|
|
)
|
2020-11-13 21:11:56 +00:00
|
|
|
def get_static_allocations(metadata):
|
|
|
|
allocations = {}
|
2020-11-15 12:23:24 +00:00
|
|
|
for rnode in repo.nodes:
|
|
|
|
if rnode.metadata.get('location', '') != metadata.get('location', ''):
|
|
|
|
continue
|
|
|
|
|
2020-11-13 21:11:56 +00:00
|
|
|
for identifier, interface in rnode.metadata.get('interfaces', {}).items():
|
|
|
|
if interface.get('dhcp', False):
|
2021-01-07 21:14:17 +00:00
|
|
|
try:
|
|
|
|
allocations[rnode.name] = {
|
|
|
|
'ipv4': sorted(interface['ips'])[0],
|
|
|
|
'mac': interface['mac'],
|
|
|
|
}
|
|
|
|
except KeyError:
|
|
|
|
pass
|
2020-11-15 11:07:02 +00:00
|
|
|
|
2020-11-13 21:11:56 +00:00
|
|
|
return {
|
|
|
|
'dhcpd': {
|
|
|
|
'fixed_allocations': allocations,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-15 11:01:14 +00:00
|
|
|
|
2021-01-07 17:44:38 +00:00
|
|
|
@metadata_reactor.provides(
|
|
|
|
'dhcpd/listen_interfaces',
|
|
|
|
)
|
2020-11-13 22:30:21 +00:00
|
|
|
def get_listen_interfaces(metadata):
|
|
|
|
listen_interfaces = []
|
|
|
|
for identfier, subnet in node.metadata.get('dhcpd/subnets', {}).items():
|
2020-11-15 11:01:32 +00:00
|
|
|
listen_interfaces.append(subnet['interface'])
|
2020-11-13 22:30:21 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
'dhcpd': {
|
|
|
|
'listen_interfaces': ' '.join(sorted(listen_interfaces)),
|
|
|
|
}
|
|
|
|
}
|
2020-11-15 11:01:14 +00:00
|
|
|
|
|
|
|
|
2021-01-07 17:44:38 +00:00
|
|
|
@metadata_reactor.provides(
|
|
|
|
'iptables/bundle_rules/dhcpd',
|
|
|
|
)
|
2020-11-15 11:01:14 +00:00
|
|
|
def iptables(metadata):
|
|
|
|
iptables = set()
|
|
|
|
for identfier, subnet in node.metadata.get('dhcpd/subnets', {}).items():
|
2020-11-15 11:01:32 +00:00
|
|
|
iptables.add('iptables -A INPUT -i {} -p udp --dport 67:68 -j ACCEPT'.format(subnet['interface']))
|
2020-11-15 11:01:14 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
'iptables': {
|
|
|
|
'bundle_rules': {
|
|
|
|
# iptables bundle relies on this being a list.
|
|
|
|
'dhcpd': sorted(list(iptables)),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|