From 717caf80dd2be4b7f14cfcbb14566b528c8b6fd9 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 8 Nov 2017 14:52:07 +0100 Subject: [PATCH] Extended PdnsApiZone class --- pp_lib/pdns_show_zone.py | 19 ++++++++++++------- pp_lib/pdns_zone.py | 21 +++++++++++++++++++-- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/pp_lib/pdns_show_zone.py b/pp_lib/pdns_show_zone.py index 35e7bd9..b8fbed5 100644 --- a/pp_lib/pdns_show_zone.py +++ b/pp_lib/pdns_show_zone.py @@ -120,19 +120,19 @@ class PpPDNSShowZoneApp(PpPDNSApplication): self.default_ttl = ttl # ------------------------------------------------------------------------- - def show_zone(self, zone): + def show_zone(self, zone_name): - zone_unicode = zone + zone_unicode = zone_name json_response = None - zout = "{!r}".format(zone) - if 'xn--' in zone: - zone_unicode = zone.encode('idna').decode('idna') - zout = "{!r} ({})".format(zone, zone_unicode) + zout = "{!r}".format(zone_name) + if 'xn--' in zone_name: + zone_unicode = zone_name.encode('idna').decode('idna') + zout = "{!r} ({})".format(zone_name, 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) + path = "/servers/{}/zones/{}".format(self.api_servername, zone_name) try: json_response = self.perform_request(path) except (PDNSApiNotFoundError, PDNSApiValidationError) as e: @@ -141,6 +141,11 @@ class PpPDNSShowZoneApp(PpPDNSApplication): if self.verbose > 2: LOG.debug("Got a response:\n{}".format(pp(json_response))) + zone = PdnsApiZone.init_from_dict( + json_response, appname=self.appname, verbose=self.verbose, base_dir=self. base_dir) + if self.verbose > 2: + LOG.debug("Zone object:\n{}".format(pp(zone.as_dict()))) + return True # ============================================================================= diff --git a/pp_lib/pdns_zone.py b/pp_lib/pdns_zone.py index 05cdc40..69a739e 100644 --- a/pp_lib/pdns_zone.py +++ b/pp_lib/pdns_zone.py @@ -22,7 +22,7 @@ from .common import pp, to_bytes, to_utf8 from .errors import PpError from .obj import PpBaseObjectError, PpBaseObject -__version__ = '0.2.1' +__version__ = '0.3.1' LOG = logging.getLogger(__name__) @@ -38,7 +38,8 @@ class PdnsApiZone(PpBaseObject): def __init__( self, appname=None, verbose=0, version=__version__, base_dir=None, initialized=None, account=None, dnssec=False, id=None, kind=None, last_check=None, - masters=None, name=None, notified_serial=None, serial=None, url=None): + masters=None, name=None, notified_serial=None, serial=None, url=None, + rrsets=None, soa_edit=None, soa_edit_api=None): # { 'account': 'local', # 'dnssec': False, @@ -64,6 +65,8 @@ class PdnsApiZone(PpBaseObject): self._url = url self.records = [] + self._soa_edit = soa_edit + self._soa_edit_api = soa_edit_api super(PdnsApiZone, self).__init__( appname=appname, verbose=verbose, version=version, base_dir=base_dir) @@ -208,6 +211,18 @@ class PdnsApiZone(PpBaseObject): """The URL in the API to get the zone object.""" return getattr(self, '_url', None) + # ----------------------------------------------------------- + @property + def soa_edit(self): + """The SOA edit property of the zone object.""" + return getattr(self, '_soa_edit', None) + + # ----------------------------------------------------------- + @property + def soa_edit_api(self): + """The SOA edit property (API) of the zone object.""" + return getattr(self, '_soa_edit_api', None) + # ------------------------------------------------------------------------- def as_dict(self, short=True): """ @@ -233,6 +248,8 @@ class PdnsApiZone(PpBaseObject): res['serial'] = self.serial res['url'] = self.url res['records'] = copy.copy(self.records) + res['soa_edit'] = self.soa_edit + res['soa_edit_api'] = self.soa_edit_api return res -- 2.39.5