modified: .gitignore
Ingore build/ dir modified: src/netbox_plugin_bind_provisioner/__init__.py Set version v0.9.9 modified: src/netbox_plugin_bind_provisioner/management/commands/bind-transfer-endpoint.py Fix bug where an exception occurse if a view has no zones. Feature added - Fixes #5
This commit is contained in:
1 parent
787c3d0a20
commit
a9c59f4c57
3 files changed
+12
-23
No files matched your search
@@ -1,3 +1,4 @@
|
|||||||
src/netbox_plugin_bind_provisioner.egg-info
|
src/netbox_plugin_bind_provisioner.egg-info
|
||||||
dist/
|
dist/
|
||||||
|
build/
|
||||||
__pycache__
|
__pycache__
|
||||||
@@ -5,7 +5,7 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
__version__ = "0.9.8"
|
__version__ = "0.9.9"
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class CatalogZone():
|
|||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, view_name, soa_only=False):
|
def create(cls, name, view_name):
|
||||||
# Synchronize following across threads as TCP and UDP listener both use it.
|
# Synchronize following across threads as TCP and UDP listener both use it.
|
||||||
with cls.lock:
|
with cls.lock:
|
||||||
#cls = self.__class__
|
#cls = self.__class__
|
||||||
@@ -77,12 +77,9 @@ class CatalogZone():
|
|||||||
# Setting previous last zone update for next iteration:
|
# Setting previous last zone update for next iteration:
|
||||||
cls._previous_last_zone_update = last_zone_update
|
cls._previous_last_zone_update = last_zone_update
|
||||||
cls._incrementSerial()
|
cls._incrementSerial()
|
||||||
# If there was no update, do nothing.
|
|
||||||
#else:
|
|
||||||
# logger.debug(f"No need to update serial for catalog zone")
|
|
||||||
|
|
||||||
# Zone origin
|
# Zone origin
|
||||||
origin = dns.name.from_text("catz", dns.name.root)
|
origin = dns.name.from_text(name, dns.name.root)
|
||||||
|
|
||||||
# Create a new empty zone
|
# Create a new empty zone
|
||||||
zone = dns.zone.Zone(origin)
|
zone = dns.zone.Zone(origin)
|
||||||
@@ -198,11 +195,11 @@ class CatalogZone():
|
|||||||
|
|
||||||
class DNSBaseRequestHandler(socketserver.BaseRequestHandler):
|
class DNSBaseRequestHandler(socketserver.BaseRequestHandler):
|
||||||
# getZoneFromNB rewritten
|
# getZoneFromNB rewritten
|
||||||
def getZoneFromNB(self, zone_name, view_name, soa_only=False):
|
def getZoneFromNB(self, zone_name, view_name):
|
||||||
# Find the zone
|
# Find the zone
|
||||||
try:
|
try:
|
||||||
nb_zone = Zone.objects.get(
|
nb_zone = Zone.objects.get(
|
||||||
name=zone_name, view=view_name, status=ZoneStatusChoices.STATUS_ACTIVE
|
name=zone_name, view__name=view_name, status=ZoneStatusChoices.STATUS_ACTIVE
|
||||||
)
|
)
|
||||||
except Zone.DoesNotExist:
|
except Zone.DoesNotExist:
|
||||||
return None
|
return None
|
||||||
@@ -263,14 +260,6 @@ class DNSBaseRequestHandler(socketserver.BaseRequestHandler):
|
|||||||
return zone
|
return zone
|
||||||
|
|
||||||
|
|
||||||
# def denyRequest(self, query, rcode: dns.rcode = dns.rcode.REFUSED):
|
|
||||||
# response = dns.message.make_response(query)
|
|
||||||
# response.set_rcode(rcode)
|
|
||||||
# wire = response.to_wire(multi=False)
|
|
||||||
# length = len(wire).to_bytes(2, byteorder="big")
|
|
||||||
# self.request.sendall(length + wire)
|
|
||||||
|
|
||||||
|
|
||||||
def denyRequestBadTSIG(self, wire, tsig_error: dns.rcode):
|
def denyRequestBadTSIG(self, wire, tsig_error: dns.rcode):
|
||||||
# Use empty keyring to parse TSIG without validating
|
# Use empty keyring to parse TSIG without validating
|
||||||
query = dns.message.from_wire(wire, keyring={}, ignore_trailing=True, continue_on_error=True)
|
query = dns.message.from_wire(wire, keyring={}, ignore_trailing=True, continue_on_error=True)
|
||||||
@@ -348,11 +337,11 @@ class UDPRequestHandler(DNSBaseRequestHandler):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Check if catalog zone
|
# Check if catalog zone
|
||||||
if dname == "catz":
|
if dname == "catz" or dname == f"{nb_view.name}.catz":
|
||||||
zone = CatalogZone.create(nb_view.name, soa_only=True)
|
zone = CatalogZone.create(dname, nb_view.name)
|
||||||
# If generic zone, retreive from NB
|
# If generic zone, retreive from NB
|
||||||
else:
|
else:
|
||||||
zone = self.getZoneFromNB(dname, nb_view, soa_only=True)
|
zone = self.getZoneFromNB(dname, nb_view.name)
|
||||||
# When zone was not found, let client know
|
# When zone was not found, let client know
|
||||||
if not zone:
|
if not zone:
|
||||||
logger.warning(f"Zone {nb_view.name}/{dname} not found in NB")
|
logger.warning(f"Zone {nb_view.name}/{dname} not found in NB")
|
||||||
@@ -366,7 +355,6 @@ class UDPRequestHandler(DNSBaseRequestHandler):
|
|||||||
soa_rdata = soa_rdataset[0] # Get the first SOA record
|
soa_rdata = soa_rdataset[0] # Get the first SOA record
|
||||||
|
|
||||||
# Now, create the rrset from the soa_rdata
|
# Now, create the rrset from the soa_rdata
|
||||||
#rrset = dns.rrset.from_rdata(dname, soa_rdataset.ttl, soa_rdata)
|
|
||||||
rrset = dns.rrset.from_rdata(zone.origin, soa_rdataset.ttl, soa_rdata)
|
rrset = dns.rrset.from_rdata(zone.origin, soa_rdataset.ttl, soa_rdata)
|
||||||
|
|
||||||
# Append the rrset to the response's answer section
|
# Append the rrset to the response's answer section
|
||||||
@@ -471,10 +459,10 @@ class TCPRequestHandler(DNSBaseRequestHandler):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Check if catalog zone
|
# Check if catalog zone
|
||||||
if dname == "catz":
|
if dname == "catz" or dname == f"{nb_view.name}.catz":
|
||||||
zone = CatalogZone.create(nb_view.name)
|
zone = CatalogZone.create(dname, nb_view.name)
|
||||||
else:
|
else:
|
||||||
zone = self.getZoneFromNB(dname, nb_view)
|
zone = self.getZoneFromNB(dname, nb_view.name)
|
||||||
|
|
||||||
# When zone was not found, let client know
|
# When zone was not found, let client know
|
||||||
if not zone:
|
if not zone:
|
||||||
|
|||||||
Reference in new issue
Block a user