bundles/systemd-networkd: combine templates for interfaces

This commit is contained in:
Franzi 2023-09-24 18:54:47 +02:00
parent e27e374983
commit 53ff288d89
Signed by: kunsi
GPG key ID: 12E3D2136B818350
3 changed files with 26 additions and 38 deletions

View file

@ -1,27 +0,0 @@
<%
from ipaddress import ip_network
%>\
[Match]
Name=${interface}
[Network]
DHCP=yes
IPv6AcceptRA=yes
[DHCPv4]
UseDomains=${str(config.get('use_dhcp_domains', False)).lower()}
UseHostname=no
UseMTU=${str(config.get('use_dhcp_mtu', True)).lower()}
UseNTP=${str(config.get('use_dhcp_ntp', False)).lower()}
UseTimezone=no
% if config.get('send_hostname', True):
SendHostname=yes
Hostname=${node.name.split('.')[-1]}
% else:
SendHostname=no
% endif
% if config.get('forwarding', False):
IPForward=yes
%endif

View file

@ -25,6 +25,7 @@ Destination=${route}
GatewayOnlink=yes GatewayOnlink=yes
% endfor % endfor
% if not config.get('dhcp', False):
% if 'gateway4' in config: % if 'gateway4' in config:
[Route] [Route]
Gateway=${config['gateway4']} Gateway=${config['gateway4']}
@ -36,19 +37,35 @@ GatewayOnlink=yes
Gateway=${config['gateway6']} Gateway=${config['gateway6']}
GatewayOnlink=yes GatewayOnlink=yes
% endif
% endif % endif
[Network] [Network]
DHCP=no % if config.get('ipv6_accept_ra', False) or config.get('dhcp', False):
% if config.get('ipv6_accept_ra', False):
IPv6AcceptRA=yes IPv6AcceptRA=yes
% else: % else:
IPv6AcceptRA=no IPv6AcceptRA=no
% endif % endif
% if config.get('dhcp', False):
DHCP=yes
IPv6AcceptRA=yes
% if config.get('forwarding', False): [DHCPv4]
IPForward=yes UseDomains=false
%endif UseHostname=no
UseMTU=true
UseNTP=false
UseTimezone=no
SendHostname=no
% else:
DHCP=no
% endif
% for vlan in sorted(config.get('vlans', set())): % for vlan in sorted(config.get('vlans', set())):
VLAN=${interface}.${vlan} VLAN=${interface}.${vlan}
% endfor % endfor
% if 'activation_policy' in config:
[Link]
ActivationPolicy=${config['activation_policy']}
% endif

View file

@ -40,9 +40,7 @@ for interface, config in node.metadata.get('interfaces').items():
if config.get('dhcp', False): if config.get('dhcp', False):
if 'vlans' in config: if 'vlans' in config:
raise BundleError(f'{node.name} interface {interface} cannot use vlans and dhcp!') raise BundleError(f'{node.name} interface {interface} cannot use vlans and dhcp!')
template = 'template-iface-dhcp.network'
else: else:
template = 'template-iface-nodhcp.network'
all_interfaces_use_dhcp = False all_interfaces_use_dhcp = False
if '.' in interface: if '.' in interface:
@ -80,7 +78,7 @@ for interface, config in node.metadata.get('interfaces').items():
if not config.get('ignore', False): if not config.get('ignore', False):
files[f'/etc/systemd/network/{interface}.network'] = { files[f'/etc/systemd/network/{interface}.network'] = {
'source': template, 'source': 'template-iface.network',
'content_type': 'mako', 'content_type': 'mako',
'context': { 'context': {
'interface': interface, 'interface': interface,