From d859c1e920c0a234333e5215cb2384fa6c507940 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Mon, 15 Jan 2018 16:38:58 +0100 Subject: [PATCH] Ensuring correct SOA in class PDNSMigrateNsApp --- pp_lib/pdns_migrate_ns.py | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/pp_lib/pdns_migrate_ns.py b/pp_lib/pdns_migrate_ns.py index ce40504..ce55fab 100644 --- a/pp_lib/pdns_migrate_ns.py +++ b/pp_lib/pdns_migrate_ns.py @@ -13,6 +13,7 @@ import os import logging import logging.config import textwrap +import copy from functools import cmp_to_key @@ -24,7 +25,7 @@ from .pdns_app import PpPDNSAppError, PpPDNSApplication, PDNSApiNotFoundError, P from .pdns_zone import PdnsApiZone from .pdns_record import compare_rrsets -__version__ = '0.2.3' +__version__ = '0.2.4' LOG = logging.getLogger(__name__) @@ -47,11 +48,14 @@ class PDNSMigrateNsApp(PpPDNSApplication): ] new_local_nameservers = [ - 'ns1-local.pixelpark.com', - 'ns2-local.pixelpark.com', - 'ns3-local.pixelpark.com', + 'ns1-local.pixelpark.com.', + 'ns2-local.pixelpark.com.', + 'ns3-local.pixelpark.com.', ] + address_hostmaster_local = 'hostmaster.pixelpark.com.' + address_hostmaster_public = 'hostmaster.pixelpark.net.' + # ------------------------------------------------------------------------- def __init__(self, appname=None, version=__version__): @@ -138,10 +142,14 @@ class PDNSMigrateNsApp(PpPDNSApplication): return False new_nameservers = [] + hm_address = self.address_hostmaster_public + + is_local = self.is_local(zone_name) - if self.is_local(zone_name): + if is_local: LOG.debug("Using local nameservers for substituting.") new_nameservers = sorted(self.new_local_nameservers) + hm_address = self.address_hostmaster_local else: LOG.debug("Using public nameservers for substituting.") new_nameservers = sorted(self.new_public_nameservers) @@ -153,7 +161,18 @@ class PDNSMigrateNsApp(PpPDNSApplication): LOG.error("Could not find SOA for zone {!r}.".format(zone_name)) return False if self.verbose > 2: - LOG.debug("SOA of zone {!r}:\n{}".format(zone_name, soa)) + LOG.debug("Current SOA of zone {!r}:\n{}".format(zone_name, soa)) + + new_soa = copy.copy(soa) + new_soa.primary = new_nameservers[0] + new_soa.email = hm_address + if self.verbose > 2: + LOG.debug("New SOA of zone {!r}:\n{}".format(zone_name, new_soa)) + + if new_soa != soa: + self.ensure_soa(zone, new_soa) + else: + LOG.debug("Update SOA of zone is not necessary.".format(zone_name)) if not self.ensure_nameservers(zone, new_nameservers): return False @@ -177,6 +196,14 @@ class PDNSMigrateNsApp(PpPDNSApplication): 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): -- 2.39.5