2021-04-01 14:26:06 +00:00
|
|
|
from bundlewrap.exceptions import BundleError
|
|
|
|
|
2021-04-02 16:57:13 +00:00
|
|
|
repo.libs.tools.require_bundle(node, 'systemd')
|
2020-06-06 08:18:25 +00:00
|
|
|
|
|
|
|
files = {
|
2020-11-09 13:48:19 +00:00
|
|
|
'/etc/network/interfaces': {
|
|
|
|
'delete': True,
|
|
|
|
},
|
2020-06-06 08:18:25 +00:00
|
|
|
}
|
|
|
|
|
2022-02-12 10:24:19 +00:00
|
|
|
svc_systemd = {
|
2022-07-10 11:32:11 +00:00
|
|
|
'systemd-networkd': {
|
|
|
|
'before': {
|
|
|
|
'git_deploy:',
|
|
|
|
},
|
|
|
|
},
|
2022-04-03 07:01:10 +00:00
|
|
|
'systemd-resolved': {
|
|
|
|
'running': False,
|
|
|
|
'enabled': False,
|
|
|
|
},
|
2022-02-12 10:24:19 +00:00
|
|
|
}
|
|
|
|
|
2020-11-09 13:48:19 +00:00
|
|
|
directories = {
|
|
|
|
'/etc/systemd/network': {
|
|
|
|
'purge': True,
|
2021-07-02 13:03:47 +00:00
|
|
|
'needed_by': {
|
|
|
|
'svc_systemd:systemd-networkd',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:systemd-networkd:restart',
|
|
|
|
},
|
2020-11-09 13:48:19 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-04-10 10:18:23 +00:00
|
|
|
mac_host_prefix = '%04x' % (node.magic_number % 65534)
|
|
|
|
generated_mac = f'52:54:00:{mac_host_prefix[0:2]}:{mac_host_prefix[2:4]}:{{}}'
|
2022-04-03 07:01:10 +00:00
|
|
|
all_interfaces_use_dhcp = True
|
2021-04-10 10:18:23 +00:00
|
|
|
|
2022-04-03 07:01:10 +00:00
|
|
|
for interface, config in node.metadata.get('interfaces').items():
|
2020-11-09 13:58:09 +00:00
|
|
|
if config.get('dhcp', False):
|
2021-04-01 14:26:06 +00:00
|
|
|
if 'vlans' in config:
|
|
|
|
raise BundleError(f'{node.name} interface {interface} cannot use vlans and dhcp!')
|
2020-11-09 13:58:09 +00:00
|
|
|
else:
|
2022-04-03 07:01:10 +00:00
|
|
|
all_interfaces_use_dhcp = False
|
2020-11-09 13:58:09 +00:00
|
|
|
|
2020-11-13 15:29:17 +00:00
|
|
|
if '.' in interface:
|
2021-04-10 10:18:23 +00:00
|
|
|
vlan_id = int(interface.split('.')[1])
|
|
|
|
vlan_hex = '%02x' % (vlan_id % 255)
|
2021-10-11 18:46:07 +00:00
|
|
|
files[f'/etc/systemd/network/{interface}.netdev'] = {
|
2020-11-13 15:29:17 +00:00
|
|
|
'source': 'template-iface-vlan.netdev',
|
|
|
|
'content_type': 'mako',
|
|
|
|
'context': {
|
|
|
|
'interface': interface,
|
2021-04-10 10:18:23 +00:00
|
|
|
'vlan': vlan_id,
|
|
|
|
'mac': generated_mac.format(vlan_hex)
|
2020-11-13 15:29:17 +00:00
|
|
|
},
|
|
|
|
'needed_by': {
|
|
|
|
'svc_systemd:systemd-networkd',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:systemd-networkd:restart',
|
|
|
|
},
|
|
|
|
}
|
2021-09-29 17:44:37 +00:00
|
|
|
elif interface.startswith('dummy'):
|
2021-10-11 18:46:07 +00:00
|
|
|
files[f'/etc/systemd/network/{interface}.netdev'] = {
|
2021-09-29 17:44:37 +00:00
|
|
|
'source': 'template-dummy.netdev',
|
|
|
|
'content_type': 'mako',
|
|
|
|
'context': {
|
|
|
|
'name': interface,
|
|
|
|
},
|
|
|
|
'needed_by': {
|
|
|
|
'svc_systemd:systemd-networkd',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:systemd-networkd:restart',
|
|
|
|
},
|
|
|
|
}
|
2020-11-13 15:29:17 +00:00
|
|
|
|
2020-11-13 20:40:44 +00:00
|
|
|
if not config.get('ignore', False):
|
2021-10-11 18:46:07 +00:00
|
|
|
files[f'/etc/systemd/network/{interface}.network'] = {
|
2023-09-24 16:54:47 +00:00
|
|
|
'source': 'template-iface.network',
|
2020-11-13 20:40:44 +00:00
|
|
|
'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
|
|
|
|
2022-04-03 07:01:10 +00:00
|
|
|
if not all_interfaces_use_dhcp:
|
|
|
|
files['/etc/resolv.conf'] = {
|
|
|
|
'content_type': 'mako',
|
|
|
|
}
|
|
|
|
|
2021-02-18 17:12:25 +00:00
|
|
|
for bond, config in node.metadata.get('systemd-networkd/bonds', {}).items():
|
2021-10-11 18:46:07 +00:00
|
|
|
files[f'/etc/systemd/network/{bond}.netdev'] = {
|
2020-11-12 18:38:10 +00:00
|
|
|
'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',
|
|
|
|
},
|
|
|
|
}
|
2021-10-11 18:46:07 +00:00
|
|
|
|
|
|
|
files[f'/etc/systemd/network/{bond}.network'] = {
|
2020-11-12 18:38:10 +00:00
|
|
|
'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():
|
2021-10-11 18:46:07 +00:00
|
|
|
filename = '{}-match-{}'.format(
|
|
|
|
brname,
|
|
|
|
'-'.join(sorted(config['match'])),
|
|
|
|
)
|
|
|
|
|
|
|
|
files[f'/etc/systemd/network/{brname}.netdev'] = {
|
2020-11-12 18:38:10 +00:00
|
|
|
'source': 'template-bridge.netdev',
|
|
|
|
'content_type': 'mako',
|
|
|
|
'context': {
|
|
|
|
'bridge': brname,
|
|
|
|
},
|
|
|
|
'needed_by': {
|
|
|
|
'svc_systemd:systemd-networkd',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:systemd-networkd:restart',
|
|
|
|
},
|
|
|
|
}
|
2021-10-11 18:46:07 +00:00
|
|
|
|
|
|
|
files[f'/etc/systemd/network/{filename}.network'] = {
|
2020-11-12 18:38:10 +00:00
|
|
|
'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',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-10-11 18:46:07 +00:00
|
|
|
if config.get('vlans', set()):
|
|
|
|
files[f'/etc/systemd/network/{brname}.network'] = {
|
|
|
|
'source': 'template-bridge-vlan.network',
|
|
|
|
'content_type': 'mako',
|
|
|
|
'context': {
|
|
|
|
'bridge': brname,
|
|
|
|
'vlans': config.get('vlans', set()),
|
|
|
|
},
|
|
|
|
'needed_by': {
|
|
|
|
'svc_systemd:systemd-networkd',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:systemd-networkd:restart',
|
|
|
|
},
|
|
|
|
}
|