Record wireless links as part of cable path

This commit is contained in:
jeremystretch
2021-10-13 13:28:14 -04:00
parent 445e16f668
commit 138af27bf7
5 changed files with 59 additions and 38 deletions

View File

@@ -1,4 +1,5 @@
from django.contrib.contenttypes.models import ContentType
from django.db import transaction
def compile_path_node(ct_id, object_id):
@@ -26,3 +27,29 @@ def path_node_to_object(repr):
ct_id, object_id = decompile_path_node(repr)
ct = ContentType.objects.get_for_id(ct_id)
return ct.model_class().objects.get(pk=object_id)
def create_cablepath(node):
"""
Create CablePaths for all paths originating from the specified node.
"""
from dcim.models import CablePath
cp = CablePath.from_origin(node)
if cp:
cp.save()
def rebuild_paths(obj):
"""
Rebuild all CablePaths which traverse the specified node
"""
from dcim.models import CablePath
cable_paths = CablePath.objects.filter(path__contains=obj)
with transaction.atomic():
for cp in cable_paths:
cp.delete()
if cp.origin:
create_cablepath(cp.origin)