Commit 90f9d15c authored by Benjamin Graillot's avatar Benjamin Graillot Committed by root

Fix des records A, AAAA et CNAME portant le nom de zones

parent 64ee985f
......@@ -73,7 +73,16 @@ template_reverse = ("$TTL 2D\n"
def write_dns_files(api_client):
for zone in api_client.list("dns/zones"):
dns_zones = api_client.list("dns/zones")
zone_names = {zone['name'][1:] for zone in dns_zones}
records_to_add = {name: {'a': [], 'aaaa': [], 'cname': []} for name in zone_names}
def add_record(zone, record, type):
nonlocal records_to_add
records_to_add[zone][type].append(record)
return False
for zone in sorted(dns_zones, key=lambda zone:zone['name'].count('.')):
zone_name = zone['name'][1:]
now = datetime.datetime.now(datetime.timezone.utc)
......@@ -146,6 +155,7 @@ def write_dns_files(api_client):
template_a.format(hostname=x['hostname'],
ipv4=x['ipv4'])
for x in zone['a_records']
if (True if x['hostname'] + '.' + zone_name not in zone_names else add_record(x['hostname'] + '.' + zone_name, template_a.format(hostname='@', ipv4=ip['ipv4']), 'a'))
)
aaaa_records = "\n".join(
......@@ -153,14 +163,25 @@ def write_dns_files(api_client):
ipv6=ip['ipv6'])
for x in zone['aaaa_records']
for ip in x['ipv6']
if x['ipv6'] is not None
if x['ipv6'] is not None
and (True if x['hostname'] + '.' + zone_name not in zone_names else add_record(x['hostname'] + '.' + zone_name, template_aaaa.format(hostname='@', ipv6=ip['ipv6']), 'aaaa'))
)
cname_records = "\n".join(
template_cname.format(hostname=x['hostname'],
alias=x['alias'])
for x in zone['cname_records']
if (True if x['hostname'] + '.' + zone_name not in zone_names else add_record(x['hostname'] + '.' + zone_name, template_cname.format(hostname='@', alias=x['alias']), 'cname'))
)
if records_to_add[zone_name]['a']:
a_records += "\n" + "\n".join(records_to_add[zone_name]['a'])
if records_to_add[zone_name]['aaaa']:
aaaa_records += "\n" + "\n".join(records_to_add[zone_name]['aaaa'])
if records_to_add[zone_name]['cname']:
cname_records += "\n" + "\n".join(records_to_add[zone_name]['cname'])
zone_file_content = template_zone.format(soa=soa,
originv4=originv4,
......@@ -340,4 +361,6 @@ for service in api_client.list("services/regen/"):
write_dns_files(api_client)
write_dns_reverse_file(api_client)
api_client.patch(service['api_url'], data={'need_regen': False})
os.system('/usr/sbin/knotc zone-reload >/dev/null 2>&1')
ok = os.system('/usr/sbin/knotc zone-reload >/dev/null 2>&1')
if not ok:
os.system('/usr/sbin/knotc zone-reload')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment