From 7281290057bc3d7dffaa97ae1bb7732344702bf3 Mon Sep 17 00:00:00 2001 From: Benjamin Graillot Date: Mon, 24 Dec 2018 10:46:34 +0100 Subject: [PATCH] =?UTF-8?q?Augmente=20le=20serial=20=C3=A0=20chaque=20maj?= =?UTF-8?q?=20des=20zones?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index c8ca082..82f25de 100755 --- a/main.py +++ b/main.py @@ -2,6 +2,7 @@ import argparse from configparser import ConfigParser import datetime +import json from multiprocessing import Pool import netaddr import os @@ -81,12 +82,19 @@ template_reverse = ( "{ptr_records}\n" ) +try: + with open(path + '/serial.json') as serial_json: + serial = json.load(serial_json) +except: + serial = 1 def write_dns_file(zone): + global serial + zone_name = zone['name'][1:] now = datetime.datetime.now(datetime.timezone.utc) - serial = now.strftime("%Y%m%d") + str(int(100*(now.hour*3600 + now.minute*60 + now.second)/86400)) + #serial = now.strftime("%Y%m%d") + str(int(100*(now.hour*3600 + now.minute*60 + now.second)/86400)) soa_mail_fields = zone['soa']['mail'].split('@') soa_mail = "{}.{}.".format(soa_mail_fields[0].replace('.', '\\.'), @@ -411,6 +419,8 @@ if __name__ == '__main__': if args.force: write_dns_files(api_client, args.processes[0]) write_dns_reverse_file(api_client) + with open(path + '/serial.json', 'w') as serial_json: + json.dump(serial + 1, serial_json) if not args.keep: for service in api_client.list("services/regen/"): if service['hostname'] == client_hostname and \ @@ -418,14 +428,19 @@ if __name__ == '__main__': service['need_regen']: api_client.patch(service['api_url'], data={'need_regen': False}) else: + increase_serial = False for service in api_client.list("services/regen/"): if service['hostname'] == client_hostname and \ service['service_name'] == 'dns' and \ service['need_regen']: + increase_serial = True write_dns_files(api_client, args.processes[0]) write_dns_reverse_file(api_client) if not args.keep: api_client.patch(service['api_url'], data={'need_regen': False}) + if increase_serial: + with open(path + '/serial.json', 'w') as serial_json: + json.dump(serial + 1, serial_json) if not args.no_reload: error = os.system('/usr/sbin/knotc zone-reload >/dev/null 2>&1')