bundles/systemd-networkd: generate unique mac address for vlan interfaces

This commit is contained in:
Franzi 2021-04-10 12:18:23 +02:00
parent ac58f2a10c
commit 0d1a220b7b
Signed by: kunsi
GPG key ID: 12E3D2136B818350
2 changed files with 8 additions and 1 deletions

View file

@ -1,6 +1,7 @@
[NetDev]
Name=${interface}
Kind=vlan
MACAddress=${mac}
[VLAN]
Id=${vlan}

View file

@ -25,6 +25,9 @@ directories = {
},
}
mac_host_prefix = '%04x' % (node.magic_number % 65534)
generated_mac = f'52:54:00:{mac_host_prefix[0:2]}:{mac_host_prefix[2:4]}:{{}}'
# Don't use .get() here. We might end up with a node without a network
# config!
for interface, config in node.metadata['interfaces'].items():
@ -36,12 +39,15 @@ for interface, config in node.metadata['interfaces'].items():
template = 'template-iface-nodhcp.network'
if '.' in interface:
vlan_id = int(interface.split('.')[1])
vlan_hex = '%02x' % (vlan_id % 255)
files[f'/etc/systemd/network/{interface}.netdev'] = {
'source': 'template-iface-vlan.netdev',
'content_type': 'mako',
'context': {
'interface': interface,
'vlan': interface.split('.')[1],
'vlan': vlan_id,
'mac': generated_mac.format(vlan_hex)
},
'needed_by': {
'svc_systemd:systemd-networkd',