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': { 'dns': {
metadata.get('bind/domain'): { metadata.get('bind/domain'): {
'A': [ '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': [ '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 = { defaults = {
'network': { 'network': {
'gateway4': '172.31.1.1', 'external': {
'gateway6': 'fe80::1', 'gateway4': '172.31.1.1',
'gateway6': 'fe80::1',
},
}, },
} }

View file

@ -1,37 +1,43 @@
from ipaddress import ip_interface from ipaddress import ip_interface
defaults = {
'network': {
}
}
@metadata_reactor.provides( @metadata_reactor.provides(
'systemd-networkd/networks', 'systemd-networkd/networks',
) )
def interfaces(metadata): def systemd_networkd(metadata):
network = { units = {}
'Match': {
'Name': metadata.get('network/interface'),
},
'Network': {
'DHCP': 'no',
'IPv6AcceptRA': 'no',
}
}
for i in [4, 6]: for type, network in metadata.get('network').items():
if metadata.get(f'network/ipv{i}', None): units[type] = {
network.update({ 'Match': {
f'Address#ipv{i}': { 'Name': network['interface'],
'Address': metadata.get(f'network/ipv{i}'), },
}, 'Network': {
f'Route#ipv{i}': { 'DHCP': 'no',
'Gateway': metadata.get(f'network/gateway{i}'), 'IPv6AcceptRA': 'no',
'GatewayOnlink': 'yes', }
} }
})
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 { return {
'systemd-networkd': { 'systemd-networkd': {
'networks': { 'networks': units,
metadata.get('network/interface'): network,
}
} }
} }
@ -41,13 +47,19 @@ def interfaces(metadata):
'network/gateway6', 'network/gateway6',
) )
def guess_gateway(metadata): def guess_gateway(metadata):
if metadata.get('network/gateway4', None): networks = {}
return {}
else: for type, network in metadata.get('network').items():
return { if not network.get('gateway4', None):
'network': { if ip_interface(network['ipv4']).network.prefixlen == 32:
'gateway4': str( networks[type] = {
ip_interface(metadata.get('network/ipv4')).network[1] 'gateway4': str(ip_interface(network['ipv4']).network[0]),
), }
} else:
} networks[type] = {
'gateway4': str(ip_interface(network['ipv4']).network[1]),
}
return {
'network': networks,
}

View file

@ -19,16 +19,18 @@ def dns(metadata):
dns = {} dns = {}
for config in metadata.get('nginx/vhosts', {}).values(): for config in metadata.get('nginx/vhosts', {}).values():
dns[config['domain']] = {} dns[config['domain']] = {
'A': [
if metadata.get('network/ipv4'): str(ip_interface(network['ipv4']).ip)
dns[config['domain']]['A'] = [ for network in metadata.get('network').values()
str(ip_interface(metadata.get('network/ipv4')).ip) if 'ipv4' in network
] ],
if metadata.get('network/ipv6'): 'AAAA': [
dns[config['domain']]['AAAA'] = [ str(ip_interface(network['ipv6']).ip)
str(ip_interface(metadata.get('network/ipv6')).ip) for network in metadata.get('network').values()
] if 'ipv6' in network
],
}
return { return {
'dns': dns, 'dns': dns,

View file

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

View file

@ -13,8 +13,10 @@
'metadata': { 'metadata': {
'id': 'af96709e-b13f-4965-a588-ef2cd476437a', 'id': 'af96709e-b13f-4965-a588-ef2cd476437a',
'network': { 'network': {
'interface': 'enp1s0f0', 'internal': {
'ipv4': '10.0.0.2/24', 'interface': 'enp1s0f0',
'ipv4': '10.0.0.2/24',
},
}, },
'gitea': { 'gitea': {
'version': '1.14.2', 'version': '1.14.2',

View file

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