diff --git a/bundles/systemd-networkd/files/template-iface-nodhcp.network b/bundles/systemd-networkd/files/template-iface-nodhcp.network index 437a793..4efb79e 100644 --- a/bundles/systemd-networkd/files/template-iface-nodhcp.network +++ b/bundles/systemd-networkd/files/template-iface-nodhcp.network @@ -36,3 +36,7 @@ IPv6AcceptRA=no % if config.get('forwarding', False): IPForward=yes %endif + +% for vlan in sorted(config.get('vlans', set())): +VLAN=${interface}.${vlan} +% endfor diff --git a/bundles/systemd-networkd/files/template-iface-vlan.netdev b/bundles/systemd-networkd/files/template-iface-vlan.netdev new file mode 100644 index 0000000..9f71a17 --- /dev/null +++ b/bundles/systemd-networkd/files/template-iface-vlan.netdev @@ -0,0 +1,6 @@ +[NetDev] +Name=${interface} +Kind=vlan + +[VLAN] +Id=${vlan} diff --git a/bundles/systemd-networkd/items.py b/bundles/systemd-networkd/items.py index 0627b86..2cfb7a3 100644 --- a/bundles/systemd-networkd/items.py +++ b/bundles/systemd-networkd/items.py @@ -25,11 +25,31 @@ directories = { # config! for interface, config in node.metadata['interfaces'].items(): if config.get('dhcp', False): + assert not 'vlans' in config, f'interface {interface} cannot use vlans and dhcp!' template = 'template-iface-dhcp.network' else: template = 'template-iface-nodhcp.network' - files['/etc/systemd/network/50-iface-{}.network'.format(interface)] = { + if '.' in interface: + files['/etc/systemd/network/60-iface-{}.netdev'.format(interface)] = { + 'source': 'template-iface-vlan.netdev', + 'content_type': 'mako', + 'context': { + 'interface': interface, + 'vlan': interface.split('.')[1], + }, + 'needed_by': { + 'svc_systemd:systemd-networkd', + }, + 'triggers': { + 'svc_systemd:systemd-networkd:restart', + }, + } + weight = 61 + else: + weight = 50 + + files['/etc/systemd/network/{}-iface-{}.network'.format(weight, interface)] = { 'source': template, 'content_type': 'mako', 'context': { diff --git a/bundles/systemd-networkd/metadata.py b/bundles/systemd-networkd/metadata.py new file mode 100644 index 0000000..99d694a --- /dev/null +++ b/bundles/systemd-networkd/metadata.py @@ -0,0 +1,16 @@ +@metadata_reactor +def add_vlan_infos_to_interface(metadata): + interfaces = {} + + for iface, config in metadata.get('interfaces', {}).items(): + if not '.' in iface: + continue + + interface,vlan = iface.split('.') + + interfaces.setdefault(interface, {}).setdefault('vlans', set()) + interfaces[interface]['vlans'].add(vlan) + + return { + 'interfaces': interfaces, + }