mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 14:01:15 +02:00
Add project.created, project.opened and project.deleted controller notification stream.
Move project.updated and project.closed from project notification to controller notification stream.
This commit is contained in:
4 files changed
+103
-73
No files matched your search
@@ -130,16 +130,27 @@ class Project:
|
||||
self._iou_id_lock = asyncio.Lock()
|
||||
|
||||
log.debug('Project "{name}" [{id}] loaded'.format(name=self.name, id=self._id))
|
||||
self.emit_controller_notification("project.created", self.__json__())
|
||||
|
||||
def emit_notification(self, action, event):
|
||||
"""
|
||||
Emit a notification to all clients using this project.
|
||||
Emit a project notification to all clients using this project.
|
||||
|
||||
:param action: Action name
|
||||
:param event: Event to send
|
||||
"""
|
||||
|
||||
self.controller.notification.project_emit(action, event, project_id=self.id)
|
||||
self._controller.notification.project_emit(action, event, project_id=self.id)
|
||||
|
||||
def emit_controller_notification(self, action, event):
|
||||
"""
|
||||
Emit a controller notification, all clients will see it.
|
||||
|
||||
:param action: Action name
|
||||
:param event: Event to send
|
||||
"""
|
||||
|
||||
self._controller.notification.controller_emit(action, event)
|
||||
|
||||
async def update(self, **kwargs):
|
||||
"""
|
||||
@@ -154,7 +165,7 @@ class Project:
|
||||
|
||||
# We send notif only if object has changed
|
||||
if old_json != self.__json__():
|
||||
self.emit_notification("project.updated", self.__json__())
|
||||
self.emit_controller_notification("project.updated", self.__json__())
|
||||
self.dump()
|
||||
|
||||
# update on computes
|
||||
@@ -803,7 +814,8 @@ class Project:
|
||||
self._clean_pictures()
|
||||
self._status = "closed"
|
||||
if not ignore_notification:
|
||||
self.emit_notification("project.closed", self.__json__())
|
||||
self.emit_controller_notification("project.closed", self.__json__())
|
||||
|
||||
self.reset()
|
||||
self._closing = False
|
||||
|
||||
@@ -857,6 +869,7 @@ class Project:
|
||||
shutil.rmtree(self.path)
|
||||
except OSError as e:
|
||||
raise aiohttp.web.HTTPConflict(text="Cannot delete project directory {}: {}".format(self.path, str(e)))
|
||||
self.emit_controller_notification("project.deleted", self.__json__())
|
||||
|
||||
async def delete_on_computes(self):
|
||||
"""
|
||||
@@ -976,7 +989,7 @@ class Project:
|
||||
await self.add_drawing(dump=False, **drawing_data)
|
||||
|
||||
self.dump()
|
||||
# We catch all error to be able to rollback the .gns3 to the previous state
|
||||
# We catch all error to be able to roll back the .gns3 to the previous state
|
||||
except Exception as e:
|
||||
for compute in list(self._project_created_on_compute):
|
||||
try:
|
||||
@@ -1001,6 +1014,7 @@ class Project:
|
||||
pass
|
||||
|
||||
self._loading = False
|
||||
self.emit_controller_notification("project.opened", self.__json__())
|
||||
# Should we start the nodes when project is open
|
||||
if self._auto_start:
|
||||
# Start all in the background without waiting for completion
|
||||
|
||||
Reference in new issue
Block a user