1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

make single front/rear port work when between panels

This commit is contained in:
Sander Steffann
2020-05-07 02:12:08 +02:00
parent edf15532d2
commit a0f4d481dc
2 changed files with 176 additions and 16 deletions

View File

@@ -115,26 +115,32 @@ class CableTermination(models.Model):
# Map a front port to its corresponding rear port
if isinstance(termination, FrontPort):
position_stack.append(termination.rear_port_position)
# Retrieve the corresponding RearPort from database to ensure we have an up-to-date instance
peer_port = RearPort.objects.get(pk=termination.rear_port.pk)
# Don't use the stack for 1-on-1 ports, they don't have to come in pairs
if peer_port.positions > 1:
position_stack.append(termination.rear_port_position)
return peer_port
# Map a rear port/position to its corresponding front port
elif isinstance(termination, RearPort):
if termination.positions > 1:
# Can't map to a FrontPort without a position if there are multiple options
if not position_stack:
raise CableTraceSplit(termination)
# Can't map to a FrontPort without a position if there are multiple options
if termination.positions > 1 and not position_stack:
raise CableTraceSplit(termination)
position = position_stack.pop()
# We can assume position 1 if the RearPort has only one position
position = position_stack.pop() if position_stack else 1
# Validate the position
if position not in range(1, termination.positions + 1):
raise Exception("Invalid position for {} ({} positions): {})".format(
termination, termination.positions, position
))
# Validate the position
if position not in range(1, termination.positions + 1):
raise Exception("Invalid position for {} ({} positions): {})".format(
termination, termination.positions, position
))
else:
# Don't use the stack for 1-on-1 ports, they don't have to come in pairs
position = 1
try:
peer_port = FrontPort.objects.get(