From d9f3474977d07dac841ca4cf1513fa41c41ca1a0 Mon Sep 17 00:00:00 2001 From: mwiegand Date: Fri, 25 Jun 2021 01:23:36 +0200 Subject: [PATCH] wip --- bundles/network/metadata.py | 36 ++++++++----- .../systemd-networkd/files/interface.network | 50 ------------------- bundles/systemd-networkd/items.py | 16 ------ 3 files changed, 24 insertions(+), 78 deletions(-) delete mode 100644 bundles/systemd-networkd/files/interface.network diff --git a/bundles/network/metadata.py b/bundles/network/metadata.py index 2012168..08cab3c 100644 --- a/bundles/network/metadata.py +++ b/bundles/network/metadata.py @@ -2,24 +2,36 @@ from ipaddress import ip_interface @metadata_reactor.provides( - 'interfaces', + 'systemd-networkd/networks', ) def interfaces(metadata): - interface = { - 'ips': [], + network = { + 'Match': { + 'Name': metadata.get('network/interface'), + }, + 'Network': { + 'DHCP': 'no', + 'IPv6AcceptRA': 'no', + } } - if metadata.get('network/ipv4', None): - interface['ips'].append(metadata.get('network/ipv4')) - interface['gateway4'] = metadata.get('network/gateway4') - - if metadata.get('network/ipv6', None): - interface['ips'].append(metadata.get('network/ipv6')) - interface['gateway6'] = metadata.get('network/gateway6') + for i in [4, 6]: + if metadata.get(f'network/ipv{i}', None): + network.update({ + f'Address#ipv{i}': { + 'Address': metadata.get(f'network/ipv{i}'), + }, + f'Route#ipv{i}': { + 'Gateway': metadata.get(f'network/gateway{i}'), + 'GatewayOnlink': 'yes', + } + }) return { - 'interfaces': { - metadata.get('network/interface'): interface, + 'systemd-networkd': { + 'networks': { + metadata.get('network/interface'): network, + } } } diff --git a/bundles/systemd-networkd/files/interface.network b/bundles/systemd-networkd/files/interface.network deleted file mode 100644 index bdbaed0..0000000 --- a/bundles/systemd-networkd/files/interface.network +++ /dev/null @@ -1,50 +0,0 @@ -<% - from ipaddress import ip_network -%>\ -[Match] -Name=${interface} - -% for addr in sorted(config.get('ips', set())): -[Address] -<% - if '/' in addr: - ip, prefix = addr.split('/') - else: - ip = addr - prefix = '32' -%>\ -Address=${ip}/${prefix} - -% endfor -% for route, rconfig in sorted(config.get('routes', {}).items()): -[Route] -% if 'via' in rconfig: -Gateway=${rconfig['via']} -% endif -Destination=${route} -GatewayOnlink=yes - -% endfor -% if 'gateway4' in config: -[Route] -Gateway=${config['gateway4']} -GatewayOnlink=yes - -% endif -% if 'gateway6' in config: -[Route] -Gateway=${config['gateway6']} -GatewayOnlink=yes - -% endif -[Network] -DHCP=no -IPv6AcceptRA=no - -% if config.get('forwarding', False): -IPForward=yes -%endif - -% for vlan in sorted(config.get('vlans', set())): -VLAN=${interface}.${vlan} -% endfor diff --git a/bundles/systemd-networkd/items.py b/bundles/systemd-networkd/items.py index 47d421d..dc804dd 100644 --- a/bundles/systemd-networkd/items.py +++ b/bundles/systemd-networkd/items.py @@ -16,22 +16,6 @@ directories = { }, } -for interface, config in node.metadata['interfaces'].items(): - files[f'/etc/systemd/network/{interface}.network'] = { - 'source': 'interface.network', - 'content_type': 'mako', - 'context': { - 'interface': interface, - 'config': config, - }, - 'needed_by': { - 'svc_systemd:systemd-networkd', - }, - 'triggers': { - 'svc_systemd:systemd-networkd:restart', - }, - } - for type, path in { 'networks': '/etc/systemd/network/{}.network', 'netdevs': '/etc/systemd/network/{}.netdev',