bundlewrap/bundles/dhcpd/metadata.py

55 lines
1.4 KiB
Python
Raw Normal View History

defaults = {
'apt': {
'packages': {
'isc-dhcp-server': {},
},
},
'bash_aliases': {
'leases': 'sudo dhcp-lease-list | tail -n +4 | sort -k 2,2',
},
}
@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
2021-02-12 19:37:36 +00:00
for iface_name, iface_config in rnode.metadata.get('interfaces', {}).items():
if iface_config.get('dhcp', False):
try:
2021-02-12 19:37:36 +00:00
allocations[f'{rnode.name}_{iface_name}'] = {
'ipv4': sorted(iface_config['ips'])[0],
'mac': iface_config['mac'],
}
except KeyError:
pass
return {
'dhcpd': {
'fixed_allocations': allocations,
}
}
2020-11-15 11:01:14 +00:00
@metadata_reactor.provides(
'iptables/bundle_rules/dhcpd',
)
2020-11-15 11:01:14 +00:00
def iptables(metadata):
2021-02-12 19:37:36 +00:00
rules = set()
2021-04-20 16:17:52 +00:00
for subnet in node.metadata.get('dhcpd/subnets', {}):
rules.add('iptables -A INPUT -i {} -p udp --dport 67:68 -j ACCEPT'.format(subnet))
2020-11-15 11:01:14 +00:00
return {
'iptables': {
'bundle_rules': {
2021-04-20 16:17:52 +00:00
# can't use port_rules here, because we're generating interface based rules.
2021-02-12 19:37:36 +00:00
'dhcpd': sorted(list(rules)),
2020-11-15 11:01:14 +00:00
},
}
}