from .pdns_app import PpPDNSAppError, PpPDNSApplication
from .pdns_zone import PdnsApiZone
-__version__ = '0.3.2'
+__version__ = '0.4.1'
LOG = logging.getLogger(__name__)
# -------------------------------------------------------------------------
def __init__(self, appname=None, version=__version__):
+ self.show_numbers = False
+
description = textwrap.dedent('''\
Lists all available zones from given PowerDNS API.
''')
self.initialized = True
+ # -------------------------------------------------------------------------
+ def init_arg_parser(self):
+ """
+ Method to initiate the argument parser.
+
+ This method should be explicitely called by all init_arg_parser()
+ methods in descendant classes.
+ """
+
+ super(PpPDNSListZonesApp, self).init_arg_parser()
+
+ self.arg_parser.add_argument(
+ '-N', '--numbers', action='store_true', dest='show_numbers',
+ help="Show number of Ressource Record Sets and Records for each zone",
+ )
+
+ # -------------------------------------------------------------------------
+ def perform_arg_parser(self):
+ """
+ Public available method to execute some actions after parsing
+ the command line parameters.
+ """
+
+ super(PpPDNSListZonesApp, self).perform_arg_parser()
+
+ if self.args.show_numbers:
+ self.show_numbers = True
+
# -------------------------------------------------------------------------
def _run(self):
if len(zone.name_unicode) > len_zone:
len_zone = len(zone.name_unicode)
- tpl = PdnsApiZone.get_list_template()
+ if self.show_numbers:
+ tpl = PdnsApiZone.get_list_template(show_numbers=True)
+ else:
+ tpl = PdnsApiZone.get_list_template(show_numbers=False)
line = tpl.format(
name="Zone", len_zone=len_zone, kind="Type", serial="Serial",
- dnssec="DNSSEC", account="Account information")
+ dnssec="DNSSEC", nr_rrsets='RR Sets', nr_records='Records',
+ account="Account information")
print(line)
print('-' * len(line))
+ nr_zones = 0
+ nr_rrsets = 0
+ nr_records = 0
for zone in sorted(zone_list, key=lambda x: cmp_to_key(compare_fqdn)(x.name_unicode)):
- print(zone.get_line(len_zone))
+ if self.show_numbers:
+ nr_zones += 1
+ zone_complete = self.get_api_zone(zone.name)
+ for rrset in zone_complete.rrsets:
+ nr_rrsets += 1
+ for record in rrset.records:
+ nr_records += 1
+ print(zone.get_line(len_zone, zone_complete.rrsets))
+ else:
+ print(zone.get_line(len_zone))
+
+ print('-' * len(line))
+ line = tpl.format(
+ name="Total:", len_zone=len_zone, kind="", serial=nr_zones,
+ dnssec="Zones", nr_rrsets=nr_rrsets, nr_records=nr_records, account="")
+ print(line)
# =============================================================================
from .obj import PpBaseObjectError, PpBaseObject
from .pdns_record import PdnsApiRrset, PdnsSoaData
-__version__ = '0.5.4'
+__version__ = '0.5.5'
LOG = logging.getLogger(__name__)
# -------------------------------------------------------------------------
@classmethod
- def get_list_template(cls):
+ def get_list_template(cls, show_numbers=False):
- return "{name:<{len_zone}} {kind:<8} {serial:>10} {dnssec:<6} {account}"
+ tpl = "{name:<{len_zone}} {kind:<8} {serial:>10} {dnssec:<6}"
+ if show_numbers:
+ tpl += ' {nr_rrsets:>8} {nr_records:>8} '
+ tpl += ' {account}'
+ return tpl
# -------------------------------------------------------------------------
- def get_line(self, len_zone=20):
+ def get_line(self, len_zone=20, rrsets=None):
- tpl = self.get_list_template()
+ if rrsets:
+ tpl = self.get_list_template(True)
+ else:
+ tpl = self.get_list_template(False)
params = {
'name': self.name_unicode,
'serial': self.serial,
'dnssec': 'no',
'account': '',
+ 'nr_rrsets': '',
+ 'nr_records': '',
}
if self.dnssec:
params['dnssec'] = 'yes'
if self.account:
params['account'] = self.account
+ if rrsets:
+ params['nr_rrsets'] = 0
+ params['nr_records'] = 0
+ for rrset in rrsets:
+ params['nr_rrsets'] += 1
+ for record in rrset.records:
+ params['nr_records'] += 1
+
return tpl.format(**params)
# -------------------------------------------------------------------------