import textwrap
import copy
import socket
+import time
from functools import cmp_to_key
for zone in sorted(self.zones, key=lambda x: cmp_to_key(compare_fqdn)(x.name_unicode)):
self.zone_names.append(zone.name)
+ idx = 0
+ print('')
+ print('')
for zone_name in self.zone_names:
+ if idx:
+ print('')
+ print('')
+ print('Sleeping a little bit ...')
+ print('')
+ time.sleep(3)
migrated = self.migrate_zone(zone_name)
+ if migrated:
+ idx += 1
if self.oneshot and migrated:
break
if not zone:
return False
- api_host_address = None
- for addr_info in socket.getaddrinfo(self.api_host, 53, family=socket.AF_INET):
- api_host_address = addr_info[4][0]
- break
-
new_nameservers = []
hm_address = self.address_hostmaster_public
LOG.debug("New SOA of zone {!r}:\n{}".format(zone_name, new_soa))
if new_soa != soa:
- self.ensure_soa(zone, new_soa)
+ LOG.info("Update SOA of zone {!r} ...".format(zone_name))
+ self.update_soa(zone, new_soa, "Update SOA on great NS- and SOA-Migration.")
else:
LOG.debug("Update SOA of zone is not necessary.".format(zone_name))
- dns_soa = zone.get_soa_by_dns(api_host_address)
- LOG.debug("Got SOA from DNS by {h!r}:\n{s}".format(h=self.api_host, s=dns_soa))
-
- if not self.ensure_nameservers(zone, new_nameservers):
+ LOG.info("Setting nameservers for zone {!r} ...".format(zone_name))
+ comment = "Update NS entries on great NS- and SOA-Migration."
+ if not self.set_nameservers(zone, new_nameservers, comment=comment):
return False
- new_serial = zone.get_new_serial(dns_soa.serial)
- LOG.debug("Got new serial number for zone {z!r}: {s}.".format(
- z=zone_name, s=new_serial))
-
zone_parts = zone_name.split('.')
top_zone_name = '.'.join(zone_parts[1:])
LOG.debug("Top zone of {z!r} is {t!r}.".format(z=zone_name, t=top_zone_name))
LOG.info("Setting nameservers for zone {z!r} in zone {t!r}.".format(
z=zone_name, t=top_zone_name))
top_zone = self.get_api_zone(top_zone_name)
- return self.ensure_nameservers(top_zone, new_nameservers, zone_name)
+ return self.set_nameservers(top_zone, new_nameservers, zone_name, comment=comment)
else:
LOG.debug("Top zone {!r} is not in our responsibility.".format(top_zone_name))
return True
- # -------------------------------------------------------------------------
- def ensure_soa(self, zone, new_soa):
-
- LOG.info("Updating SOA of zone {z!r} with {s!r} ...".format(
- z=zone.name, s=new_soa.data))
-
- self.update_soa(zone, new_soa, "Update on great NS- and SOA-Migration.")
-
- # -------------------------------------------------------------------------
- def ensure_nameservers(self, zone, new_nameservers, for_zone=None):
-
- current_nameservers = zone.get_zone_nameservers(for_zone=for_zone)
- LOG.debug("Current nameservers of zone {z!r}:\n{ns}".format(
- z=zone.name, ns=pp(current_nameservers)))
-
- ns2remove = []
- ns2add = []
-
- for ns in current_nameservers:
- if ns not in new_nameservers:
- ns2remove.append(ns)
- for ns in new_nameservers:
- if ns not in current_nameservers:
- ns2add.append(ns)
-
- if not ns2remove and not ns2add:
- LOG.info("Zone {!r} has already the expected zones.".format(zone.name))
- return False
-
- LOG.debug("Nameservers to remove from zone {z!r}:\n{ns}".format(
- z=zone.name, ns=pp(ns2remove)))
- LOG.debug("Nameservers to add to zone {z!r}:\n{ns}".format(
- z=zone.name, ns=pp(ns2add)))
-
- return True
-
# =============================================================================