Added error-handling

master
Ruakij 3 years ago
parent 71d46c7710
commit 503ecd8557

@ -121,16 +121,21 @@ def readYamlFile(file: str):
return yaml.load(f, Loader=yaml.FullLoader) return yaml.load(f, Loader=yaml.FullLoader)
def updateNsData(zone): def updateNsData(zone):
adaptedZone = adaptZoneName(zone) try:
adaptedZone = adaptZoneName(zone)
log.info(f'{adaptedZone} |\tUpdating NS-Data') log.info(f'{adaptedZone} |\tUpdating NS-Data')
dumpFile = f"{adaptedZone}.dump.js" dumpFile = f"{adaptedZone}.dump.js"
dumpZoneData(zone, dumpFile) if dumpZoneData(zone, dumpFile) != 0:
zone = adaptedZone raise "Dumping data failed!"
zone = adaptedZone
adaptFileForRequire(zone, dumpFile) adaptFileForRequire(zone, dumpFile)
dnscontrolPush(zone) if dnscontrolPush(zone) != 0:
raise "Pushing data failed!"
except:
log.error(f'{adaptedZone} |\tUpdating NS-Data failed!')
def adaptZoneName(zone): def adaptZoneName(zone):
if config['zone']['public-suffix'] != "" and zone.endswith(config['zone']['public-suffix']): if config['zone']['public-suffix'] != "" and zone.endswith(config['zone']['public-suffix']):
@ -140,7 +145,7 @@ def adaptZoneName(zone):
def dumpZoneData(zone, dumpFile): def dumpZoneData(zone, dumpFile):
log.debug(f'{zone} |\tDumping..') log.debug(f'{zone} |\tDumping..')
os.system(f"dnscontrol get-zones --format=js --out={dumpFile} powerdns POWERDNS {zone}") return os.system(f"dnscontrol get-zones --format=js --out={dumpFile} powerdns POWERDNS {zone}")
ignoreLinesRexp = r"^\s*(var|D\(|DnsProvider\(|DefaultTTL\()" ignoreLinesRexp = r"^\s*(var|D\(|DnsProvider\(|DefaultTTL\()"
def adaptFileForRequire(zone, dumpFile): def adaptFileForRequire(zone, dumpFile):
@ -157,7 +162,7 @@ def adaptFileForRequire(zone, dumpFile):
def dnscontrolPush(zone): def dnscontrolPush(zone):
log.debug(f'{zone} |\tPushing..') log.debug(f'{zone} |\tPushing..')
os.system(f"dnscontrol push --domains {zone}") return os.system(f"dnscontrol push --domains {zone}")
if __name__ == "__main__": if __name__ == "__main__":
sys.exit(main(sys.argv)) sys.exit(main(sys.argv))

Loading…
Cancel
Save