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

Refactor CablePath.from_origin()

This commit is contained in:
jeremystretch
2022-05-10 09:53:55 -04:00
parent b44bfa1aa6
commit 5667a9c456
3 changed files with 100 additions and 97 deletions

View File

@@ -85,23 +85,20 @@ def update_connected_endpoints(instance, created, raw=False, **kwargs):
term for term in instance.terminations if not term.pk
])
# Split terminations into A/B sets
_terms = defaultdict(list)
for term in instance.terminations:
_terms[term.cable_end].append(term)
# Split terminations into A/B sets and save link assignments
# TODO: Update link peers
# Set cable on terminating endpoints
for term in instance.terminations:
if term.termination.cable != instance:
term.termination.cable = instance
term.termination.save()
_terms = defaultdict(list)
for t in instance.terminations:
if t.termination.cable != instance:
t.termination.cable = instance
t.termination.save()
_terms[t.cable_end].append(t.termination)
# Create/update cable paths
if created:
for terms in _terms.values():
# Examine type of first termination to determine object type (all must be the same)
if isinstance(terms[0].termination, PathEndpoint):
if isinstance(terms[0], PathEndpoint):
create_cablepath(terms)
# else:
# rebuild_paths(terms)