ascension

Migrate DNS zones to the GNU Name System
Log | Files | Refs | README | LICENSE

commit ef5106902865aecc21998731b8237ab168e9e1ce
parent ecd247943b01aa4da58643e2d3c8c04bb8638740
Author: rexxnor <rexxnor+gnunet@brief.li>
Date:   Sun, 14 Oct 2018 00:13:18 +0200

fixed non existing file

Diffstat:
Mgnsmigrator/gnsmigrator.py | 38++++++++++++++------------------------
1 file changed, 14 insertions(+), 24 deletions(-)

diff --git a/gnsmigrator/gnsmigrator.py b/gnsmigrator/gnsmigrator.py @@ -394,27 +394,12 @@ class BaseMigrator(): return domain.split('.')[0] @staticmethod - def get_current_serial(zonename): + def get_current_serial(domain): """ - Extracts the current serial from a given zone + Gets the current serial for a given zone """ - if zonename[-1] == '.': - zonename = zonename[:-1] - try: - serial = sp.check_output([GNUNET_GNS_COMMAND, - '-t', 'SOA', - '-u', '@.%s' % zonename]) - except sp.CalledProcessError: - soa_serial = 0 - return soa_serial - serial = serial.decode() - soapattern = re.compile(r'.+\s(\d+),\d+,+\d+,\d+,\d+', re.M) - if re.findall(soapattern, serial): - soa_serial = re.findall(soapattern, serial)[0] - else: - soa_serial = 0 - return soa_serial - + soa_answer = dns.resolver.query(domain, 'SOA') + return soa_answer[0].serial class ZoneMigrator(BaseMigrator): """ @@ -437,7 +422,7 @@ class TLDMigrator(BaseMigrator): cls.zonegenerator = {} @classmethod - def initial_zone_transfer(cls, serial): + def initial_zone_transfer(cls, serial=None): """ Transfer and initialize the zone """ @@ -479,24 +464,29 @@ class TLDMigrator(BaseMigrator): print(filenotfound) currentserial = cls.get_current_serial(cls.tld) - zoneserial = None + zoneserial = 0 if zone: for record in zone.iterate_rdatas(rdtype=dns.rdatatype.SOA): zoneserial = str(record[2]).split(' ')[2].split(',')[0] break else: - if currentserial != zoneserial: + if zoneserial == 0: + cls.initial_zone_transfer() + if zoneserial < currentserial: cls.transfer_zone() + # zip and pickle the zone with gzip.open('%s.zone.gz' % cls.tld[:-1], 'wb') as zonefile: pickle.dump(zone, zonefile) @classmethod def transfer_zone(cls, zone_factory=dns.zone.Zone, - relativize=True, check_origin=True): + relativize=True, check_origin=True + ): """ Do the actual zone transfer """ + zone = None try: for message in cls.zonegenerator: origin = message.origin @@ -542,7 +532,7 @@ class TLDMigrator(BaseMigrator): if record is None: break # execute thing to run on item - dnsname, ttl, authns = record + _, _, authns = record if str(authns)[:-1] == ".": authns = str(authns)[:-1] else: