GNS3 / gns3-server

GNS3 server
GNU General Public License v3.0
768 stars 258 forks source link

Add 'project.opened' WebSocket notification #2319

Closed andrei-korshikov closed 5 months ago

andrei-korshikov commented 8 months ago

Using version 2.2.44. Looking at /v2/notifications/ws and /v2/compute/notifications/ws. When new project becomes alive, there is no any special notification, just usual stream of 'ping' (from compute) and 'compute.updated' (from controller). So, to catch the moment when new project is opened (or created), I have to constantly poll /v2/projects and watch if there is something new. Not a problem, but it would be nice to be notified. What about /v2/projects/ws?;)

grossmj commented 7 months ago

Actually there is another endpoint that isn't well documented for project specific notifications: https://gns3-server.readthedocs.io/en/stable/api/v2/controller/project/projectsprojectidnotificationsws.html (we have one WebSocket connection per project).

You will receive notifications like "project.updated" or "project.closed" but no "project.opened". I can add "project.opened" but it wouldn't make sense to have it on the project notification endpoint since that channel is only listened to once the project has already been opened.

Maybe a "project.created" and "project.deleted" for /v2/notifications/ws would be good?

andrei-korshikov commented 7 months ago

I totally understand that "project.opened" is not suitable for /v2/projects/{project_id}/notifications/ws, and agree that /v2/notifications/ws would be the right place.

Do you plan to distinguish between "project.created" and "project.opened"? The question is: is "created" project also "opened" one? I think yes (every "created" is "opened", but not every "opened" is "created"), but I'm not sure.

grossmj commented 7 months ago

Do you plan to distinguish between "project.created" and "project.opened"? The question is: is "created" project also "opened" one? I think yes (every "created" is "opened", but not every "opened" is "created"), but I'm not sure.

I am thinking just having "project.created" when a new project is created.

andrei-korshikov commented 7 months ago

How to determine the moment when existed (previously closed) project becomes opened?

I think, I should provide some clarification about my use case. I'm not opening/creating projects in my app. Instead, my app is waiting until a project is opened/created in GNS3 GUI (more precisely, it's looking for another project with status == 'opened'), and after that my script does some small automation.

grossmj commented 7 months ago

I think, I should provide some clarification about my use case. I'm not opening/creating projects in my app. Instead, my app is waiting until a project is opened/created in GNS3 GUI (more precisely, it's looking for another project with status == 'opened'), and after that my script does some small automation.

Ok, so I think we can have both "project.created" and "project.opened" then. Also, for consistency, I am considering moving "project.updated" and "project.closed" from /v2/projects/{project_id}/notifications/ws to /v2/notifications/ws. It makes more sense this way.

grossmj commented 5 months ago

Starting with version 2.2.45, /v2/notifications/ws will have the following notifications: project.created, project.opened, project.updated, project.closed as well as project.deleted

andrei-korshikov commented 5 months ago

Thanks a lot!