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
% endfor
% if not config.get('dhcp', False):
% if 'gateway4' in config:
[Route]
Gateway=${config['gateway4']}
@ -36,19 +37,35 @@ GatewayOnlink=yes
Gateway=${config['gateway6']}
GatewayOnlink=yes
% endif
% endif
[Network]
DHCP=no
% if config.get('ipv6_accept_ra', False):
% if config.get('ipv6_accept_ra', False) or config.get('dhcp', False):
IPv6AcceptRA=yes
% else:
IPv6AcceptRA=no
% endif
% if config.get('dhcp', False):
DHCP=yes
IPv6AcceptRA=yes
% if config.get('forwarding', False):
IPForward=yes
%endif
[DHCPv4]
UseDomains=false
UseHostname=no
UseMTU=true
UseNTP=false
UseTimezone=no
SendHostname=no
% else:
DHCP=no
% endif
% for vlan in sorted(config.get('vlans', set())):
VLAN=${interface}.${vlan}
% 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 'vlans' in config:
raise BundleError(f'{node.name} interface {interface} cannot use vlans and dhcp!')
template = 'template-iface-dhcp.network'
else:
template = 'template-iface-nodhcp.network'
all_interfaces_use_dhcp = False
if '.' in interface:
@ -80,7 +78,7 @@ for interface, config in node.metadata.get('interfaces').items():
if not config.get('ignore', False):
files[f'/etc/systemd/network/{interface}.network'] = {
'source': template,
'source': 'template-iface.network',
'content_type': 'mako',
'context': {
'interface': interface,