import os
import logging
import copy
+import datetime
# Third party modules
+import dns.resolver
+from dns.resolver import Resolver, NoAnswer
# Own modules
from .common import pp, to_bytes, to_utf8, to_bool
from .obj import PpBaseObjectError, PpBaseObject
from .pdns_record import PdnsApiRrset, PdnsSoaData
-__version__ = '0.4.5'
+__version__ = '0.5.1'
LOG = logging.getLogger(__name__)
return soa
+ # -------------------------------------------------------------------------
+ def get_soa_by_dns(self, *nameservers):
+
+ soa = None
+
+ resolver = Resolver()
+
+ if nameservers:
+ resolver.nameservers = []
+ for ns in nameservers:
+ LOG.debug("Adding nameserver to use: {!r}.".format(ns))
+ resolver.nameservers.append(ns)
+
+ try:
+ answers = resolver.query(self.name, 'SOA', raise_on_no_answer=False)
+ except NoAnswer as e:
+ LOG.error("Got no answer from nameservers: {}".format(e))
+ return None
+
+ for rdata in answers:
+ soa = PdnsSoaData(
+ primary=rdata.mname, email=rdata.rname, serial=rdata.serial, refresh=rdata.refresh,
+ retry=rdata.retry, expire=rdata.expire, ttl=rdata.minimum,
+ appname=self.appname, verbose=self.verbose, base_dir=self.base_dir)
+ return soa
+
+ return None
+
+ # -------------------------------------------------------------------------
+ def get_new_serial(self, *compare_serials):
+
+ i = 0
+ today = datetime.date.today()
+ new_serial = today.year * 1000000 + today.month * 10000 + today.day * 100 + i
+ one_day = datetime.timedelta(1)
+
+ compare = []
+ compare.append(self.serial)
+ compare.append(self.notified_serial)
+ if compare_serials:
+ for serial in compare_serials:
+ compare.append(serial)
+ if self.verbose > 3:
+ LOG.debug("Compare serials: {}".format(pp(compare)))
+
+ found = False
+ while not found:
+ if self.verbose > 3:
+ LOG.debug("Trying new serial {} ...".format(new_serial))
+ found = True
+ for serial in compare:
+ if serial >= new_serial:
+ found = False
+ break
+ if found:
+ return new_serial
+ i += 1
+ if i > 99:
+ today += one_day
+ i = 0
+ new_serial = today.year * 1000000 + today.month * 10000 + today.day * 100 + i
+
+ return new_serial
+
# -------------------------------------------------------------------------
def get_zone_nameservers(self, for_zone=None):