From 4a36310ff4c5c163cbd04deb3d314932dd54501d Mon Sep 17 00:00:00 2001 From: BENOIT JEAN Date: Thu, 5 Oct 2023 18:52:27 +0200 Subject: [PATCH] Fix IP coupling when zone is renamed or deleted When a zone is renamed, and an (IPAM) IP address is linked to a "A" or "AAAA" DNS record from this zone, the dns_name field is updated. When a zone is deleted, and an (IPAM) IP address is linked to a "A" or "AAAA" DNS record from this zone, the dns_name field and custom field "name" are emptied. --- netbox_dns/models.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/netbox_dns/models.py b/netbox_dns/models.py index 570e842d..b577a618 100644 --- a/netbox_dns/models.py +++ b/netbox_dns/models.py @@ -9,8 +9,8 @@ from dns.rdtypes.ANY import SOA from dns.exception import DNSException -from netaddr import IPNetwork, AddrFormatError -from ipam.models import IPAddress +from netaddr import IPNetwork, AddrFormatError, IPAddress +from ipam.models import IPAddress as IP from django.core.validators import ( MinValueValidator, @@ -557,9 +557,9 @@ def save(self, *args, **kwargs): ): record.update_ptr_record() - # Fix name in IPAddress when zone name is changed + # Fix name in IP Address when zone name is changed if get_plugin_config("netbox_dns", "feature_ipam_coupling") and name_changed: - for ip in IPAddress.objects.filter(custom_field_data__zone=self.pk): + for ip in IP.objects.filter(custom_field_data__zone=self.pk): ip.dns_name = f'{ip.custom_field_data["name"]}.{self.name}' ip.save(update_fields=["dns_name"]) @@ -579,7 +579,7 @@ def delete(self, *args, **kwargs): if get_plugin_config("netbox_dns", "feature_ipam_coupling"): # Remove coupling from IPAddress to DNS record when zone is deleted - for ip in IPAddress.objects.filter(custom_field_data__zone=self.pk): + for ip in IP.objects.filter(custom_field_data__zone=self.pk): ip.dns_name = "" ip.custom_field_data["name"] = "" ip.custom_field_data["dns_record"] = None