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

Drop support for split paths

This commit is contained in:
Jeremy Stretch
2020-10-01 14:16:43 -04:00
parent cd398b15d8
commit 610420c020
13 changed files with 66 additions and 97 deletions

View File

@ -1,5 +1,6 @@
from django.contrib.contenttypes.models import ContentType
from .exceptions import CableTraceSplit
from .models import FrontPort, RearPort
@ -17,13 +18,13 @@ def path_node_to_object(repr):
return model_class.objects.get(pk=int(object_id))
def trace_paths(node):
def trace_path(node):
destination = None
path = []
position_stack = []
if node.cable is None:
return []
return [], None
while node.cable is not None:
@ -50,20 +51,12 @@ def trace_paths(node):
node = FrontPort.objects.get(rear_port=peer_termination, rear_port_position=position)
path.append(object_to_path_node(node))
else:
# No position indicated, so we have to trace _all_ peer FrontPorts
paths = []
for frontport in FrontPort.objects.filter(rear_port=peer_termination):
branches = trace_paths(frontport)
if branches:
for branch, destination in branches:
paths.append(([*path, object_to_path_node(frontport), *branch], destination))
else:
paths.append(([*path, object_to_path_node(frontport)], None))
return paths
# No position indicated: path has split (probably invalid?)
raise CableTraceSplit(peer_termination)
# Anything else marks the end of the path
else:
destination = peer_termination
break
return [(path, destination)]
return path, destination