This commit is contained in:
cronekorkn 2024-09-23 21:25:27 +02:00
parent 3b89fb7886
commit 6d8f227e83
Signed by: cronekorkn
SSH key fingerprint: SHA256:v0410ZKfuO1QHdgKBsdQNF64xmTxOF8osF1LIqwTcVw
4 changed files with 29 additions and 3 deletions

View file

@ -1,4 +1,4 @@
from ipaddress import ip_interface
from ipaddress import ip_interface, ip_network
hashable = repo.libs.hashable.hashable
@ -36,16 +36,28 @@ defaults = {
@metadata_reactor.provides(
'kea',
'kea/Dhcp4/interfaces-config/interfaces',
'kea/Dhcp4/subnet4',
)
def subnets(metadata):
subnet4 = set()
interfaces = set()
reservations = set(
hashable({
'hw-address': network_conf['mac'],
'ip-address': str(ip_interface(network_conf['ipv4']).ip),
})
for other_node in repo.nodes
for network_conf in other_node.metadata.get('network', {}).values()
if 'mac' in network_conf
)
for network_name, network_conf in metadata.get('network').items():
dhcp_server_config = network_conf.get('dhcp_server_config', None)
if dhcp_server_config:
_network = ip_network(dhcp_server_config['subnet'])
subnet4.add(hashable({
'subnet': dhcp_server_config['subnet'],
'pools': [
@ -63,7 +75,13 @@ def subnets(metadata):
'data': '10.0.10.2',
},
],
'reservations': set(
reservation
for reservation in reservations
if ip_interface(reservation['ip-address']).ip in _network
),
}))
interfaces.add(network_conf.get('interface', network_name))
return {

View file

@ -29,6 +29,7 @@
'internal': {
'interface': 'eth0',
'ipv4': '10.0.0.16/24',
'mac': 'd8:3a:dd:16:fc:9d',
'gateway4': '10.0.0.1',
},
},

View file

@ -14,6 +14,7 @@
'network': {
'internal': {
'ipv4': '10.0.2.8/24',
'mac': 'b8:27:eb:15:30:86',
},
},
'dns': {

View file

@ -5,7 +5,13 @@
'home',
],
'metadata': {
'id': '',
'id': '87879bc1-130f-4fca-a8d2-e1d93a794df4',
'network': {
'internal': {
'ipv4': '10.0.2.100/24',
'mac': '00:17:88:67:e7:f2',
},
},
'dns': {
'hue.ckn.li': {
'A': {'10.0.2.100'},