mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 09:16:10 -06:00
Condensed the "if" logic a bit
This commit is contained in:
parent
0b0977d842
commit
0338f566a2
@ -352,19 +352,16 @@ class IPAddressForm(TenancyForm, NetBoxModelForm):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Do not allow assigning a network ID or broadcast address to an interface.
|
# Do not allow assigning a network ID or broadcast address to an interface.
|
||||||
if interface:
|
if interface and (address := self.cleaned_data.get('address')):
|
||||||
if address := self.cleaned_data.get('address'):
|
if address.ip == address.network:
|
||||||
if address.ip == address.network:
|
msg = f"{address} is a network ID, which may not be assigned to an interface."
|
||||||
msg = f"{address} is a network ID, which may not be assigned to an interface."
|
if address.version == 4 and address.prefixlen not in (31, 32):
|
||||||
if address.version == 4:
|
|
||||||
if address.prefixlen not in (31, 32):
|
|
||||||
raise ValidationError(msg)
|
|
||||||
if address.version == 6:
|
|
||||||
if address.prefixlen not in (127, 128):
|
|
||||||
raise ValidationError(msg)
|
|
||||||
if address.ip == address.broadcast:
|
|
||||||
msg = f"{address} is a broadcast address, which may not be assigned to an interface."
|
|
||||||
raise ValidationError(msg)
|
raise ValidationError(msg)
|
||||||
|
if address.version == 6 and address.prefixlen not in (127, 128):
|
||||||
|
raise ValidationError(msg)
|
||||||
|
if address.ip == address.broadcast:
|
||||||
|
msg = f"{address} is a broadcast address, which may not be assigned to an interface."
|
||||||
|
raise ValidationError(msg)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
ipaddress = super().save(*args, **kwargs)
|
ipaddress = super().save(*args, **kwargs)
|
||||||
|
Loading…
Reference in New Issue
Block a user