Implement requested changes

This commit is contained in:
Austin de Coup-Crank 2023-05-16 11:45:18 -05:00
parent 73891479ae
commit 0b0977d842

View File

@ -354,14 +354,17 @@ 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:
if address := self.cleaned_data.get('address'): if address := self.cleaned_data.get('address'):
if address.ip == address.network and address.prefixlen not in (31, 32, 127, 128): if address.ip == address.network:
self.add_error( msg = f"{address} is a network ID, which may not be assigned to an interface."
'interface', if address.version == 4:
f"{address} is a network ID, which may not be assigned to an interface.") 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: if address.ip == address.broadcast:
self.add_error( msg = f"{address} is a broadcast address, which may not be assigned to an interface."
'interface', raise ValidationError(msg)
f"{address} is a broadcast address, which may not be assigned to an interface.")
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
ipaddress = super().save(*args, **kwargs) ipaddress = super().save(*args, **kwargs)