From 359b366b275852ad4dd1ab83a052a55135e63a5b Mon Sep 17 00:00:00 2001 From: Daniel Sheppard Date: Tue, 12 Sep 2023 13:24:00 -0500 Subject: [PATCH] Improve handling of links with multi-terminations --- netbox/dcim/models/cables.py | 20 ++++++++++++++++++-- netbox/dcim/tests/test_cablepaths.py | 6 ++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/netbox/dcim/models/cables.py b/netbox/dcim/models/cables.py index 21f1e9466..0b5dbb92a 100644 --- a/netbox/dcim/models/cables.py +++ b/netbox/dcim/models/cables.py @@ -551,8 +551,12 @@ class CablePath(models.Model): is_complete = False is_split = True - # Step 4: Record the links - path.append([object_to_path_node(link) for link in links]) + # Step 4: Record the links, keeping cables in order to allow for SVG rendering + cables = [] + for link in links: + if object_to_path_node(link) not in cables: + cables.append(object_to_path_node(link)) + path.append(cables) # Step 5: Update the path status if a link is not connected links_status = [link.status for link in links if link.status != LinkStatusChoices.STATUS_CONNECTED] @@ -782,3 +786,15 @@ class CablePath(models.Model): return [ ct.get_peer_termination() for ct in nodes ] + + def get_asymmetric_nodes(self): + """ + Return all available next segments in a split cable path. + """ + from circuits.models import CircuitTermination + asymmetric_nodes = [] + for nodes in self.path_objects: + if type(nodes[0]) in [RearPort, FrontPort, CircuitTermination]: + asymmetric_nodes.extend([node for node in nodes if node.link is None]) + + return asymmetric_nodes diff --git a/netbox/dcim/tests/test_cablepaths.py b/netbox/dcim/tests/test_cablepaths.py index bad515742..73093be6d 100644 --- a/netbox/dcim/tests/test_cablepaths.py +++ b/netbox/dcim/tests/test_cablepaths.py @@ -50,9 +50,7 @@ class CablePathTestCase(TestCase): path.append([object_to_path_node(node) for node in step]) else: path.append([object_to_path_node(step)]) - - cablepath = CablePath.objects.filter(path=path, **kwargs).first() - return cablepath + return CablePath.objects.filter(path=path, **kwargs).first() def assertPathExists(self, nodes, **kwargs): """ @@ -333,7 +331,7 @@ class CablePathTestCase(TestCase): is_active=True ) path2 = self.assertPathExists( - ((interface3, interface4), (cable1, cable1), (interface1, interface2)), + ((interface3, interface4), cable1, (interface1, interface2)), is_complete=True, is_active=True )