Merge pull request 'bundle/dhcpd: improvements' (#19) from kunsi-dhcpd-improvements into main
All checks were successful
bundlewrap/pipeline/head This commit looks good

Reviewed-on: https://git.kunsmann.eu/kunsi/bundlewrap/pulls/19
This commit is contained in:
sophie 2020-11-15 12:34:41 +00:00
commit 75e199ae0d
5 changed files with 45 additions and 19 deletions

View file

@ -7,21 +7,22 @@ ddns-update-style none;
authoritative;
% for identfier, subnet in dhcp_config.get('subnets', {}).items():
% for identifier, subnet in dhcp_config.get('subnets', {}).items():
# subnet '${identifier}'
subnet ${subnet['subnet']} netmask ${subnet['netmask']} {
% if subnet.get('range_lower', None) and subnet.get('range_higher', None):
% if subnet.get('range_lower', None) and subnet.get('range_higher', None):
range ${subnet['range_lower']} ${subnet['range_higher']};
% endif
% endif
interface "${subnet['interface']}";
default-lease-time ${subnet.get('default-lease-time', 600)};
max-lease-time ${subnet.get('max-lease-time', 3600)};
% for option, value in sorted(subnet.get('options', {}).items()):
% if re.match('([^0-9\.,\ ])', value):
option ${option} "${value}";
% else:
option ${option} ${value};
% endif
% endfor
% for option, value in sorted(subnet.get('options', {}).items()):
% if re.match('([^0-9\.,\ ])', value):
option ${option} "${value}";
% else:
option ${option} ${value};
% endif
% endfor
}
% endfor

View file

@ -2,7 +2,7 @@ files = {
'/etc/dhcp/dhcpd.conf': {
'content_type': 'mako',
'context': {
'dhcp_config': node.metadata.get('dhcpd'),
'dhcp_config': node.metadata['dhcpd'],
},
'needs': {
'pkg_apt:isc-dhcp-server'
@ -14,7 +14,8 @@ files = {
'/etc/default/isc-dhcp-server': {
'content_type': 'mako',
'context': {
'listen_interfaces': node.metadata.get('dhcpd', {}).get('listen_interfaces'),
# Set by our own metadata reactor. Guaranteed to exist.
'listen_interfaces': node.metadata['dhcpd']['listen_interfaces'],
},
'needs': {
'pkg_apt:isc-dhcp-server'

View file

@ -10,27 +10,48 @@ defaults = {
@metadata_reactor
def get_static_allocations(metadata):
allocations = {}
for rnode in repo.nodes_in_group('home'):
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):
allocations[rnode.name] = {
'ipv4': sorted(interface['ips'])[0],
'mac': interface['mac'],
'ipv4': sorted(interface['ips'])[0],
'mac': interface['mac'],
}
return {
'dhcpd': {
'fixed_allocations': allocations,
}
}
@metadata_reactor
def get_listen_interfaces(metadata):
listen_interfaces = []
for identfier, subnet in node.metadata.get('dhcpd/subnets', {}).items():
listen_interfaces.append(subnet.get('interface'))
listen_interfaces.append(subnet['interface'])
return {
'dhcpd': {
'listen_interfaces': ' '.join(sorted(listen_interfaces)),
}
}
@metadata_reactor
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)),
},
}
}

View file

@ -13,6 +13,7 @@ groups['gce'] = {
},
},
},
'location': 'gce',
'nameservers': {
'8.8.8.8',
'8.8.4.4',
@ -33,6 +34,9 @@ groups['htz'] = {
'subgroups': {
'htz-cloud',
},
'metadata': {
'location': 'htz',
},
}
groups['htz-cloud'] = {
@ -70,6 +74,7 @@ groups['ovh'] = {
r"ovh\..*",
},
'metadata': {
'location': 'ovh',
'users': {
'debian': {
'delete': True,

View file

@ -94,8 +94,6 @@ nodes['home.router'] = {
'broadcast-address': '172.19.138.255',
'subnet-mask': '255.255.255.0',
},
'default-lease-time': 300,
'max-lease-time': 1800,
},
},
},