2020-06-06 08:18:25 +00:00
|
|
|
assert node.has_bundle('systemd')
|
|
|
|
|
|
|
|
files = {
|
2020-11-09 13:48:19 +00:00
|
|
|
'/etc/network/interfaces': {
|
|
|
|
'delete': True,
|
|
|
|
},
|
2020-06-06 08:18:25 +00:00
|
|
|
}
|
|
|
|
|
2021-02-18 16:56:43 +00:00
|
|
|
if node.metadata.get('systemd-networkd/enable-resolved', False):
|
|
|
|
symlinks['/etc/resolv.conf'] = {
|
|
|
|
'target': '/run/systemd/resolve/stub-resolv.conf',
|
|
|
|
}
|
|
|
|
svc_systemd['systemd-resolved'] = {}
|
|
|
|
else:
|
|
|
|
files['/etc/resolv.conf'] = {
|
|
|
|
'content_type': 'mako',
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-09 13:48:19 +00:00
|
|
|
directories = {
|
|
|
|
'/etc/systemd/network': {
|
|
|
|
'purge': True,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
# Don't use .get() here. We might end up with a node without a network
|
|
|
|
# config!
|
|
|
|
for interface, config in node.metadata['interfaces'].items():
|
2020-11-09 13:58:09 +00:00
|
|
|
if config.get('dhcp', False):
|
2020-11-13 15:29:17 +00:00
|
|
|
assert not 'vlans' in config, f'interface {interface} cannot use vlans and dhcp!'
|
2020-11-12 18:38:10 +00:00
|
|
|
template = 'template-iface-dhcp.network'
|
2020-11-09 13:58:09 +00:00
|
|
|
else:
|
2020-11-12 18:38:10 +00:00
|
|
|
template = 'template-iface-nodhcp.network'
|
2020-11-09 13:58:09 +00:00
|
|
|
|
2020-11-13 15:29:17 +00:00
|
|
|
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
|
|
|
|
|
2020-11-13 20:40:44 +00:00
|
|
|
if not config.get('ignore', False):
|
|
|
|
files['/etc/systemd/network/{}-iface-{}.network'.format(weight, interface)] = {
|
|
|
|
'source': template,
|
|
|
|
'content_type': 'mako',
|
|
|
|
'context': {
|
|
|
|
'interface': interface,
|
|
|
|
'config': config,
|
|
|
|
},
|
|
|
|
'needed_by': {
|
|
|
|
'svc_systemd:systemd-networkd',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:systemd-networkd:restart',
|
|
|
|
},
|
|
|
|
}
|
2020-06-06 08:18:25 +00:00
|
|
|
|
2021-02-18 17:12:25 +00:00
|
|
|
for bond, config in node.metadata.get('systemd-networkd/bonds', {}).items():
|
2020-11-12 18:38:10 +00:00
|
|
|
files['/etc/systemd/network/20-bond-{}.netdev'.format(bond)] = {
|
|
|
|
'source': 'template-bond.netdev',
|
|
|
|
'content_type': 'mako',
|
|
|
|
'context': {
|
|
|
|
'bond': bond,
|
|
|
|
'mode': config.get('mode', '802.3ad'),
|
2020-11-15 08:39:44 +00:00
|
|
|
'prio': config.get('priority', '32768'),
|
2020-11-12 18:38:10 +00:00
|
|
|
},
|
|
|
|
'needed_by': {
|
|
|
|
'svc_systemd:systemd-networkd',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:systemd-networkd:restart',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
files['/etc/systemd/network/21-bond-{}.network'.format(bond)] = {
|
|
|
|
'source': 'template-bond.network',
|
|
|
|
'content_type': 'mako',
|
|
|
|
'context': {
|
|
|
|
'bond': bond,
|
|
|
|
'match': config['match'],
|
|
|
|
},
|
|
|
|
'needed_by': {
|
|
|
|
'svc_systemd:systemd-networkd',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:systemd-networkd:restart',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-02-18 17:12:25 +00:00
|
|
|
for brname, config in node.metadata.get('systemd-networkd/bridges', {}).items():
|
2020-11-12 18:38:10 +00:00
|
|
|
files['/etc/systemd/network/30-bridge-{}.netdev'.format(brname)] = {
|
|
|
|
'source': 'template-bridge.netdev',
|
|
|
|
'content_type': 'mako',
|
|
|
|
'context': {
|
|
|
|
'bridge': brname,
|
|
|
|
},
|
|
|
|
'needed_by': {
|
|
|
|
'svc_systemd:systemd-networkd',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:systemd-networkd:restart',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
files['/etc/systemd/network/31-bridge-{}.network'.format(brname)] = {
|
|
|
|
'source': 'template-bridge.network',
|
|
|
|
'content_type': 'mako',
|
|
|
|
'context': {
|
|
|
|
'bridge': brname,
|
|
|
|
'match': config['match'],
|
|
|
|
},
|
|
|
|
'needed_by': {
|
|
|
|
'svc_systemd:systemd-networkd',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:systemd-networkd:restart',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-06-06 08:18:25 +00:00
|
|
|
svc_systemd = {
|
|
|
|
'systemd-networkd': {},
|
|
|
|
}
|