Skip to content

Commit

Permalink
Inactivate Devices & Links that are deleted in UISP
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew-Dickinson committed Oct 6, 2024
1 parent 3e0a0e3 commit fee33b7
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/meshapi/util/uisp_import/sync_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,22 @@ def import_and_sync_uisp_devices(uisp_devices: List[UISPDevice]) -> None:
device = Device(**device_fields)
device.save()

with transaction.atomic():
for device in Device.objects.filter(uisp_id__isnull=False):
uisp_uuid_set = {uisp_device["identification"]["id"] for uisp_device in uisp_devices}

if device.uisp_id and device.uisp_id not in uisp_uuid_set and device.status != Device.DeviceStatus.INACTIVE:
# If this device has been removed from UISP, mark it as inactive
device.status = Device.DeviceStatus.INACTIVE
device.save()

notify_admins_of_changes(
device,
[
f"Marked as inactive because there is no corresponding device in UISP, it was probably deleted there",
],
)


def import_and_sync_uisp_links(uisp_links: List[UISPDataLink]) -> None:
uisp_session = get_uisp_session()
Expand Down Expand Up @@ -258,6 +274,22 @@ def import_and_sync_uisp_links(uisp_links: List[UISPDataLink]) -> None:
created=True,
)

with transaction.atomic():
for link in Link.objects.filter(uisp_id__isnull=False):
uisp_uuid_set = {uisp_link["id"] for uisp_link in uisp_links}

if link.uisp_id and link.uisp_id not in uisp_uuid_set and link.status != Link.LinkStatus.INACTIVE:
# If this link has been removed from UISP, mark it as inactive
link.status = Link.LinkStatus.INACTIVE
link.save()

notify_admins_of_changes(
link,
[
f"Marked as inactive because there is no corresponding link in UISP, it was probably deleted there",
],
)


def sync_link_table_into_los_objects() -> None:
for link in (
Expand Down

0 comments on commit fee33b7

Please sign in to comment.