Fix output of dns-list-zones and dns-zone-list

This commit is contained in:
2025-09-01 16:58:14 +02:00
parent d163a82e0e
commit fd33964168
2 changed files with 17 additions and 10 deletions

View File

@@ -2,6 +2,7 @@
import argparse
import dnsmgr
import re
import sys
from json import dumps
@@ -46,6 +47,9 @@ def main():
zones.sort(key=lambda zone: zone.view)
rev_domain = dnsmgr.name_from_text('in-addr.arpa')
rev_domain6 = dnsmgr.name_from_text('ip6.arpa')
zone_records = {}
for zone in zones:
try:
@@ -61,13 +65,17 @@ def main():
continue
for value in rdataset:
records.append({
'name': name.to_text(),
'name_unicode': name.to_unicode(),
'name': name.to_unicode() if args.decode else name.to_text(),
'ttl': str(rdataset.ttl),
'type': str(rdataset.rdtype.to_text(rdataset.rdtype)),
'value': value.to_text(origin=zone.origin, relativize=False)})
records.sort(key=lambda r: f'{r["name_unicode"]}{r["type"]}')
if zone.origin.is_subdomain(rev_domain):
records.sort(key=lambda r: int(re.findall(r'\d+|$', r['name'])[0] or 0))
elif zone.origin.is_subdomain(rev_domain6):
records.sort(key=lambda r: int(''.join(re.findall(r'\d+', r['name'])) or 0))
else:
records.sort(key=lambda r: f'{r["name"]}{r["type"]}')
zone_records[zone.view] = records
views = sorted(zone_records.keys())
@@ -92,8 +100,7 @@ def main():
for view in views:
rows = []
for record in zone_records[view]:
name = record['name_unicode'] if args.decode else record['name']
row = [name, record['ttl'], record['type'], record['value']]
row = [record['name'], record['ttl'], record['type'], record['value']]
rows.append(row)
if len(views) > 1 or view != dnsmgr.NAMED_DEFAULT_VIEW: