from bundlewrap.exceptions import BundleError repo.libs.tools.require_bundle(node, 'systemd') files = { '/etc/network/interfaces': { 'delete': True, }, } 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', } 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(): 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: files[f'/etc/systemd/network/{interface}.netdev'] = { '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', }, } if not config.get('ignore', False): files[f'/etc/systemd/network/{interface}.network'] = { 'source': template, 'content_type': 'mako', 'context': { 'interface': interface, 'config': config, }, 'needed_by': { 'svc_systemd:systemd-networkd', }, 'triggers': { 'svc_systemd:systemd-networkd:restart', }, } for bond, config in node.metadata.get('systemd-networkd/bonds', {}).items(): files[f'/etc/systemd/network/{bond}.netdev'] = { 'source': 'template-bond.netdev', 'content_type': 'mako', 'context': { 'bond': bond, 'mode': config.get('mode', '802.3ad'), 'prio': config.get('priority', '32768'), }, 'needed_by': { 'svc_systemd:systemd-networkd', }, 'triggers': { 'svc_systemd:systemd-networkd:restart', }, } files[f'/etc/systemd/network/{bond}.network'] = { 'source': 'template-bond.network', 'content_type': 'mako', 'context': { 'bond': bond, 'match': config['match'], 'vlans': node.metadata.get(f'interfaces/{bond}/vlans', set()), }, 'needed_by': { 'svc_systemd:systemd-networkd', }, 'triggers': { 'svc_systemd:systemd-networkd:restart', }, } for brname, config in node.metadata.get('systemd-networkd/bridges', {}).items(): files[f'/etc/systemd/network/{brname}.netdev'] = { 'source': 'template-bridge.netdev', 'content_type': 'mako', 'context': { 'bridge': brname, }, 'needed_by': { 'svc_systemd:systemd-networkd', }, 'triggers': { 'svc_systemd:systemd-networkd:restart', }, } files[f'/etc/systemd/network/{brname}.network'] = { 'source': 'template-bridge.network', 'content_type': 'mako', 'context': { 'bridge': brname, 'match': config['match'], 'vlans': node.metadata.get(f'interfaces/{brname}/vlans', set()), }, 'needed_by': { 'svc_systemd:systemd-networkd', }, 'triggers': { 'svc_systemd:systemd-networkd:restart', }, } svc_systemd = { 'systemd-networkd': {}, }