bundles/dhcpd add defaults file and some escaping
All checks were successful
bundlewrap/pipeline/head This commit looks good

This commit is contained in:
Sophie Schiller 2020-11-13 23:30:21 +01:00
parent ef211f7356
commit cbfc8c75ad
4 changed files with 62 additions and 3 deletions

View file

@ -1,5 +1,8 @@
#dhcpd.conf #dhcpd.conf
<%
import re
%>
ddns-update-style none; ddns-update-style none;
authoritative; authoritative;
@ -9,11 +12,15 @@ 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']}; range ${subnet['range_lower']} ${subnet['range_higher']};
% endif % endif
interface ${subnet['interface']}; interface "${subnet['interface']}";
default-lease-time ${subnet.get('default-lease-time', 600)}; default-lease-time ${subnet.get('default-lease-time', 600)};
max-lease-time ${subnet.get('max-lease-time', 3600)}; max-lease-time ${subnet.get('max-lease-time', 3600)};
% for option, value in sorted(subnet.get('options', {}).items()): % for option, value in sorted(subnet.get('options', {}).items()):
% if re.match('([^0-9\.,\ ])', value):
option ${option} "${value}";
% else:
option ${option} ${value}; option ${option} ${value};
% endif
% endfor % endfor
} }
% endfor % endfor

View file

@ -0,0 +1,18 @@
# Defaults for isc-dhcp-server (sourced by /etc/init.d/isc-dhcp-server)
# Path to dhcpd's config file (default: /etc/dhcp/dhcpd.conf).
#DHCPDv4_CONF=/etc/dhcp/dhcpd.conf
#DHCPDv6_CONF=/etc/dhcp/dhcpd6.conf
# Path to dhcpd's PID file (default: /var/run/dhcpd.pid).
#DHCPDv4_PID=/var/run/dhcpd.pid
#DHCPDv6_PID=/var/run/dhcpd6.pid
# Additional options to start dhcpd with.
# Don't use options -cf or -pf here; use DHCPD_CONF/ DHCPD_PID instead
#OPTIONS=""
# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
# Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACESv4="${listen_interfaces}"
INTERFACESv6=""

View file

@ -5,10 +5,33 @@ files = {
'dhcp_config': node.metadata.get('dhcpd'), 'dhcp_config': node.metadata.get('dhcpd'),
}, },
'needs': { 'needs': {
'pkg_apt:' 'pkg_apt:isc-dhcp-server'
},
'triggers': {
'svc_systemd:isc-dhcp-server:restart',
},
},
'/etc/default/isc-dhcp-server': {
'content_type': 'mako',
'context': {
'listen_interfaces': node.metadata.get('dhcpd', {}).get('listen_interfaces'),
},
'needs': {
'pkg_apt:isc-dhcp-server'
}, },
'triggers': { 'triggers': {
'svc_systemd:isc-dhcp-server:restart', 'svc_systemd:isc-dhcp-server:restart',
}, },
}, },
} }
svc_systemd = {
'isc-dhcp-server': {
'needs': {
'pkg_apt:isc-dhcp-server',
'file:/etc/dhcp/dhcpd.conf',
'file:/etc/default/isc-dhcp-server',
},
},
}

View file

@ -1,7 +1,7 @@
defaults = { defaults = {
'apt': { 'apt': {
'packages': { 'packages': {
'isc-dhcpd-server': {}, 'isc-dhcp-server': {},
}, },
}, },
} }
@ -23,3 +23,14 @@ def get_static_allocations(metadata):
} }
} }
@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'))
return {
'dhcpd': {
'listen_interfaces': ' '.join(sorted(listen_interfaces)),
}
}