bundles/systemd-networkd: support vlans

This commit is contained in:
Franzi 2020-11-13 16:29:17 +01:00
parent 4213b60052
commit 75d86f3339
Signed by: kunsi
GPG key ID: 12E3D2136B818350
4 changed files with 47 additions and 1 deletions

View file

@ -36,3 +36,7 @@ IPv6AcceptRA=no
% if config.get('forwarding', False): % if config.get('forwarding', False):
IPForward=yes IPForward=yes
%endif %endif
% for vlan in sorted(config.get('vlans', set())):
VLAN=${interface}.${vlan}
% endfor

View file

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

View file

@ -25,11 +25,31 @@ directories = {
# config! # config!
for interface, config in node.metadata['interfaces'].items(): for interface, config in node.metadata['interfaces'].items():
if config.get('dhcp', False): if config.get('dhcp', False):
assert not 'vlans' in config, f'interface {interface} cannot use vlans and dhcp!'
template = 'template-iface-dhcp.network' template = 'template-iface-dhcp.network'
else: else:
template = 'template-iface-nodhcp.network' 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, 'source': template,
'content_type': 'mako', 'content_type': 'mako',
'context': { 'context': {

View file

@ -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,
}