bundles/dhcpd add initial items, metadata and template

This commit is contained in:
Sophie Schiller 2020-11-13 22:11:56 +01:00
parent 6ba0f6df1d
commit dcf944b198
6 changed files with 87 additions and 0 deletions

Binary file not shown.

View file

@ -0,0 +1,26 @@
#dhcpd.conf
ddns-update-style none;
authoritative;
% for identfier, subnet in dhcp_config.get('subnets', {}).items():
subnet ${subnet['subnet']} netmask ${subnet['netmask']} {
% if subnet.get('range_lower', None) and subnet.get('range_higher', None):
range ${subnet['range_lower']} ${subnet['range_higher']};
% 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()):
option ${option} ${value};
% endfor
}
% endfor
% for identifier, allocation in dhcp_config.get('fixed_allocations', {}).items():
host ${identifier} {
hardware ethernet ${allocation['mac']};
fixed-address ${allocation['ipv4']};
}
% endfor

14
bundles/dhcpd/items.py Normal file
View file

@ -0,0 +1,14 @@
files = {
'/etc/dhcp/dhcpd.conf': {
'content_type': 'mako',
'context': {
'dhcp_config': node.metadata.get('dhcpd'),
},
'needs': {
'pkg_apt:'
},
'triggers': {
'svc_systemd:isc-dhcp-server:restart',
},
},
}

25
bundles/dhcpd/metadata.py Normal file
View file

@ -0,0 +1,25 @@
defaults = {
'apt': {
'packages': {
'isc-dhcpd-server': {},
},
},
}
@metadata_reactor
def get_static_allocations(metadata):
allocations = {}
for rnode in repo.nodes_in_group('home'):
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'],
}
return {
'dhcpd': {
'fixed_allocations': allocations,
}
}

View file

@ -49,6 +49,7 @@ groups['home'] = {
'lldp',
},
'metadata': {
'location': 'home',
'nameservers': {
'172.19.138.1',
},

View file

@ -3,6 +3,7 @@ nodes['home.router'] = {
'bundles': {
'iptables',
'pppd',
'dhcpd',
},
'groups': set(),
'metadata': {
@ -45,6 +46,26 @@ nodes['home.router'] = {
'password': vault.decrypt('encrypt$gAAAAABfruaXEDkaFksFMU8g97ydWyJF8p2KcSDJJBlzaOLDsLL6oCDYjG1kMPVESOzqjn8ThtSht1uZDuMCstA-sATmLS-EWQ=='),
'interface': 'enp1s0.100',
},
'dhcpd': {
'subnets': {
'home': {
'subnet': '172.19.138.0',
'netmask': '255.255.255.0',
'range_lower': '172.19.138.100',
'range_higher': '172.19.138.250',
'interface': 'enp1s0.42',
'options': {
'routers': '172.19.138.1',
'domain-name-servers': '8.8.8.8, 8.8.4.4',
'domain-name': 'franzi-home.kunbox.net',
'broadcast-address': '172.19.138.255',
'subnet-mask': '255.255.255.0',
},
'default-lease-time': 300,
'max-lease-time': 1800,
},
},
},
'vm': {
'cpu': 2,
'ram': 2,