From dcf944b1981f72dd5f7dba78303eac9e2cf6ae15 Mon Sep 17 00:00:00 2001 From: Sophie Schiller Date: Fri, 13 Nov 2020 22:11:56 +0100 Subject: [PATCH] bundles/dhcpd add initial items, metadata and template --- bundles/dhcpd/.metadata.py.swp | Bin 0 -> 12288 bytes bundles/dhcpd/files/dhcpd.conf | 26 ++++++++++++++++++++++++++ bundles/dhcpd/items.py | 14 ++++++++++++++ bundles/dhcpd/metadata.py | 25 +++++++++++++++++++++++++ groups/locations.py | 1 + nodes/home/router.py | 21 +++++++++++++++++++++ 6 files changed, 87 insertions(+) create mode 100644 bundles/dhcpd/.metadata.py.swp create mode 100644 bundles/dhcpd/files/dhcpd.conf create mode 100644 bundles/dhcpd/items.py create mode 100644 bundles/dhcpd/metadata.py diff --git a/bundles/dhcpd/.metadata.py.swp b/bundles/dhcpd/.metadata.py.swp new file mode 100644 index 0000000000000000000000000000000000000000..0de9b1ec730fda0459480bded686c39209f51111 GIT binary patch literal 12288 zcmeI2F>ezw6vtimPy`YZVmV;AL`p6RFjSS0n2k`ndi%0b5y8w1>TeXv3-8;`T1urr`%@m_QuU|a-?Dcf8q8@kmJlY6Hn=<5@nfmBj&@`B7YVzW7E+D6n=>UQuw%I?yRIw7nGxM7 zcrLi-iMjWOj5JLIh`_N3%zWNiYp^Sq`@P_Q>Eeax%;{Ul3MD5ZKm>>Y5g-CYfCvx) zB0vQG4FcY*um`x66XkZ!mF>!*wj5GJ1c(3;AOb{y2oM1xKm>>Y5g-CYfC&7B1h`;q zwZYgURQUhDdjJ2v%Gg)bC)8`yE7Wt;Gt^VmKI$Rr4r&8+9`*htV=qt|)kiVZH_ZD5 z^%3>Y5g-CYfCvx)B0vQGR{{~*oQ2?RSv>~%6`pXJq>L<zIktVK%W;$dsh`%QGM`hitiK%)2*hS9Y{#manHN-_f9EOr>TqZ@qU zpta7ba&m1WDL{FdOR()_6!xOU3J0H;7kLiqbeL^#-b$p0scV)gL%JfW2nVB+P^3$x zN=H`DOfw$qDa56BZ8u>Db0#2 literal 0 HcmV?d00001 diff --git a/bundles/dhcpd/files/dhcpd.conf b/bundles/dhcpd/files/dhcpd.conf new file mode 100644 index 0000000..1854552 --- /dev/null +++ b/bundles/dhcpd/files/dhcpd.conf @@ -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 diff --git a/bundles/dhcpd/items.py b/bundles/dhcpd/items.py new file mode 100644 index 0000000..3d47949 --- /dev/null +++ b/bundles/dhcpd/items.py @@ -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', + }, + }, +} diff --git a/bundles/dhcpd/metadata.py b/bundles/dhcpd/metadata.py new file mode 100644 index 0000000..03af663 --- /dev/null +++ b/bundles/dhcpd/metadata.py @@ -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, + } + } + diff --git a/groups/locations.py b/groups/locations.py index c52b766..b9bc5c3 100644 --- a/groups/locations.py +++ b/groups/locations.py @@ -49,6 +49,7 @@ groups['home'] = { 'lldp', }, 'metadata': { + 'location': 'home', 'nameservers': { '172.19.138.1', }, diff --git a/nodes/home/router.py b/nodes/home/router.py index 4c7f197..12a6f45 100644 --- a/nodes/home/router.py +++ b/nodes/home/router.py @@ -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,