fix: remove existing patchpanel backfill

This commit is contained in:
2026-08-06 16:03:58 +02:00
parent 8c6c48531e
commit 66d13292f2
11 changed files with 30 additions and 179 deletions
+1 -17
View File
@@ -75,7 +75,7 @@ def retrace_patchpanel_paths(ports):
return retraced
def synchronize_patchpanel(device_id, *, force_retrace=False):
def synchronize_patchpanel(device_id):
"""Enforce front position 1 -> rear position 1 for a Patchpanel device."""
if not device_id:
return 0
@@ -113,26 +113,10 @@ def synchronize_patchpanel(device_id, *, force_retrace=False):
for front, rear in pairs
]
)
force_retrace = True
if force_retrace:
retrace_patchpanel_paths([*front_ports, *rear_ports])
return len(pairs)
def repair_existing_patchpanels():
"""Repair mappings and cable paths for all existing Patchpanel devices."""
from dcim.models import Device
device_ids = Device.objects.filter(role__name__iexact=PATCHPANEL_ROLE_NAME).values_list("pk", flat=True)
device_count = 0
mapping_count = 0
for device_id in device_ids:
mapping_count += synchronize_patchpanel(device_id, force_retrace=True)
device_count += 1
return device_count, mapping_count
def _component_saved(sender, instance, raw=False, **kwargs):
if not raw and not _component_instantiation_active.get():
synchronize_patchpanel(getattr(instance, "device_id", None))