Skip to content

Instantly share code, notes, and snippets.

@yellowcrescent
Created September 20, 2018 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yellowcrescent/6d7ad1c814776841c37436a028680336 to your computer and use it in GitHub Desktop.
Save yellowcrescent/6d7ad1c814776841c37436a028680336 to your computer and use it in GitHub Desktop.
PowerDNS-Admin changes
diff --git a/app/models.py b/app/models.py
index 9a116b8..503a0f7 100644
--- a/app/models.py
+++ b/app/models.py
@@ -1015,6 +1015,7 @@ class Record(object):
records.append(new_srr)
logging.info("%s new SOA serial --> %s", domain_dot, newser)
else:
+ newser = None
logging.error("Failed to retrieve SOA record for domain")
@@ -1074,24 +1075,12 @@ class Record(object):
postdata_for_new = {"rrsets": final_records}
+ # Apply zone updates
try:
headers = {}
headers['X-API-Key'] = PDNS_API_KEY
jdata1 = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones/%s' % domain), headers=headers, method='PATCH', data=postdata_for_delete)
jdata2 = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones/%s' % domain), headers=headers, method='PATCH', data=postdata_for_new)
- jdata3 = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones/%s/notify' % domain), headers=headers, method='PUT')
-
- logging.debug("NOTIFY data (jdata3):", jdata3)
- if 'result' in jdata3:
- if 'queued' in jdata3['result']:
- notify_ok = True
- logging.info('NOTIFY queued successfully for zone update on slave')
- else:
- notify_ok = False
- logging.error('NOTIFY failed for zone (not queued)')
- else:
- notify_ok = False
- logging.error('NOTIFY failed for zone (no result)')
if 'error' in jdata2.keys():
logging.error('Cannot apply record changes.')
@@ -1100,10 +1089,30 @@ class Record(object):
else:
self.auto_ptr(domain, new_records, deleted_records)
logging.info('Record was applied successfully.')
- return {'status': 'ok', 'msg': 'Record was applied successfully'}
+
except Exception, e:
logging.error("Cannot apply record changes to domain %s. DETAIL: %s" % (str(e), domain))
- return {'status': 'error', 'msg': 'There was something wrong, please contact administrator'}
+ return {'status': 'error', 'msg': 'There was something wrong, please contact administrator.'}
+
+ # Send NOTIFY
+ try:
+ jdata3 = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones/%s/notify' % domain), headers=headers, method='PUT')
+ except Exception as e:
+ logging.error("Failed to sent NOTIFY for domain %s. DETAIL: %s" % (str(e), domain))
+ return {'status': 'error', 'msg': 'DNS record updated successfully, but failed to send NOTIFYs to slaves.'}
+
+ if 'result' in jdata3:
+ if 'queued' in jdata3['result']:
+ notify_ok = True
+ logging.info('NOTIFY queued successfully for zone update on slave')
+ else:
+ notify_ok = False
+ logging.error('NOTIFY failed for zone (not queued)')
+ else:
+ notify_ok = False
+ logging.error('NOTIFY failed for zone (no result)')
+
+ return {'status': 'ok', 'msg': 'Update(s) applied successfully. New SOA serial: %s' % (newser)}
def auto_ptr(self, domain, new_records, deleted_records):
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment