mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-27 10:58:37 -06:00
Add auto A/AAAA creating when ptr modified & fix bug w/ prefix serial
This commit is contained in:
parent
ee78bf5455
commit
ff5d770766
@ -493,6 +493,7 @@ class IPAddress(CreatedUpdatedModel):
|
|||||||
raise ValidationError("Duplicate IP address found in global table: {}".format(duplicate_ips.first()))
|
raise ValidationError("Duplicate IP address found in global table: {}".format(duplicate_ips.first()))
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
|
self.update_dns()
|
||||||
if self.address:
|
if self.address:
|
||||||
# Infer address family from IPAddress object
|
# Infer address family from IPAddress object
|
||||||
self.family = self.address.version
|
self.family = self.address.version
|
||||||
@ -501,6 +502,31 @@ class IPAddress(CreatedUpdatedModel):
|
|||||||
r.save()
|
r.save()
|
||||||
super(IPAddress, self).save(*args, **kwargs)
|
super(IPAddress, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
def update_dns(self):
|
||||||
|
"""Auto-create a corresponding A/AAAA DNS record (if possible) whenever the PTR field is modified"""
|
||||||
|
if self.ptr:
|
||||||
|
which_zone = None
|
||||||
|
zones = dns.models.Zone.objects.all()
|
||||||
|
for zone in zones:
|
||||||
|
if self.ptr.endswith(zone.name):
|
||||||
|
which_zone = zone
|
||||||
|
break
|
||||||
|
|
||||||
|
if which_zone:
|
||||||
|
zone_name = which_zone.name
|
||||||
|
record_name = self.ptr[:-len(zone_name)]
|
||||||
|
if record_name.endswith('.'):
|
||||||
|
record_name = record_name[:-1]
|
||||||
|
record_type = 'A' if self.family==4 else 'AAAA'
|
||||||
|
|
||||||
|
dns.models.Record.objects.get_or_create(
|
||||||
|
name = record_name,
|
||||||
|
record_type = record_type,
|
||||||
|
zone = which_zone,
|
||||||
|
address = self,
|
||||||
|
description = 'gen by netbox'
|
||||||
|
)
|
||||||
|
|
||||||
def to_csv(self):
|
def to_csv(self):
|
||||||
|
|
||||||
# Determine if this IP is primary for a Device
|
# Determine if this IP is primary for a Device
|
||||||
|
@ -354,11 +354,14 @@ class PrefixBulkEditView(PermissionRequiredMixin, BulkEditView):
|
|||||||
fields_to_update['vrf'] = form.cleaned_data['vrf']
|
fields_to_update['vrf'] = form.cleaned_data['vrf']
|
||||||
elif form.cleaned_data['vrf_global']:
|
elif form.cleaned_data['vrf_global']:
|
||||||
fields_to_update['vrf'] = None
|
fields_to_update['vrf'] = None
|
||||||
for field in ['site', 'status', 'role', 'description']:
|
for field in ['site', 'status', 'role', 'description', 'ttl', 'soa_name', 'soa_contact', 'soa_refresh', 'soa_retry', 'soa_expire', 'soa_minimum']:
|
||||||
if form.cleaned_data[field]:
|
if form.cleaned_data[field]:
|
||||||
fields_to_update[field] = form.cleaned_data[field]
|
fields_to_update[field] = form.cleaned_data[field]
|
||||||
|
|
||||||
return self.cls.objects.filter(pk__in=pk_list).update(**fields_to_update)
|
plist = self.cls.objects.filter(pk__in=pk_list)
|
||||||
|
for p in plist:
|
||||||
|
p.save()
|
||||||
|
return plist.update(**fields_to_update)
|
||||||
|
|
||||||
|
|
||||||
class PrefixBulkDeleteView(PermissionRequiredMixin, BulkDeleteView):
|
class PrefixBulkDeleteView(PermissionRequiredMixin, BulkDeleteView):
|
||||||
@ -484,13 +487,13 @@ class IPAddressBulkEditView(PermissionRequiredMixin, BulkEditView):
|
|||||||
fields_to_update['vrf'] = form.cleaned_data['vrf']
|
fields_to_update['vrf'] = form.cleaned_data['vrf']
|
||||||
elif form.cleaned_data['vrf_global']:
|
elif form.cleaned_data['vrf_global']:
|
||||||
fields_to_update['vrf'] = None
|
fields_to_update['vrf'] = None
|
||||||
for field in ['description']:
|
for field in ['ptr', 'description']:
|
||||||
if form.cleaned_data[field]:
|
if form.cleaned_data[field]:
|
||||||
fields_to_update[field] = form.cleaned_data[field]
|
fields_to_update[field] = form.cleaned_data[field]
|
||||||
|
|
||||||
iplist = self.cls.objects.filter(pk__in=pk_list)
|
iplist = self.cls.objects.filter(pk__in=pk_list)
|
||||||
for ip in iplist:
|
for ip in iplist:
|
||||||
ip.save() # in order to update dns zones serials
|
ip.save()
|
||||||
return iplist.update(**fields_to_update)
|
return iplist.update(**fields_to_update)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user