remove network metadata from dummy nodes

This commit is contained in:
cronekorkn 2022-10-08 00:11:00 +02:00
parent 2d77fa8d10
commit 89e25b4ca3
Signed by: cronekorkn
SSH key fingerprint: SHA256:v0410ZKfuO1QHdgKBsdQNF64xmTxOF8osF1LIqwTcVw
11 changed files with 64 additions and 50 deletions

View file

@ -98,7 +98,7 @@ def zfs(metadata):
def dns(metadata):
return {
'dns': {
metadata.get('backup-server/hostname'): repo.libs.dns.get_a_records(metadata),
metadata.get('backup-server/hostname'): repo.libs.ip.get_a_records(metadata),
}
}

View file

@ -92,7 +92,7 @@ def master_slave(metadata):
def dns(metadata):
return {
'dns': {
metadata.get('bind/hostname'): repo.libs.dns.get_a_records(metadata),
metadata.get('bind/hostname'): repo.libs.ip.get_a_records(metadata),
}
}

View file

@ -66,7 +66,7 @@ def domain(metadata):
'domain': metadata.get('grafana/hostname'),
},
},
},
},
}
@metadata_reactor.provides(
@ -74,7 +74,7 @@ def domain(metadata):
)
def influxdb2(metadata):
influxdb_metadata = repo.get_node(metadata.get('grafana/influxdb_node')).metadata.get('influxdb')
return {
'grafana': {
'datasources': {
@ -93,7 +93,7 @@ def influxdb2(metadata):
'isDefault': True,
},
},
},
},
}
@ -106,7 +106,7 @@ def datasource_key_to_name(metadata):
'datasources': {
name: {'name': name} for name in metadata.get('grafana/datasources').keys()
},
},
},
}
@ -116,7 +116,7 @@ def datasource_key_to_name(metadata):
def dns(metadata):
return {
'dns': {
metadata.get('grafana/hostname'): repo.libs.dns.get_a_records(metadata),
metadata.get('grafana/hostname'): repo.libs.ip.get_a_records(metadata),
}
}

View file

@ -23,6 +23,6 @@ def hostname_file(metadata):
def dns(metadata):
return {
'dns': {
metadata.get('hostname'): repo.libs.dns.get_a_records(metadata),
metadata.get('hostname'): repo.libs.ip.get_a_records(metadata),
},
}

View file

@ -68,7 +68,7 @@ def zfs(metadata):
def dns(metadata):
return {
'dns': {
metadata.get('influxdb/hostname'): repo.libs.dns.get_a_records(metadata),
metadata.get('influxdb/hostname'): repo.libs.ip.get_a_records(metadata),
}
}

View file

@ -87,7 +87,7 @@ def vhosts(metadata):
def dns(metadata):
return {
'dns': {
domain: repo.libs.dns.get_a_records(metadata, internal=config.get('internal_dns', True))
domain: repo.libs.ip.get_a_records(metadata, internal=config.get('internal_dns', True))
for domain, config in metadata.get('nginx/vhosts').items()
},
}

View file

@ -1,4 +1,5 @@
from ipaddress import ip_interface
from ipaddress import ip_address, ip_interface
defaults = {
'apt': {
@ -6,7 +7,7 @@ defaults = {
'clamav': {},
'clamav-daemon': {},
'clamav-freshclam': {},
'clamav-unofficial-sigs': {},
'clamav-unofficial-sigs': {},
'rspamd': {},
},
},
@ -44,10 +45,6 @@ def nginx_vhost(metadata):
def ignored_ips(metadata):
return {
'rspamd': {
'ip_whitelist': {
str(ip_interface(network['ipv4']).ip)
for other_node in repo.nodes
for network in other_node.metadata.get('network').values()
}
'ip_whitelist': repo.libs.ip.get_all_ips(repo.nodes),
},
}

View file

@ -1,23 +0,0 @@
from ipaddress import ip_interface
def get_a_records(metadata, internal=True, external=True):
networks = metadata.get('network')
if not internal:
networks.pop('internal', None)
if not external:
networks.pop('external', None)
return {
'A': [
str(ip_interface(network['ipv4']).ip)
for network in networks.values()
if 'ipv4' in network
],
'AAAA': [
str(ip_interface(network['ipv6']).ip)
for network in networks.values()
if 'ipv6' in network
],
}

48
libs/ip.py Normal file
View file

@ -0,0 +1,48 @@
from ipaddress import ip_address, ip_interface
def get_a_records(metadata, internal=True, external=True):
networks = metadata.get('network')
if not internal:
networks.pop('internal', None)
if not external:
networks.pop('external', None)
return {
'A': [
str(ip_interface(network['ipv4']).ip)
for network in networks.values()
if 'ipv4' in network
],
'AAAA': [
str(ip_interface(network['ipv6']).ip)
for network in networks.values()
if 'ipv6' in network
],
}
def get_all_ips(nodes):
ips = set()
for node in nodes:
try:
ip_address(node.hostname)
except ValueError:
pass
else:
ips.add(node.hostname)
if node.has_bundle('network'):
for network in node.metadata.get('network').values():
if 'ipv4' in network:
ips.add(str(ip_interface(network['ipv4']).ip))
if 'ipv6' in network:
ips.add(str(ip_interface(network['ipv6']).ip))
if node.has_bundle('wireguard'):
ips.add(str(ip_interface(node.metadata.get('wireguard/my_ip')).ip))
return ips

View file

@ -1,15 +1,11 @@
{
'dummy': True,
'hostname': '10.0.2.100',
'groups': [
'home',
],
'metadata': {
'id': '',
'network': {
'internal': {
'ipv4': '10.0.2.100/24',
},
},
'dns': {
'hue.ckn.li': {
'A': {'10.0.2.100'},

View file

@ -1,15 +1,11 @@
{
'dummy': True,
'hostname': '10.0.0.4',
'groups': [
'home',
],
'metadata': {
'id': '',
'network': {
'internal': {
'ipv4': '10.0.0.4/24',
},
},
'dns': {
'unifi.ckn.li': {
'A': {'10.0.0.4'},