bundles/systemd-networkd: support vlans
This commit is contained in:
parent
4213b60052
commit
75d86f3339
4 changed files with 47 additions and 1 deletions
|
@ -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
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
[NetDev]
|
||||||
|
Name=${interface}
|
||||||
|
Kind=vlan
|
||||||
|
|
||||||
|
[VLAN]
|
||||||
|
Id=${vlan}
|
|
@ -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': {
|
||||||
|
|
16
bundles/systemd-networkd/metadata.py
Normal file
16
bundles/systemd-networkd/metadata.py
Normal 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,
|
||||||
|
}
|
Loading…
Reference in a new issue