bundle/systemd-networkd #4

Merged
kunsi merged 5 commits from interface-configuration into main 2020-11-09 14:27:52 +00:00
13 changed files with 125 additions and 28 deletions

View file

@ -0,0 +1,14 @@
<%
from ipaddress import ip_network
%>\
[Match]
Name=${interface}
[Network]
DHCP=yes
IPv6AcceptRA=yes
UseHostname=no
% if config.get('forwarding', False):
IPForward=yes
%endif

View file

@ -0,0 +1,38 @@
<%
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]
DHCP=no
IPv6AcceptRA=no
% if config.get('forwarding', False):
IPForward=yes
%endif

View file

@ -0,0 +1,40 @@
assert node.has_bundle('systemd')
files = {
'/etc/network/interfaces': {
'delete': True,
},
}
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):
template = 'template-dhcp.network'
else:
template = 'template.network'
files['/etc/systemd/network/10-{}.network'.format(interface)] = {
'source': template,
'content_type': 'mako',
'context': {
'interface': interface,
'config': config,
},
'needed_by': {
'svc_systemd:systemd-networkd',
},
'triggers': {
'svc_systemd:systemd-networkd:restart',
},
}
svc_systemd = {
'systemd-networkd': {},
}

View file

@ -9,6 +9,7 @@ groups['all'] = {
'postfix', 'postfix',
'sudo', 'sudo',
'systemd', 'systemd',
'systemd-networkd',
'users', 'users',
}, },
'metadata': { 'metadata': {

View file

@ -20,10 +20,11 @@ def resolve_identifier(repo, identifier):
found_ips = set() found_ips = set()
for node in nodes: for node in nodes:
for interface, config in node.metadata.get('interfaces', {}).items(): for interface, config in node.metadata.get('interfaces', {}).items():
for ip in config.get('ipv4', set()): for ip in config.get('ips', set()):
found_ips.add(ip_address(ip)) if '/' in ip:
for ip in config.get('ipv4', set()): found_ips.add(ip_address(ip.split('/')[0]))
found_ips.add(ip_address(ip)) else:
found_ips.add(ip_address(ip))
if node.metadata.get('external_ipv4', None): if node.metadata.get('external_ipv4', None):
found_ips.add(ip_address(node.metadata.get('external_ipv4'))) found_ips.add(ip_address(node.metadata.get('external_ipv4')))

View file

@ -13,8 +13,8 @@ nodes['gce.bind01'] = {
}, },
'metadata': { 'metadata': {
'interfaces': { 'interfaces': {
'eth0': { 'ens4': {
'ipv4': { 'ips': {
'10.156.0.4', '10.156.0.4',
}, },
'gateway4': '10.156.0.1', 'gateway4': '10.156.0.1',

View file

@ -9,8 +9,8 @@ nodes['gce.dns02'] = {
}, },
'metadata': { 'metadata': {
'interfaces': { 'interfaces': {
'eth0': { 'ens4': {
'ipv4': { 'ips': {
'10.132.0.2', '10.132.0.2',
}, },
'gateway4': '10.132.0.1', 'gateway4': '10.132.0.1',

View file

@ -9,8 +9,8 @@ nodes['gce.dns03'] = {
}, },
'metadata': { 'metadata': {
'interfaces': { 'interfaces': {
'eth0': { 'ens4': {
'ipv4': { 'ips': {
'10.166.0.2', '10.166.0.2',
}, },
'gateway4': '10.166.0.1', 'gateway4': '10.166.0.1',

View file

@ -10,11 +10,9 @@ nodes['htz-cloud.luther'] = {
'metadata': { 'metadata': {
'interfaces': { 'interfaces': {
'eth0': { 'eth0': {
'ipv4': { 'ips': {
'195.201.136.20', '195.201.136.20',
}, '2a01:4f8:c2c:fc3b::1/64',
'ipv6': {
'2a01:4f8:c2c:fc3b::1',
}, },
'gateway4': '172.31.1.1', 'gateway4': '172.31.1.1',
'gateway6': 'fe80::1', 'gateway6': 'fe80::1',

View file

@ -6,11 +6,9 @@ nodes['htz-cloud.pirmasens'] = {
'metadata': { 'metadata': {
'interfaces': { 'interfaces': {
'eth0': { 'eth0': {
'ipv4': { 'ips': {
'195.201.90.143', '195.201.90.143',
}, '2a01:4f8:1c1c:2acf::1/64',
'ipv6': {
'2a01:4f8:1c1c:2acf::1',
}, },
'gateway4': '172.31.1.1', 'gateway4': '172.31.1.1',
'gateway6': 'fe80::1', 'gateway6': 'fe80::1',

View file

@ -11,11 +11,9 @@ nodes['htz-cloud.sewfile'] = {
'metadata': { 'metadata': {
'interfaces': { 'interfaces': {
'eth0': { 'eth0': {
'ipv4': { 'ips': {
'116.203.205.248', '116.203.205.248',
}, '2a01:4f8:c0c:c71b::1/64',
'ipv6': {
'2a01:4f8:c0c:c71b::1',
}, },
'gateway4': '172.31.1.1', 'gateway4': '172.31.1.1',
'gateway6': 'fe80::1', 'gateway6': 'fe80::1',

View file

@ -24,12 +24,10 @@ nodes['htz.ex42-1048908'] = {
'metadata': { 'metadata': {
'interfaces': { 'interfaces': {
'enp0s31f6': { 'enp0s31f6': {
'ipv4': { 'ips': {
'94.130.52.224', '94.130.52.224/26',
}, '2a01:4f8:10b:2a5f::02/64',
'ipv6': { '2a01:4f8:10b:2a5f::1337/64',
'2a01:4f8:10b:2a5f::02',
'2a01:4f8:10b:2a5f::1337',
}, },
'gateway4': '94.130.52.193', 'gateway4': '94.130.52.193',
'gateway6': 'fe80::1', 'gateway6': 'fe80::1',

View file

@ -13,6 +13,17 @@ nodes['rx300'] = {
}, },
'groups': set(), 'groups': set(),
'metadata': { 'metadata': {
'interfaces': {
'eth0': {
'ips': {
'172.19.138.26/24',
},
'gateway4': '172.19.138.1',
},
'eth1': {
'dhcp': True,
},
},
'zfs': { 'zfs': {
'module_options': { 'module_options': {
'zfs_arc_max_mb': 16384, # 16GB 'zfs_arc_max_mb': 16384, # 16GB