From 519542322c8a5e3d218217fa3f8cdab9b7f73b7b Mon Sep 17 00:00:00 2001 From: Johan Marcusson Date: Wed, 23 Aug 2023 09:42:47 +0200 Subject: [PATCH] Add device_update websocket events for action CREATED and DELETED --- src/cnaas_nms/db/device.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/cnaas_nms/db/device.py b/src/cnaas_nms/db/device.py index 86e3ad09..b0771189 100644 --- a/src/cnaas_nms/db/device.py +++ b/src/cnaas_nms/db/device.py @@ -490,3 +490,17 @@ def after_update_device(mapper, connection, target: Device): update_data = {"action": "UPDATED", "device_id": target.id, "hostname": target.hostname, "object": target.as_dict()} json_data = json.dumps(update_data) add_event(json_data=json_data, event_type="update", update_type="device") + + +@event.listens_for(Device, "before_delete") +def before_delete_device(mapper, connection, target: Device): + update_data = {"action": "DELETED", "device_id": target.id, "hostname": target.hostname, "object": target.as_dict()} + json_data = json.dumps(update_data) + add_event(json_data=json_data, event_type="update", update_type="device") + + +@event.listens_for(Device, "after_insert") +def after_insert_device(mapper, connection, target: Device): + update_data = {"action": "CREATED", "device_id": target.id, "hostname": target.hostname, "object": target.as_dict()} + json_data = json.dumps(update_data) + add_event(json_data=json_data, event_type="update", update_type="device")