Skip to content

Commit

Permalink
Handle moved project notifications on controller stream
Browse files Browse the repository at this point in the history
  • Loading branch information
grossmj committed Jan 12, 2024
1 parent fefda50 commit 18be274
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 10 additions & 0 deletions gns3/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,16 @@ def _event_received(self, result, *args, **kwargs):
elif result["action"] == "compute.created" or result["action"] == "compute.updated":
from .compute_manager import ComputeManager
ComputeManager.instance().computeDataReceivedCallback(result["event"])
elif result["action"] == "project.closed":
from .topology import Topology
project = Topology.instance().project()
if project and project.id() == result["event"]["project_id"]:
Topology.instance().setProject(None)
elif result["action"] == "project.updated":
from .topology import Topology
project = Topology.instance().project()
if project and project.id() == result["event"]["project_id"]:
project.projectUpdatedCallback(result["event"])
elif result["action"] == "log.error":
log.error(result["event"]["message"])
elif result["action"] == "log.warning":
Expand Down
9 changes: 6 additions & 3 deletions gns3/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,9 @@ def update(self):
"variables": self._variables,
"supplier": self._supplier
}
self.put("", self._projectUpdatedCallback, body=body)
self.put("", self.projectUpdatedCallback, body=body)

def _projectUpdatedCallback(self, result, error=False, **kwargs):
def projectUpdatedCallback(self, result, error=False, **kwargs):
if error:
self.project_creation_error_signal.emit(result["message"])
return
Expand Down Expand Up @@ -712,10 +712,13 @@ def _event_received(self, result, *args, **kwargs):
drawing = Topology.instance().getDrawingFromUuid(result["event"]["drawing_id"])
if drawing is not None:
drawing.delete(skip_controller=True)
# project.closed and project.updated notifications have been moved to the controller
# because they are not project specific, keeping it there for backward compatibility
# when connected to an older controller version
elif result["action"] == "project.closed":
Topology.instance().setProject(None)
elif result["action"] == "project.updated":
self._projectUpdatedCallback(result["event"])
self.projectUpdatedCallback(result["event"])
elif result["action"] == "snapshot.restored":
Topology.instance().restoreSnapshot(result["event"]["project_id"])
elif result["action"] == "log.error":
Expand Down

0 comments on commit 18be274

Please sign in to comment.