mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-20 19:19:22 -06:00
cleaned up IPAddress clean() to be more like Prefix's
This commit is contained in:
parent
eedec192ba
commit
485a21f13e
@ -422,19 +422,13 @@ class IPAddress(CreatedUpdatedModel, CustomFieldModel):
|
|||||||
return reverse('ipam:ipaddress', args=[self.pk])
|
return reverse('ipam:ipaddress', args=[self.pk])
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
if ((not self.vrf and settings.ENFORCE_GLOBAL_UNIQUE) or (self.vrf and self.vrf.enforce_unique)):
|
|
||||||
dupes = IPAddress.objects.duplicates(self)
|
|
||||||
if dupes:
|
|
||||||
raise ValidationError({
|
|
||||||
'address': "Duplicate IP address found in global table: {}".format(dupes.first())
|
|
||||||
})
|
|
||||||
|
|
||||||
# Enforce unique IP space if applicable
|
# Enforce unique IP space if applicable
|
||||||
if ((not self.vrf and settings.ENFORCE_GLOBAL_UNIQUE) or (self.vrf and self.vrf.enforce_unique)):
|
if ((not self.vrf and settings.ENFORCE_GLOBAL_UNIQUE) or (self.vrf and self.vrf.enforce_unique)):
|
||||||
dupes = IPAddress.objects.duplicates(self)
|
dupes = IPAddress.objects.duplicates(self)
|
||||||
if dupes:
|
if dupes:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
'address': "Duplicate IP address found in {}: {}".format(
|
'address': "Duplicate IP Address found in {}: {}".format(
|
||||||
"VRF {}".format(self.vrf) if self.vrf else "global table",
|
"VRF {}".format(self.vrf) if self.vrf else "global table",
|
||||||
dupes.first(),
|
dupes.first(),
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user