Skip to content

Instantly share code, notes, and snippets.

@allenap
Created March 1, 2016 17:34
Show Gist options
  • Save allenap/60f4def2075ba67d371a to your computer and use it in GitHub Desktop.
Save allenap/60f4def2075ba67d371a to your computer and use it in GitHub Desktop.
from contextlib import contextmanager
import time
import dns.resolver
from provisioningserver.utils.twisted import retries
def query_soa(zone):
for rdata in dns.resolver.query(zone, "SOA"):
return rdata # Return the first SOA found.
class DNSChangeTimeOut(Exception):
"""A DNS change was not seen in time."""
@contextmanager
def dns_change_monitor(zone):
serial = query_soa(zone).serial
yield
for elapsed, remaining, wait in retries(15, 0.2):
if query_soa(zone).serial == serial:
time.sleep(wait)
else:
break
else:
raise DNSChangeTimeOut(
"Changes to %s were not seen." % (zone,))
with dns_change_monitor("my.zone"):
pass # Make changes to "my.zone" in MAAS.
# Here changes to "my.zone" will have been loaded by BIND.
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment