Prevent the attachment of a Cable to a CircuitTermination on a Cloud

This commit is contained in:
Jeremy Stretch
2021-03-18 15:07:22 -04:00
parent d45edcd216
commit b6f6293b76
2 changed files with 24 additions and 3 deletions

View File

@@ -242,6 +242,16 @@ class Cable(PrimaryModel):
):
raise ValidationError("A front port cannot be connected to it corresponding rear port")
# A CircuitTermination attached to a Cloud cannot have a Cable
if isinstance(self.termination_a, CircuitTermination) and self.termination_a.cloud is not None:
raise ValidationError({
'termination_a_id': "Circuit terminations attached to a cloud may not be cabled."
})
if isinstance(self.termination_b, CircuitTermination) and self.termination_b.cloud is not None:
raise ValidationError({
'termination_b_id': "Circuit terminations attached to a cloud may not be cabled."
})
# Check for an existing Cable connected to either termination object
if self.termination_a.cable not in (None, self):
raise ValidationError("{} already has a cable attached (#{})".format(