]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Ensuring correct SOA in class PDNSMigrateNsApp
authorFrank Brehm <frank.brehm@pixelpark.com>
Mon, 15 Jan 2018 15:38:58 +0000 (16:38 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Mon, 15 Jan 2018 15:38:58 +0000 (16:38 +0100)
pp_lib/pdns_migrate_ns.py

index ce40504fe2be5e84323020b44b290f5c228ba77d..ce55fab3a76448e06d4b177ac5162f62b084a06e 100644 (file)
@@ -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):