Merge pull request #95 from jallakim/update-ttl

Use correct TTL in updates
This commit is contained in:
Khanh Ngo 2016-07-29 09:46:49 +07:00 committed by GitHub
commit 998e70a642

View File

@ -858,8 +858,8 @@ class Record(object):
record = { record = {
"name": r['name'] + '.', "name": r['name'] + '.',
"type": r['type'], "type": r['type'],
"ttl": r['ttl'],
"changetype": "REPLACE", "changetype": "REPLACE",
"ttl": r['ttl'],
"records": [ "records": [
{ {
"content": r['content'], "content": r['content'],
@ -888,14 +888,14 @@ class Record(object):
# Adjustment to add multiple records which described in https://github.com/ngoduykhanh/PowerDNS-Admin/issues/5#issuecomment-181637576 # Adjustment to add multiple records which described in https://github.com/ngoduykhanh/PowerDNS-Admin/issues/5#issuecomment-181637576
final_records = [] final_records = []
records = sorted(records, key = lambda item: (item["name"], item["type"], item["changetype"]))
for key, group in itertools.groupby(records, lambda item: (item["name"], item["type"], item["changetype"])):
if NEW_SCHEMA: if NEW_SCHEMA:
records = sorted(records, key = lambda item: (item["name"], item["type"]))
for key, group in itertools.groupby(records, lambda item: (item["name"], item["type"])):
new_record = { new_record = {
"name": key[0], "name": key[0],
"type": key[1], "type": key[1],
"ttl": records[0]['ttl'], "changetype": key[2],
"changetype": "REPLACE", "ttl": None,
"records": [] "records": []
} }
for item in group: for item in group:
@ -905,18 +905,20 @@ class Record(object):
if temp_content.strip()[-1:] != '.': if temp_content.strip()[-1:] != '.':
temp_content += '.' temp_content += '.'
if new_record['ttl'] is None:
new_record['ttl'] = item['ttl']
new_record['records'].append({ new_record['records'].append({
"content": temp_content, "content": temp_content,
"disabled": temp_disabled "disabled": temp_disabled
}) })
final_records.append(new_record) final_records.append(new_record)
else: else:
records = sorted(records, key = lambda item: (item["name"], item["type"]))
for key, group in itertools.groupby(records, lambda item: (item["name"], item["type"])):
final_records.append({ final_records.append({
"name": key[0], "name": key[0],
"type": key[1], "type": key[1],
"changetype": "REPLACE", "changetype": key[2],
"records": [ "records": [
{ {
"content": item['records'][0]['content'], "content": item['records'][0]['content'],
@ -935,10 +937,7 @@ class Record(object):
headers = {} headers = {}
headers['X-API-Key'] = PDNS_API_KEY 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) 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)
# logging.debug('jdata1: ', jdata1)
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) 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)
# logging.debug('jdata2: ', jdata2)
if 'error' in jdata2.keys(): if 'error' in jdata2.keys():
logging.error('Cannot apply record changes.') logging.error('Cannot apply record changes.')