]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Splitting method get_zone_nameservers() of class PdnsApiZone into get_ns_rrset()...
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 16 Jan 2018 17:27:41 +0000 (18:27 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 16 Jan 2018 17:27:41 +0000 (18:27 +0100)
pp_lib/pdns_zone.py

index 59d15cac172d71c795cdaeee9204f20ffe73c220..b10afbc3dbbccbe0be200fc3268857682d705bcd 100644 (file)
@@ -27,7 +27,7 @@ from .errors import PpError
 from .obj import PpBaseObjectError, PpBaseObject
 from .pdns_record import PdnsApiRrset, PdnsSoaData
 
-__version__ = '0.5.1'
+__version__ = '0.5.2'
 
 LOG = logging.getLogger(__name__)
 
@@ -476,9 +476,7 @@ class PdnsApiZone(PpBaseObject):
         return new_serial
 
     # -------------------------------------------------------------------------
-    def get_zone_nameservers(self, for_zone=None):
-
-        nameservers = []
+    def get_ns_rrset(self, for_zone=None):
 
         for rrset in self.rrsets:
             if rrset.type == 'NS':
@@ -488,13 +486,41 @@ class PdnsApiZone(PpBaseObject):
                 else:
                     if self.name.lower() != rrset.name.lower():
                         continue
-                for record in rrset.records:
-                    ns = RE_DOT_AT_END.sub('.', record.content).lower()
-                    nameservers.append(ns)
+                return rrset
+        return None
+
+    # -------------------------------------------------------------------------
+    def get_ns_records(self, for_zone=None):
+
+        rrset = self.get_ns_rrset(for_zone=for_zone)
+        if self.verbose > 2:
+            LOG.debug("Got NS RRset:\n{}".format(rrset))
+        if not rrset:
+            return None
+        if not rrset.records:
+            return None
+
+        ns_records = []
+        for record in rrset.records:
+            ns_records.append(record)
+        return ns_records
+
+    # -------------------------------------------------------------------------
+    def get_zone_nameservers(self, for_zone=None):
+
+        nameservers = []
 
+        ns_records = self.get_ns_records(for_zone=for_zone)
+        if not ns_records:
+            return nameservers
+
+        for record in ns_records:
+            ns = RE_DOT_AT_END.sub('.', record.content).lower()
+            nameservers.append(ns)
         nameservers.sort()
         return nameservers
 
+
 # =============================================================================
 
 if __name__ == "__main__":