diff --git a/bundles/bind/metadata.py b/bundles/bind/metadata.py index e537b9e..ae32b71 100644 --- a/bundles/bind/metadata.py +++ b/bundles/bind/metadata.py @@ -21,10 +21,14 @@ def dns(metadata): 'dns': { metadata.get('bind/domain'): { 'A': [ - str(ip_interface(metadata.get('network/ipv4')).ip), + str(ip_interface(network['ipv4']).ip) + for network in metadata.get('network').values() + if 'ipv4' in network ], 'AAAA': [ - str(ip_interface(metadata.get('network/ipv6')).ip), + str(ip_interface(network['ipv6']).ip) + for network in metadata.get('network').values() + if 'ipv6' in network ] }, }, diff --git a/bundles/hetzner-cloud/metadata.py b/bundles/hetzner-cloud/metadata.py index b09f962..fb753ed 100644 --- a/bundles/hetzner-cloud/metadata.py +++ b/bundles/hetzner-cloud/metadata.py @@ -1,6 +1,8 @@ defaults = { 'network': { - 'gateway4': '172.31.1.1', - 'gateway6': 'fe80::1', + 'external': { + 'gateway4': '172.31.1.1', + 'gateway6': 'fe80::1', + }, }, } diff --git a/bundles/network/metadata.py b/bundles/network/metadata.py index 08cab3c..1640d58 100644 --- a/bundles/network/metadata.py +++ b/bundles/network/metadata.py @@ -1,37 +1,43 @@ from ipaddress import ip_interface +defaults = { + 'network': { + } +} + @metadata_reactor.provides( 'systemd-networkd/networks', ) -def interfaces(metadata): - network = { - 'Match': { - 'Name': metadata.get('network/interface'), - }, - 'Network': { - 'DHCP': 'no', - 'IPv6AcceptRA': 'no', - } - } +def systemd_networkd(metadata): + units = {} - for i in [4, 6]: - if metadata.get(f'network/ipv{i}', None): - network.update({ - f'Address#ipv{i}': { - 'Address': metadata.get(f'network/ipv{i}'), - }, - f'Route#ipv{i}': { - 'Gateway': metadata.get(f'network/gateway{i}'), - 'GatewayOnlink': 'yes', - } - }) + for type, network in metadata.get('network').items(): + units[type] = { + 'Match': { + 'Name': network['interface'], + }, + 'Network': { + 'DHCP': 'no', + 'IPv6AcceptRA': 'no', + } + } + + for i in [4, 6]: + if network.get(f'ipv{i}', None): + units[type].update({ + f'Address#ipv{i}': { + 'Address': network[f'ipv{i}'], + }, + f'Route#ipv{i}': { + 'Gateway': network[f'gateway{i}'], + 'GatewayOnlink': 'yes', + } + }) return { 'systemd-networkd': { - 'networks': { - metadata.get('network/interface'): network, - } + 'networks': units, } } @@ -41,13 +47,19 @@ def interfaces(metadata): 'network/gateway6', ) def guess_gateway(metadata): - if metadata.get('network/gateway4', None): - return {} - else: - return { - 'network': { - 'gateway4': str( - ip_interface(metadata.get('network/ipv4')).network[1] - ), - } - } + networks = {} + + for type, network in metadata.get('network').items(): + if not network.get('gateway4', None): + if ip_interface(network['ipv4']).network.prefixlen == 32: + networks[type] = { + 'gateway4': str(ip_interface(network['ipv4']).network[0]), + } + else: + networks[type] = { + 'gateway4': str(ip_interface(network['ipv4']).network[1]), + } + + return { + 'network': networks, + } diff --git a/bundles/nginx/metadata.py b/bundles/nginx/metadata.py index 2008a46..18051c2 100644 --- a/bundles/nginx/metadata.py +++ b/bundles/nginx/metadata.py @@ -19,16 +19,18 @@ def dns(metadata): dns = {} for config in metadata.get('nginx/vhosts', {}).values(): - dns[config['domain']] = {} - - if metadata.get('network/ipv4'): - dns[config['domain']]['A'] = [ - str(ip_interface(metadata.get('network/ipv4')).ip) - ] - if metadata.get('network/ipv6'): - dns[config['domain']]['AAAA'] = [ - str(ip_interface(metadata.get('network/ipv6')).ip) - ] + dns[config['domain']] = { + 'A': [ + str(ip_interface(network['ipv4']).ip) + for network in metadata.get('network').values() + if 'ipv4' in network + ], + 'AAAA': [ + str(ip_interface(network['ipv6']).ip) + for network in metadata.get('network').values() + if 'ipv6' in network + ], + } return { 'dns': dns, diff --git a/nodes/home.backups.py b/nodes/home.backups.py index c52b4f2..5251497 100644 --- a/nodes/home.backups.py +++ b/nodes/home.backups.py @@ -13,8 +13,10 @@ 'hostname': 'backups.sublimity.de', }, 'network': { - 'interface': 'enp1s0', - 'ipv4': '10.0.0.5/24', + 'internal': { + 'interface': 'enp1s0', + 'ipv4': '10.0.0.5/24', + }, }, 'zfs': { 'pools': { diff --git a/nodes/home.server.py b/nodes/home.server.py index 206e471..72664db 100644 --- a/nodes/home.server.py +++ b/nodes/home.server.py @@ -13,8 +13,10 @@ 'metadata': { 'id': 'af96709e-b13f-4965-a588-ef2cd476437a', 'network': { - 'interface': 'enp1s0f0', - 'ipv4': '10.0.0.2/24', + 'internal': { + 'interface': 'enp1s0f0', + 'ipv4': '10.0.0.2/24', + }, }, 'gitea': { 'version': '1.14.2', diff --git a/nodes/htz.mails.py b/nodes/htz.mails.py index 28943d1..377f770 100644 --- a/nodes/htz.mails.py +++ b/nodes/htz.mails.py @@ -41,9 +41,15 @@ }, }, 'network': { - 'interface': 'eth0', - 'ipv4': '162.55.188.157/32', - 'ipv6': '2a01:4f8:1c1c:4121::1/64', + 'internal': { + 'interface': 'ens10', + 'ipv4': '10.0.10.2/32', + }, + 'external': { + 'interface': 'eth0', + 'ipv4': '162.55.188.157/32', + 'ipv6': '2a01:4f8:1c1c:4121::2/64', + } }, 'nginx': { 'vhosts': {