- def generate_rrs(self) -> Iterator[RR]:
- serial = -1
- yield (RR(abs_hostname(self._name), self._other_TTL, 'SOA',
- '{NS} {mail} ({serial} {refresh} {retry} {expire} {NX_TTL})'.format(
- NS=self._NS[0], mail=self._mail, serial=serial,
- refresh=time(self._refresh), retry=time(self._retry), expire=time(self._expire),
- NX_TTL=time(self._NX_TTL))
- ))
+ def inc_serial(self) -> int:
+ # get serial
+ cur_serial = 0
+ try:
+ with open(self._serialfile) as f:
+ cur_serial = int(f.read())
+ except FileNotFoundError:
+ pass
+ # increment serial
+ cur_serial += 1
+ # save serial
+ with open(self._serialfile, 'w') as f:
+ f.write(str(cur_serial))
+ # be done
+ return cur_serial
+
+ def generate_rrs(self) -> Iterator:
+ # SOA record
+ serial = self.inc_serial()
+ yield self.RR(self._name, 'SOA',
+ ('{NS} {mail} ({serial} {refresh} {retry} {expire} {NX_TTL}) ; '+
+ '(serial refresh retry expire NX_TTL)').format(
+ NS=self.abs_hostname(self._NS[0]), mail=self._mail, serial=serial,
+ refresh=time(self._refresh), retry=time(self._retry), expire=time(self._expire),
+ NX_TTL=time(self._NX_TTL))
+ )
+ # NS records
+ for ns in self._NS:
+ yield self.RR(self._name, 'NS', self.abs_hostname(ns))
+
+ # all the rest
+ for name in sorted(self._domains.keys(), key=lambda s: list(reversed(s.split('.')))):
+ print(name)
+ #for rr in self._domains[name].generate_rrs(self):
+ #yield rr