Compare commits
No commits in common. "6e9610d797797b73b60c2f90ea6c45b639bd35cf" and "10eaaa7e128add2146c3994300d47e293a1855c4" have entirely different histories.
6e9610d797
...
10eaaa7e12
4 changed files with 19 additions and 9 deletions
|
@ -1,4 +1,5 @@
|
||||||
from ipaddress import ip_interface
|
from ipaddress import ip_interface
|
||||||
|
hdict, hlist = repo.libs.hashable.hdict, repo.libs.hashable.hlist
|
||||||
|
|
||||||
|
|
||||||
defaults = {
|
defaults = {
|
||||||
|
@ -75,9 +76,9 @@ def collect_records(metadata):
|
||||||
for type, values in records.items():
|
for type, values in records.items():
|
||||||
for value in values:
|
for value in values:
|
||||||
zones\
|
zones\
|
||||||
.setdefault(zone, [])\
|
.setdefault(zone, set())\
|
||||||
.append(
|
.add(
|
||||||
{'name': name, 'type': type, 'value': value}
|
hdict({'name': name, 'type': type, 'value': value})
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -104,10 +105,10 @@ def ns_records(metadata):
|
||||||
return {
|
return {
|
||||||
'bind': {
|
'bind': {
|
||||||
'zones': {
|
'zones': {
|
||||||
zone: [
|
zone: {
|
||||||
{'name': '@', 'type': 'NS', 'value': f"{nameserver}."}
|
hdict({'name': '@', 'type': 'NS', 'value': f"{nameserver}."})
|
||||||
for nameserver in nameservers
|
for nameserver in nameservers
|
||||||
] for zone in metadata.get('bind/zones').keys()
|
} for zone in metadata.get('bind/zones').keys()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,10 +90,10 @@ def systemd_networkd_netdevs(metadata):
|
||||||
'Endpoint': config['endpoint'],
|
'Endpoint': config['endpoint'],
|
||||||
'PublicKey': config['pubkey'],
|
'PublicKey': config['pubkey'],
|
||||||
'PresharedKey': config['psk'],
|
'PresharedKey': config['psk'],
|
||||||
'AllowedIPs': ', '.join(sorted([
|
'AllowedIPs': ', '.join([
|
||||||
str(ip_interface(repo.get_node(peer).metadata.get(f'wireguard/my_ip')).ip),
|
str(ip_interface(repo.get_node(peer).metadata.get(f'wireguard/my_ip')).ip),
|
||||||
*config.get('route', []),
|
*config.get('route', []),
|
||||||
])), # FIXME
|
]), # FIXME
|
||||||
'PersistentKeepalive': 30,
|
'PersistentKeepalive': 30,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
9
libs/hashable.py
Normal file
9
libs/hashable.py
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
class hdict(dict):
|
||||||
|
def __hash__(self):
|
||||||
|
return hash(json.dumps(self, sorted=True))
|
||||||
|
|
||||||
|
class hlist(list):
|
||||||
|
def __hash__(self):
|
||||||
|
return hash(json.dumps(self, sorted=True))
|
|
@ -9,7 +9,7 @@ template = '''
|
||||||
[${segment.split('#')[0]}]
|
[${segment.split('#')[0]}]
|
||||||
% for option, value in sorted(options.items()):
|
% for option, value in sorted(options.items()):
|
||||||
% if isinstance(value, dict):
|
% if isinstance(value, dict):
|
||||||
% for k, v in sorted(value.items()):
|
% for k, v in value.items():
|
||||||
${option}=${k}=${v}
|
${option}=${k}=${v}
|
||||||
% endfor
|
% endfor
|
||||||
% elif isinstance(value, (list, set, tuple)):
|
% elif isinstance(value, (list, set, tuple)):
|
||||||
|
|
Loading…
Reference in a new issue