From d067f98c1b5112629f44bce6e18204d46b3ab174 Mon Sep 17 00:00:00 2001 From: mwiegand Date: Mon, 28 Jun 2021 23:03:05 +0200 Subject: [PATCH] wip --- bundles/hetzner-cloud/metadata.py | 16 +++++++------- bundles/network/metadata.py | 35 +++++++------------------------ nodes/home.backups.py | 1 + nodes/home.server.py | 1 + nodes/htz.mails.py | 10 +++++++-- nodes/netcup.secondary.py | 2 +- 6 files changed, 27 insertions(+), 38 deletions(-) diff --git a/bundles/hetzner-cloud/metadata.py b/bundles/hetzner-cloud/metadata.py index fb753ed..e73592c 100644 --- a/bundles/hetzner-cloud/metadata.py +++ b/bundles/hetzner-cloud/metadata.py @@ -1,8 +1,8 @@ -defaults = { - 'network': { - 'external': { - 'gateway4': '172.31.1.1', - 'gateway6': 'fe80::1', - }, - }, -} +# defaults = { +# 'network': { +# 'external': { +# 'gateway4': '172.31.1.1', +# 'gateway6': 'fe80::1', +# }, +# }, +# } diff --git a/bundles/network/metadata.py b/bundles/network/metadata.py index 1640d58..bd97df3 100644 --- a/bundles/network/metadata.py +++ b/bundles/network/metadata.py @@ -29,37 +29,18 @@ def systemd_networkd(metadata): f'Address#ipv{i}': { 'Address': network[f'ipv{i}'], }, - f'Route#ipv{i}': { - 'Gateway': network[f'gateway{i}'], - 'GatewayOnlink': 'yes', - } }) + if f'gateway{i}' in network: + units[type].update({ + f'Route#ipv{i}': { + 'Gateway': network[f'gateway{i}'], + 'GatewayOnlink': 'yes', + } + }) + return { 'systemd-networkd': { 'networks': units, } } - - -@metadata_reactor.provides( - 'network/gateway4', - 'network/gateway6', -) -def guess_gateway(metadata): - 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/nodes/home.backups.py b/nodes/home.backups.py index 5251497..62dadf1 100644 --- a/nodes/home.backups.py +++ b/nodes/home.backups.py @@ -16,6 +16,7 @@ 'internal': { 'interface': 'enp1s0', 'ipv4': '10.0.0.5/24', + 'gateway4': '10.0.0.1', }, }, 'zfs': { diff --git a/nodes/home.server.py b/nodes/home.server.py index 2daa055..9e8a597 100644 --- a/nodes/home.server.py +++ b/nodes/home.server.py @@ -17,6 +17,7 @@ 'internal': { 'interface': 'enp1s0f0', 'ipv4': '10.0.0.2/24', + 'gateway4': '10.0.0.1', }, }, 'gitea': { diff --git a/nodes/htz.mails.py b/nodes/htz.mails.py index e93deb1..8b15b8b 100644 --- a/nodes/htz.mails.py +++ b/nodes/htz.mails.py @@ -49,6 +49,8 @@ 'interface': 'eth0', 'ipv4': '162.55.188.157/32', 'ipv6': '2a01:4f8:1c1c:4121::2/64', + 'gateway4': '172.31.1.1', + 'gateway6': 'fe80::1', } }, 'nginx': { @@ -107,9 +109,13 @@ '10.0.0.0/24', '10.0.2.0/24', '10.0.9.0/24', - ] + ], + }, + 'netcup.secondary': { + 'route': [ + '46.38.240.0/22', + ], }, - 'netcup.secondary': {}, }, }, 'zfs': { diff --git a/nodes/netcup.secondary.py b/nodes/netcup.secondary.py index fc43291..276f7e3 100644 --- a/nodes/netcup.secondary.py +++ b/nodes/netcup.secondary.py @@ -15,7 +15,7 @@ 'gateway4': '46.38.240.1', 'ipv6': '2a03:4000:7:534::2/64', 'gateway6': 'fe80::1', - } + }, }, 'wireguard': { 'my_ip': '172.19.136.3/22',