Tweaking the diff and equality logic
This commit is contained in:
parent
88f35e4798
commit
c178f4f718
2 changed files with 26 additions and 21 deletions
|
@ -54,10 +54,13 @@ def records_equate(lr, rr):
|
||||||
|
|
||||||
if not same_record(lr, rr):
|
if not same_record(lr, rr):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
elif lr["rrset_ttl"] != rr["rrset_ttl"]:
|
elif lr["rrset_ttl"] != rr["rrset_ttl"]:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
elif set(lr["rrset_values"]) != set(rr["rrset_values"]):
|
elif set(lr["rrset_values"]) != set(rr["rrset_values"]):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -100,28 +103,18 @@ def diff_zones(left_zone, right_zone):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
in_left_not_right = []
|
in_left_not_right = []
|
||||||
|
in_right_not_left = []
|
||||||
for lr in left_zone:
|
for lr in left_zone:
|
||||||
flag = False
|
flag = False
|
||||||
for rr in right_zone:
|
for rr in right_zone:
|
||||||
if same_record(lr, rr) and records_equate(lr, rr):
|
if records_equate(lr, rr):
|
||||||
flag = True
|
flag |= True
|
||||||
break
|
|
||||||
|
|
||||||
if not flag:
|
if not flag:
|
||||||
in_left_not_right.append(lr)
|
in_left_not_right.append(lr)
|
||||||
|
in_right_not_left.append(rr)
|
||||||
|
|
||||||
in_right_not_left = []
|
return in_left_not_right, in_right_not_left
|
||||||
for rr in right_zone:
|
|
||||||
flag = False
|
|
||||||
for lr in left_zone:
|
|
||||||
if same_record(lr, rr) and records_equate(lr, rr):
|
|
||||||
flag = True
|
|
||||||
break
|
|
||||||
|
|
||||||
if not flag:
|
|
||||||
in_right_not_left.append(lr)
|
|
||||||
|
|
||||||
return in_left_not_right or in_right_not_left
|
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
|
@ -157,6 +150,8 @@ def main():
|
||||||
**config["bindings"],
|
**config["bindings"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print(f"Using config {template_bindings!r}...")
|
||||||
|
|
||||||
api = GandiAPI(config["gandi"]["key"])
|
api = GandiAPI(config["gandi"]["key"])
|
||||||
|
|
||||||
for task in config["tasks"]:
|
for task in config["tasks"]:
|
||||||
|
@ -167,13 +162,26 @@ def main():
|
||||||
os.path.join(args.template_dir, task["template"]), template_bindings
|
os.path.join(args.template_dir, task["template"]), template_bindings
|
||||||
)
|
)
|
||||||
|
|
||||||
|
print(f"Running task {task!r}...")
|
||||||
|
|
||||||
for zone_name in task["zones"] or []:
|
for zone_name in task["zones"] or []:
|
||||||
try:
|
try:
|
||||||
live_zone = api.domain_records(zone_name)
|
live_zone = api.domain_records(zone_name)
|
||||||
|
|
||||||
if diff_zones(computed_zone, live_zone):
|
lr, rl = diff_zones(computed_zone, live_zone)
|
||||||
print("Zone {} differs, computed zone:".format(zone_name))
|
if lr or rl:
|
||||||
|
print(f"Zone {zone_name} differs;")
|
||||||
|
print("Computed:")
|
||||||
pprint(computed_zone)
|
pprint(computed_zone)
|
||||||
|
pprint("Live:")
|
||||||
|
pprint(live_zone)
|
||||||
|
if(rl):
|
||||||
|
print("Live records not recomputed")
|
||||||
|
pprint(rl)
|
||||||
|
if(lr):
|
||||||
|
print("New records not live")
|
||||||
|
pprint(lr)
|
||||||
|
|
||||||
if not args.dry:
|
if not args.dry:
|
||||||
print(api.replace_domain(zone_name, computed_zone))
|
print(api.replace_domain(zone_name, computed_zone))
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -7,7 +7,7 @@ fm1._domainkey {{ ttl }} IN CNAME fm1.tirefireind.us.dkim.fmhosted.com.
|
||||||
fm2._domainkey {{ ttl }} IN CNAME fm2.tirefireind.us.dkim.fmhosted.com.
|
fm2._domainkey {{ ttl }} IN CNAME fm2.tirefireind.us.dkim.fmhosted.com.
|
||||||
fm3._domainkey {{ ttl }} IN CNAME fm3.tirefireind.us.dkim.fmhosted.com.
|
fm3._domainkey {{ ttl }} IN CNAME fm3.tirefireind.us.dkim.fmhosted.com.
|
||||||
|
|
||||||
@ {{ ttl }} IN TXT v=spf1 include:spf.messagingengine.com ?all
|
@ {{ ttl }} IN TXT "v=spf1 include:spf.messagingengine.com ?all"
|
||||||
|
|
||||||
# Core records
|
# Core records
|
||||||
{% for link in local.public_v4s %}
|
{% for link in local.public_v4s %}
|
||||||
|
@ -20,9 +20,6 @@ feed {{ ttl }} IN A {{ link }}
|
||||||
ton {{ ttl }} IN A {{ link }}
|
ton {{ ttl }} IN A {{ link }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
# Gitlab
|
|
||||||
gitlab {{ ttl }} IN A {{ sroo.public_v4 }}
|
|
||||||
|
|
||||||
# Host records
|
# Host records
|
||||||
## The hand-rolled hosts
|
## The hand-rolled hosts
|
||||||
feed.h.dia0.site {{ ttl }} IN A 10.0.0.5
|
feed.h.dia0.site {{ ttl }} IN A 10.0.0.5
|
||||||
|
|
Loading…
Reference in a new issue