Skip to content

Commit

Permalink
Add device_update websocket events for action CREATED and DELETED
Browse files Browse the repository at this point in the history
  • Loading branch information
indy-independence committed Aug 23, 2023
1 parent 89afd7f commit 5195423
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/cnaas_nms/db/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 5195423

Please sign in to comment.