diff --git a/bundles/systemd-networkd/files/interfaces b/bundles/systemd-networkd/files/interfaces deleted file mode 100644 index 2e67d1c..0000000 --- a/bundles/systemd-networkd/files/interfaces +++ /dev/null @@ -1,3 +0,0 @@ -auto lo -iface lo inet loopback -iface lo inet6 loopback diff --git a/bundles/systemd-networkd/files/template.network b/bundles/systemd-networkd/files/template.network index 3784104..03bb020 100644 --- a/bundles/systemd-networkd/files/template.network +++ b/bundles/systemd-networkd/files/template.network @@ -1,6 +1,35 @@ +<% + 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 + +% if 'gateway4' in config: +[Route] +Gateway=${config['gateway4']} +GatewayOnLink=yes +% endif + +% if 'gateway6' in config: +[Route] +Gateway=${config['gateway6']} +GatewayOnLink=yes +% endif + [Network] % if config.get('dhcp', False): DHCP=yes @@ -11,23 +40,6 @@ DHCP=no IPv6AcceptRA=no % endif -% for addr in sorted(config.get('ip_addresses', set())): -Address=${addr} -% endfor - -% if config.get('ip4_masquerade_outgoing', False): -IPMasquerade=yes -IPForward=ipv4 +% if config.get('forwarding', False): +IPForward=yes %endif - -% if 'ip6_gateway' in config: -[Route] -Gateway=${config['ip6_gateway']} -GatewayOnLink=yes -% endif - -% if 'ip4_gateway' in config: -[Route] -Gateway=${config['ip4_gateway']} -GatewayOnLink=yes -% endif diff --git a/bundles/systemd-networkd/items.py b/bundles/systemd-networkd/items.py index 6f0764e..9980ab5 100644 --- a/bundles/systemd-networkd/items.py +++ b/bundles/systemd-networkd/items.py @@ -1,10 +1,20 @@ assert node.has_bundle('systemd') files = { - '/etc/network/interfaces': {}, + '/etc/network/interfaces': { + 'delete': True, + }, } -for interface, config in node.metadata.get('interfaces', {}).items(): +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(): files['/etc/systemd/network/10-{}.network'.format(interface)] = { 'source': 'template.network', 'content_type': 'mako', @@ -12,6 +22,9 @@ for interface, config in node.metadata.get('interfaces', {}).items(): 'interface': interface, 'config': config, }, + 'needed_by': { + 'svc_systemd:systemd-networkd', + }, 'triggers': { 'svc_systemd:systemd-networkd:restart', },