66 lines
1.7 KiB
Python
66 lines
1.7 KiB
Python
defaults = {
|
|
'apt': {
|
|
'packages': {
|
|
'isc-dhcp-server': {},
|
|
},
|
|
},
|
|
}
|
|
|
|
|
|
@metadata_reactor.provides(
|
|
'dhcpd/fixed_allocations',
|
|
)
|
|
def get_static_allocations(metadata):
|
|
allocations = {}
|
|
for rnode in repo.nodes:
|
|
if rnode.metadata.get('location', '') != metadata.get('location', ''):
|
|
continue
|
|
|
|
for identifier, interface in rnode.metadata.get('interfaces', {}).items():
|
|
if interface.get('dhcp', False):
|
|
try:
|
|
allocations[rnode.name] = {
|
|
'ipv4': sorted(interface['ips'])[0],
|
|
'mac': interface['mac'],
|
|
}
|
|
except KeyError:
|
|
pass
|
|
|
|
return {
|
|
'dhcpd': {
|
|
'fixed_allocations': allocations,
|
|
}
|
|
}
|
|
|
|
|
|
@metadata_reactor.provides(
|
|
'dhcpd/listen_interfaces',
|
|
)
|
|
def get_listen_interfaces(metadata):
|
|
listen_interfaces = []
|
|
for identfier, subnet in node.metadata.get('dhcpd/subnets', {}).items():
|
|
listen_interfaces.append(subnet['interface'])
|
|
|
|
return {
|
|
'dhcpd': {
|
|
'listen_interfaces': ' '.join(sorted(listen_interfaces)),
|
|
}
|
|
}
|
|
|
|
|
|
@metadata_reactor.provides(
|
|
'iptables/bundle_rules/dhcpd',
|
|
)
|
|
def iptables(metadata):
|
|
iptables = set()
|
|
for identfier, subnet in node.metadata.get('dhcpd/subnets', {}).items():
|
|
iptables.add('iptables -A INPUT -i {} -p udp --dport 67:68 -j ACCEPT'.format(subnet['interface']))
|
|
|
|
return {
|
|
'iptables': {
|
|
'bundle_rules': {
|
|
# iptables bundle relies on this being a list.
|
|
'dhcpd': sorted(list(iptables)),
|
|
},
|
|
}
|
|
}
|