bind slave: dont replace zones all the time

This commit is contained in:
mwiegand 2021-11-18 23:47:55 +01:00
parent 604e01f16e
commit 87861aae98

View file

@ -1,5 +1,9 @@
from ipaddress import ip_address, ip_interface from ipaddress import ip_address, ip_interface
from datetime import datetime from datetime import datetime
import json
from bundlewrap.metadata import MetadataJSONEncoder
from hashlib import sha3_512
if node.metadata.get('bind/type') == 'master': if node.metadata.get('bind/type') == 'master':
master_node = node master_node = node
@ -109,31 +113,41 @@ for view_name, view_conf in master_node.metadata.get('bind/views').items():
} }
for zone_name, zone_conf in view_conf['zones'].items(): for zone_name, zone_conf in view_conf['zones'].items():
files[f"/var/lib/bind/{view_name}/{zone_name}"] = { if node.metadata.get('bind/type') == 'master':
'owner': 'bind', files[f"/var/lib/bind/{view_name}/{zone_name}"] = {
'group': 'bind', 'source': 'db',
'needs': [ 'content_type': 'mako',
f"directory:/var/lib/bind/{view_name}", 'unless': f"test -f /var/lib/bind/{view_name}/{zone_name}" if zone_conf.get('allow_update', False) else 'false',
], 'context': {
'needed_by': [ 'serial': datetime.now().strftime('%Y%m%d%H'),
'svc_systemd:bind9', 'records': zone_conf['records'],
], 'hostname': node.metadata.get('bind/hostname'),
'triggers': [ 'type': node.metadata.get('bind/type'),
'svc_systemd:bind9:restart', },
], 'owner': 'bind',
} 'group': 'bind',
#FIXME: slave doesnt get updated if db doesnt get rewritten on each apply 'needed_by': [
files[f"/var/lib/bind/{view_name}/{zone_name}"].update({ 'svc_systemd:bind9',
'source': 'db', ],
'content_type': 'mako', 'triggers': [
'unless': f"test -f /var/lib/bind/{view_name}/{zone_name}" if zone_conf.get('allow_update', False) else 'false', 'svc_systemd:bind9:restart',
'context': { ],
'serial': datetime.now().strftime('%Y%m%d%H'), }
'records': zone_conf['records'], else:
'hostname': node.metadata.get('bind/hostname'), files[f"/var/lib/bind/{view_name}/{zone_name}"] = {
'type': node.metadata.get('bind/type'), 'content_type': 'any',
}, 'owner': 'bind',
}) 'group': 'bind',
}
if node.metadata.get('bind/type') == 'slave':
files[f"/var/lib/bind/diff"] = {
'content': sha3_512(json.dumps(master_node.metadata.get('bind'), cls=MetadataJSONEncoder, sort_keys=True).encode()).hexdigest(),
'triggers': [
'svc_systemd:bind9:restart',
],
}
svc_systemd['bind9'] = {} svc_systemd['bind9'] = {}