Skip to content

Commit

Permalink
Fixes netbox-community#810: Suppress unique IP validation on invalid …
Browse files Browse the repository at this point in the history
…IP addresses and prefixes
  • Loading branch information
jeremystretch committed Jan 18, 2017
1 parent 1f6619e commit 1350976
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions netbox/ipam/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,9 @@ def get_duplicates(self):

def clean(self):

# Disallow host masks
if self.prefix:

# Disallow host masks
if self.prefix.version == 4 and self.prefix.prefixlen == 32:
raise ValidationError({
'prefix': "Cannot create host addresses (/32) as prefixes. Create an IPv4 address instead."
Expand All @@ -314,16 +315,16 @@ def clean(self):
'prefix': "Cannot create host addresses (/128) as prefixes. Create an IPv6 address instead."
})

# Enforce unique IP space if applicable
if (self.vrf is None and settings.ENFORCE_GLOBAL_UNIQUE) or (self.vrf and self.vrf.enforce_unique):
duplicate_prefixes = self.get_duplicates()
if duplicate_prefixes:
raise ValidationError({
'prefix': "Duplicate prefix found in {}: {}".format(
"VRF {}".format(self.vrf) if self.vrf else "global table",
duplicate_prefixes.first(),
)
})
# Enforce unique IP space (if applicable)
if (self.vrf is None and settings.ENFORCE_GLOBAL_UNIQUE) or (self.vrf and self.vrf.enforce_unique):
duplicate_prefixes = self.get_duplicates()
if duplicate_prefixes:
raise ValidationError({
'prefix': "Duplicate prefix found in {}: {}".format(
"VRF {}".format(self.vrf) if self.vrf else "global table",
duplicate_prefixes.first(),
)
})

def save(self, *args, **kwargs):
if self.prefix:
Expand Down Expand Up @@ -419,16 +420,18 @@ def get_duplicates(self):

def clean(self):

# Enforce unique IP space if applicable
if (self.vrf is None and settings.ENFORCE_GLOBAL_UNIQUE) or (self.vrf and self.vrf.enforce_unique):
duplicate_ips = self.get_duplicates()
if duplicate_ips:
raise ValidationError({
'address': "Duplicate IP address found in {}: {}".format(
"VRF {}".format(self.vrf) if self.vrf else "global table",
duplicate_ips.first(),
)
})
if self.address:

# Enforce unique IP space (if applicable)
if (self.vrf is None and settings.ENFORCE_GLOBAL_UNIQUE) or (self.vrf and self.vrf.enforce_unique):
duplicate_ips = self.get_duplicates()
if duplicate_ips:
raise ValidationError({
'address': "Duplicate IP address found in {}: {}".format(
"VRF {}".format(self.vrf) if self.vrf else "global table",
duplicate_ips.first(),
)
})

def save(self, *args, **kwargs):
if self.address:
Expand Down

0 comments on commit 1350976

Please sign in to comment.