modified: netbox_dns_bridge/notify_handler.py

modified:   netbox_dns_bridge/signals/netbox_dns_zones.py
Some code cleanup
This commit is contained in:
Sven Luthi committed 2026-07-20 15:21:14 +02:00
1 parent 11ea9a6f1a
commit b4ab5596d6
2 files changed
+12 -16

No files matched your search

+10 -14
View File
@@ -42,7 +42,7 @@ def _load_tsig_key(view_name: str) -> dns.tsig.Key:
return dns.tsig.Key(name=key_name, secret=secret, algorithm=algorithm) return dns.tsig.Key(name=key_name, secret=secret, algorithm=algorithm)
class SendDNSNotify(JobRunner): class SendClientDNSNotify(JobRunner):
class Meta: class Meta:
name = "Send DNS NOTIFY" name = "Send DNS NOTIFY"
@@ -100,7 +100,7 @@ class SendDNSNotify(JobRunner):
) )
except Exception as e: except Exception as e:
LOGGER.error( LOGGER.error(
f"NOTIFY failed: {client.source_ip}" f"NOTIFY failed: {client.source_ip}:{port}"
f" {view_name}/{zone_name} {soa_serial}: {e}" f" {view_name}/{zone_name} {soa_serial}: {e}"
) )
@@ -112,10 +112,10 @@ class SendDNSNotify(JobRunner):
close_old_connections() close_old_connections()
class SendZoneNSNotify(JobRunner): class SendNSNotify(JobRunner):
"""Send a NOTIFY straight to a zone's own nameservers. """Send a NOTIFY straight to a zone's own nameservers.
Unlike ``SendDNSNotify`` (which notifies clients that previously queried the Unlike ``SendClientDNSNotify`` (which notifies clients that previously queried the
transfer endpoint), this job resolves the addresses of the zone's configured transfer endpoint), this job resolves the addresses of the zone's configured
nameservers from NetBox DNS itself and notifies each of them so they pick up nameservers from NetBox DNS itself and notifies each of them so they pick up
the changed zone quickly. the changed zone quickly.
@@ -152,9 +152,7 @@ class SendZoneNSNotify(JobRunner):
try: try:
tsig_key = _load_tsig_key(view_name) tsig_key = _load_tsig_key(view_name)
except RuntimeError as e: except RuntimeError as e:
LOGGER.error( LOGGER.error(f"NS NOTIFY aborted for {view_name}/{zone_name}: {e}")
f"NS NOTIFY aborted for {view_name}/{zone_name}: {e}"
)
return return
fqdn = dns.name.from_text(zone_name, dns.name.root).to_text() fqdn = dns.name.from_text(zone_name, dns.name.root).to_text()
@@ -179,9 +177,7 @@ class SendZoneNSNotify(JobRunner):
LOGGER.debug("Sending NS NOTIFY over UDP") LOGGER.debug("Sending NS NOTIFY over UDP")
dns.query.udp(msg, ip, port=port, timeout=2) dns.query.udp(msg, ip, port=port, timeout=2)
LOGGER.info( LOGGER.info(f"NS NOTIFY sent: {ip} {view_name}/{fqdn} {soa_serial}")
f"NS NOTIFY sent: {ip} {view_name}/{fqdn} {soa_serial}"
)
except Exception as e: except Exception as e:
LOGGER.error( LOGGER.error(
f"NS NOTIFY failed: {ip} {view_name}/{fqdn} {soa_serial}: {e}" f"NS NOTIFY failed: {ip} {view_name}/{fqdn} {soa_serial}: {e}"
@@ -242,24 +238,24 @@ def _resolve_zone_nameserver_ips(zone: Zone) -> list:
return ips return ips
def schedule(zone: Zone): def schedule_client_notify(zone: Zone):
soa_serial = _get_soa_serial(zone) soa_serial = _get_soa_serial(zone)
if soa_serial is None: if soa_serial is None:
return return
SendDNSNotify.enqueue( SendClientDNSNotify.enqueue(
zone_name=zone.name, zone_name=zone.name,
view_name=zone.view.name, view_name=zone.view.name,
soa_serial=soa_serial, soa_serial=soa_serial,
) )
def schedule_notify_ns(zone: Zone): def schedule_ns_notify(zone: Zone):
soa_serial = _get_soa_serial(zone) soa_serial = _get_soa_serial(zone)
if soa_serial is None: if soa_serial is None:
return return
SendZoneNSNotify.enqueue( SendNSNotify.enqueue(
zone_id=zone.pk, zone_id=zone.pk,
zone_name=zone.name, zone_name=zone.name,
view_name=zone.view.name, view_name=zone.view.name,
@@ -52,12 +52,12 @@ def zone_post_save(sender, instance, created, **kwargs):
catzm.increment_soa_serial() catzm.increment_soa_serial()
if SETTINGS.get("notify_clients", False): if SETTINGS.get("notify_clients", False):
notify_handler.schedule(zone) notify_handler.schedule_client_notify(zone)
# Send a NOTIFY to the zone's own nameservers when its SOA serial changed # Send a NOTIFY to the zone's own nameservers when its SOA serial changed
# and the feature is enabled — globally or per zone via a custom field. # and the feature is enabled — globally or per zone via a custom field.
if soa_serial_changed and _notify_ns_enabled(zone): if soa_serial_changed and _notify_ns_enabled(zone):
notify_handler.schedule_notify_ns(zone) notify_handler.schedule_ns_notify(zone)
transaction.on_commit(_on_commit) transaction.on_commit(_on_commit)