mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 17:38:37 -06:00
Improve Interface validation
This commit is contained in:
parent
7396975500
commit
2c9b791b85
@ -141,7 +141,9 @@ class CableTermination(models.Model):
|
|||||||
super().clean()
|
super().clean()
|
||||||
|
|
||||||
if self.mark_connected and self.cable_id:
|
if self.mark_connected and self.cable_id:
|
||||||
raise ValidationError("Cannot set mark_connected with a cable connected.")
|
raise ValidationError({
|
||||||
|
"mark_connected": "Cannot mark as connected with a cable attached."
|
||||||
|
})
|
||||||
|
|
||||||
def get_cable_peer(self):
|
def get_cable_peer(self):
|
||||||
return self._cable_peer
|
return self._cable_peer
|
||||||
@ -596,12 +598,15 @@ class Interface(ComponentModel, BaseInterface, CableTermination, PathEndpoint):
|
|||||||
super().clean()
|
super().clean()
|
||||||
|
|
||||||
# Virtual interfaces cannot be connected
|
# Virtual interfaces cannot be connected
|
||||||
if self.type in NONCONNECTABLE_IFACE_TYPES and (
|
if not self.is_connectable and self.cable:
|
||||||
self.cable or getattr(self, 'circuit_termination', False)
|
|
||||||
):
|
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
'type': "Virtual and wireless interfaces cannot be connected to another interface or circuit. "
|
'type': f"{self.get_type_display()} interfaces cannot have a cable attached."
|
||||||
"Disconnect the interface or choose a suitable type."
|
})
|
||||||
|
|
||||||
|
# Non-connectable interfaces cannot be marked as connected
|
||||||
|
if not self.is_connectable and self.mark_connected:
|
||||||
|
raise ValidationError({
|
||||||
|
'mark_connected': f"{self.get_type_display()} interfaces cannot be marked as connected."
|
||||||
})
|
})
|
||||||
|
|
||||||
# An interface's parent must belong to the same device or virtual chassis
|
# An interface's parent must belong to the same device or virtual chassis
|
||||||
|
Loading…
Reference in New Issue
Block a user