wip
This commit is contained in:
parent
f0a9074dcb
commit
d9f3474977
3 changed files with 24 additions and 78 deletions
|
@ -2,24 +2,36 @@ from ipaddress import ip_interface
|
||||||
|
|
||||||
|
|
||||||
@metadata_reactor.provides(
|
@metadata_reactor.provides(
|
||||||
'interfaces',
|
'systemd-networkd/networks',
|
||||||
)
|
)
|
||||||
def interfaces(metadata):
|
def interfaces(metadata):
|
||||||
interface = {
|
network = {
|
||||||
'ips': [],
|
'Match': {
|
||||||
|
'Name': metadata.get('network/interface'),
|
||||||
|
},
|
||||||
|
'Network': {
|
||||||
|
'DHCP': 'no',
|
||||||
|
'IPv6AcceptRA': 'no',
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if metadata.get('network/ipv4', None):
|
for i in [4, 6]:
|
||||||
interface['ips'].append(metadata.get('network/ipv4'))
|
if metadata.get(f'network/ipv{i}', None):
|
||||||
interface['gateway4'] = metadata.get('network/gateway4')
|
network.update({
|
||||||
|
f'Address#ipv{i}': {
|
||||||
if metadata.get('network/ipv6', None):
|
'Address': metadata.get(f'network/ipv{i}'),
|
||||||
interface['ips'].append(metadata.get('network/ipv6'))
|
},
|
||||||
interface['gateway6'] = metadata.get('network/gateway6')
|
f'Route#ipv{i}': {
|
||||||
|
'Gateway': metadata.get(f'network/gateway{i}'),
|
||||||
|
'GatewayOnlink': 'yes',
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'interfaces': {
|
'systemd-networkd': {
|
||||||
metadata.get('network/interface'): interface,
|
'networks': {
|
||||||
|
metadata.get('network/interface'): network,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
|
@ -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 {
|
for type, path in {
|
||||||
'networks': '/etc/systemd/network/{}.network',
|
'networks': '/etc/systemd/network/{}.network',
|
||||||
'netdevs': '/etc/systemd/network/{}.netdev',
|
'netdevs': '/etc/systemd/network/{}.netdev',
|
||||||
|
|
Loading…
Reference in a new issue