Augmente le serial à chaque maj des zones
This commit is contained in:
parent
47680039aa
commit
7281290057
1 changed files with 16 additions and 1 deletions
17
main.py
17
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')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue