This commit is contained in:
mwiegand 2021-06-26 12:21:15 +02:00
parent 609ef98ca2
commit f37e2d2fbd
7 changed files with 85 additions and 55 deletions

View file

@ -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
]
},
},

View file

@ -1,6 +1,8 @@
defaults = {
'network': {
'external': {
'gateway4': '172.31.1.1',
'gateway6': 'fe80::1',
},
},
}

View file

@ -1,13 +1,21 @@
from ipaddress import ip_interface
defaults = {
'network': {
}
}
@metadata_reactor.provides(
'systemd-networkd/networks',
)
def interfaces(metadata):
network = {
def systemd_networkd(metadata):
units = {}
for type, network in metadata.get('network').items():
units[type] = {
'Match': {
'Name': metadata.get('network/interface'),
'Name': network['interface'],
},
'Network': {
'DHCP': 'no',
@ -16,22 +24,20 @@ def interfaces(metadata):
}
for i in [4, 6]:
if metadata.get(f'network/ipv{i}', None):
network.update({
if network.get(f'ipv{i}', None):
units[type].update({
f'Address#ipv{i}': {
'Address': metadata.get(f'network/ipv{i}'),
'Address': network[f'ipv{i}'],
},
f'Route#ipv{i}': {
'Gateway': metadata.get(f'network/gateway{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 {}
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': {
'gateway4': str(
ip_interface(metadata.get('network/ipv4')).network[1]
),
}
'network': networks,
}

View file

@ -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,

View file

@ -13,9 +13,11 @@
'hostname': 'backups.sublimity.de',
},
'network': {
'internal': {
'interface': 'enp1s0',
'ipv4': '10.0.0.5/24',
},
},
'zfs': {
'pools': {
'tank': {

View file

@ -13,9 +13,11 @@
'metadata': {
'id': 'af96709e-b13f-4965-a588-ef2cd476437a',
'network': {
'internal': {
'interface': 'enp1s0f0',
'ipv4': '10.0.0.2/24',
},
},
'gitea': {
'version': '1.14.2',
'sha256': '0d11d87ce60d5d98e22fc52f2c8c6ba2b54b14f9c26c767a46bf102c381ad128',

View file

@ -41,9 +41,15 @@
},
},
'network': {
'internal': {
'interface': 'ens10',
'ipv4': '10.0.10.2/32',
},
'external': {
'interface': 'eth0',
'ipv4': '162.55.188.157/32',
'ipv6': '2a01:4f8:1c1c:4121::1/64',
'ipv6': '2a01:4f8:1c1c:4121::2/64',
}
},
'nginx': {
'vhosts': {