Fix issue where records could get deleted when different TTL.

This commit is contained in:
Joachim Tingvold 2016-07-27 15:01:23 +00:00
parent 0d1aa7971b
commit 28796ed286

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"])) 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"], item["ttl"])): for key, group in itertools.groupby(records, lambda item: (item["name"], item["type"], item["changetype"])):
if NEW_SCHEMA: if NEW_SCHEMA:
new_record = { new_record = {
"name": key[0], "name": key[0],
"type": key[1], "type": key[1],
"changetype": key[2], "changetype": key[2],
"ttl": key[3], "ttl": None,
"records": [] "records": []
} }
for item in group: for item in group:
@ -905,6 +905,8 @@ 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