2021-12-21 14:56:24 +00:00
|
|
|
from bundlewrap.exceptions import BundleError
|
|
|
|
|
|
|
|
repo.libs.tools.require_bundle(node, 'systemd')
|
|
|
|
|
|
|
|
files = {
|
|
|
|
'/etc/network/interfaces': {
|
|
|
|
'delete': True,
|
|
|
|
},
|
2021-12-22 06:46:43 +00:00
|
|
|
'/etc/resolv.conf': {
|
2021-12-21 14:56:24 +00:00
|
|
|
'content_type': 'mako',
|
2021-12-22 06:46:43 +00:00
|
|
|
},
|
|
|
|
}
|
2021-12-21 14:56:24 +00:00
|
|
|
|
|
|
|
directories = {
|
|
|
|
'/etc/systemd/network': {
|
|
|
|
'purge': True,
|
|
|
|
'needed_by': {
|
|
|
|
'svc_systemd:systemd-networkd',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:systemd-networkd:restart',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
mac_host_prefix = '%04x' % (node.magic_number % 65534)
|
|
|
|
generated_mac = f'52:54:00:{mac_host_prefix[0:2]}:{mac_host_prefix[2:4]}:{{}}'
|
|
|
|
|
2021-12-22 06:46:43 +00:00
|
|
|
for interface, config in node.metadata.get('interfaces').items():
|
2021-12-21 14:56:24 +00:00
|
|
|
if config.get('dhcp', False):
|
|
|
|
if 'vlans' in config:
|
|
|
|
raise BundleError(f'{node.name} interface {interface} cannot use vlans and dhcp!')
|
|
|
|
template = 'template-iface-dhcp.network'
|
|
|
|
else:
|
|
|
|
template = 'template-iface-nodhcp.network'
|
|
|
|
|
|
|
|
if '.' in interface:
|
|
|
|
vlan_id = int(interface.split('.')[1])
|
|
|
|
vlan_hex = '%02x' % (vlan_id % 255)
|
|
|
|
files[f'/etc/systemd/network/{interface}.netdev'] = {
|
|
|
|
'source': 'template-iface-vlan.netdev',
|
|
|
|
'content_type': 'mako',
|
|
|
|
'context': {
|
|
|
|
'interface': interface,
|
|
|
|
'vlan': vlan_id,
|
|
|
|
'mac': generated_mac.format(vlan_hex)
|
|
|
|
},
|
|
|
|
'needed_by': {
|
|
|
|
'svc_systemd:systemd-networkd',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:systemd-networkd:restart',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-12-22 06:46:43 +00:00
|
|
|
files[f'/etc/systemd/network/{interface}.network'] = {
|
|
|
|
'source': template,
|
2021-12-21 14:56:24 +00:00
|
|
|
'content_type': 'mako',
|
|
|
|
'context': {
|
2021-12-22 06:46:43 +00:00
|
|
|
'interface': interface,
|
|
|
|
'config': config,
|
2021-12-21 14:56:24 +00:00
|
|
|
},
|
|
|
|
'needed_by': {
|
|
|
|
'svc_systemd:systemd-networkd',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:systemd-networkd:restart',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
svc_systemd = {
|
|
|
|
'systemd-networkd': {},
|
|
|
|
}
|