From 5a254375fb6307e0c473f1bd0e03268f859acf60 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Wed, 7 Aug 2024 20:59:34 +0200 Subject: [PATCH] Add zone.root as a more readable alias for zone[""] --- example/__init__.py | 4 ++-- example/example_org.py | 2 +- nsconfig/__init__.py | 2 -- nsconfig/core.py | 3 ++- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/example/__init__.py b/example/__init__.py index 8c6fd28..b2b9601 100644 --- a/example/__init__.py +++ b/example/__init__.py @@ -13,7 +13,7 @@ nsconfig.sink.generate_blackhole(nsc) for rev in ['10.1.0.0/16', '10.2.0.0/16', 'fd12:3456:789a::/48']: rz = nsc.add_zone(reverse_for=rev) - rz[""].NS('ns1.example.org', 'ns2.example.org') + rz.root.NS('ns1.example.org', 'ns2.example.org') nsc.add_zone('example.net', follow_primary='10.42.0.1') @@ -21,6 +21,6 @@ rz = nsc.add_zone(reverse_for='10.3.0.0/16') rz.delegate_classless('10.3.16.0/20').NS('ns1.example.org') rz = nsc.add_zone(reverse_for='10.3.16.0/20') -rz[""].NS('ns1.example.org') +rz.root.NS('ns1.example.org') import example.example_org diff --git a/example/example_org.py b/example/example_org.py index 493aae8..905f935 100644 --- a/example/example_org.py +++ b/example/example_org.py @@ -8,7 +8,7 @@ z = nsc.add_zone( default_ttl=timedelta(hours=8), ) -(z[""] +(z.root .NS('ns1', 'ns2') .ttl(60) .MX(0, 'mail') diff --git a/nsconfig/__init__.py b/nsconfig/__init__.py index 8c6154c..f9a0541 100644 --- a/nsconfig/__init__.py +++ b/nsconfig/__init__.py @@ -2,5 +2,3 @@ # (c) 2024 Martin Mareš from nsconfig.core import Nsc, NscZone, NscZoneConfig, NscNode - -pass diff --git a/nsconfig/core.py b/nsconfig/core.py index 7df3234..7dab75a 100644 --- a/nsconfig/core.py +++ b/nsconfig/core.py @@ -265,6 +265,7 @@ class NscZonePrimary(NscZone): self.aliases = [] self.zone = dns.zone.Zone(origin=self.name, rdclass=RdataClass.IN) + self.root = NscNode(self, "") self.update_soa() def update_soa(self) -> None: @@ -280,7 +281,7 @@ class NscZonePrimary(NscZone): minimum=conf.min_ttl, ) self.zone.delete_rdataset("", RdataType.SOA) - self[""]._add(soa) + self.root._add(soa) def n(self, name: str) -> NscNode: return NscNode(self, name) -- 2.39.2