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': {
'gateway4': '172.31.1.1',
'gateway6': 'fe80::1',
'external': {
'gateway4': '172.31.1.1',
'gateway6': 'fe80::1',
},
},
}

View file

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

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,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': {

View file

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

View file

@ -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': {