from .common import pp, compare_fqdn, to_str
from .common import RE_DOT_AT_END
-from .pdns_app import PpPDNSAppError, PpPDNSApplication
+from .pdns_app import PpPDNSAppError, PpPDNSApplication, PDNSApiNotFoundError, PDNSApiValidationError
from .pdns_zone import PdnsApiZone
-__version__ = '0.2.0'
+__version__ = '0.3.1'
LOG = logging.getLogger(__name__)
)
self.initialized = True
+ self.default_ttl = 3600
# -------------------------------------------------------------------------
def init_arg_parser(self):
zone_idna = zone
if 'xn--' not in zone:
zone_idna = to_str(zone.encode('idna'))
- zone_idna = RE_DOT_AT_END.sub('.', zone_idna)
+ zone_idna = RE_DOT_AT_END.sub('.', zone_idna).lower()
self.zones.append(zone_idna)
# -------------------------------------------------------------------------
def _run(self):
- for zone in self.zones:
+ success = True
+ self.get_default_ttl()
- zone_unicode = zone
- zout = "{!r}".format(zone)
- if 'xn--' in zone:
- zone_unicode = zone.encode('idna').decode('idna')
- zout = "{!r} ({})".format(zone, zone_unicode)
+ for zone in self.zones:
+ if not self.show_zone(zone):
+ success = False
- LOG.info("Show all information about zone {} from PowerDNS environment {!r}.".format(
- zout, self.environment))
+ if not success:
+ self.exit(1)
+ # -------------------------------------------------------------------------
+ def get_default_ttl(self):
+
+ LOG.debug("Retrieving defaul TTL from server ...")
+ path = "/servers/{}/config".format(self.api_servername)
+ json_response = self.perform_request(path)
+ ttl = None
+
+ for cfg in json_response:
+ if cfg['name'] == 'default-ttl':
+ try:
+ ttl = int(cfg['value'])
+ except ValueError as e:
+ LOG.error("Found invalid TTL {!r} from server: {}".format(
+ cfg['value'], e))
+ break
+ if ttl:
+ LOG.debug("Got a default TTL {} from server.".format(ttl))
+ self.default_ttl = ttl
+ # -------------------------------------------------------------------------
+ def show_zone(self, zone):
+
+ zone_unicode = zone
+ json_response = None
+ zout = "{!r}".format(zone)
+ if 'xn--' in zone:
+ zone_unicode = zone.encode('idna').decode('idna')
+ zout = "{!r} ({})".format(zone, zone_unicode)
+
+ LOG.info("Show all information about zone {} from PowerDNS environment {!r}.".format(
+ zout, self.environment))
+
+ path = "/servers/{}/zones/{}".format(self.api_servername, zone)
+ try:
+ json_response = self.perform_request(path)
+ except (PDNSApiNotFoundError, PDNSApiValidationError) as e:
+ LOG.error("The given zone {} was not found.".format(zout))
+ return False
+ if self.verbose > 2:
+ LOG.debug("Got a response:\n{}".format(pp(json_response)))
+
+ return True
# =============================================================================