From 0613efa2979e1955c2b27de95dea7c61593d6dac Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Mon, 15 Aug 2016 20:51:59 +0200 Subject: [PATCH] Support for auto open project --- gns3server/controller/__init__.py | 2 +- gns3server/controller/project.py | 34 ++++++++++++++++++++++++++++++- gns3server/schemas/project.py | 28 +++++++++++++++++++++++++ tests/controller/test_project.py | 11 +++++++++- 4 files changed, 72 insertions(+), 3 deletions(-) diff --git a/gns3server/controller/__init__.py b/gns3server/controller/__init__.py index 84667609..dfcf2b7c 100644 --- a/gns3server/controller/__init__.py +++ b/gns3server/controller/__init__.py @@ -299,7 +299,7 @@ class Controller: self.remove_project(self._projects[topo_data["project_id"]]) project = yield from self.add_project(path=os.path.dirname(path), status="closed", filename=os.path.basename(path), **topo_data) - if load: + if load or project.auto_open: yield from project.open() return project diff --git a/gns3server/controller/project.py b/gns3server/controller/project.py index 65b3b2b1..3172a3b8 100644 --- a/gns3server/controller/project.py +++ b/gns3server/controller/project.py @@ -67,6 +67,8 @@ class Project: assert name is not None self._name = name self._auto_start = False + self._auto_close = False + self._auto_open = False self._status = status # Disallow overwrite of existing project @@ -139,8 +141,35 @@ class Project: @property def auto_start(self): + """ + Should project auto start when opened + """ return self._auto_start + @auto_start.setter + def auto_start(self, val): + self._auto_start = val + + @property + def auto_close(self): + """ + Should project automaticaly closed when client + stop listening for notification + """ + return self._auto_close + + @auto_close.setter + def auto_close(self, val): + self._auto_close = val + + @property + def auto_open(self): + return self._auto_open + + @auto_open.setter + def auto_open(self, val): + self._auto_open = val + @property def controller(self): return self._controller @@ -604,7 +633,10 @@ class Project: "project_id": self._id, "path": self._path, "filename": self._filename, - "status": self._status + "status": self._status, + "auto_start": self._auto_start, + "auto_close": self._auto_close, + "auto_open": self._auto_open } def __repr__(self): diff --git a/gns3server/schemas/project.py b/gns3server/schemas/project.py index 4b81f516..e3733508 100644 --- a/gns3server/schemas/project.py +++ b/gns3server/schemas/project.py @@ -31,6 +31,10 @@ PROJECT_CREATE_SCHEMA = { "type": ["string", "null"], "minLength": 1 }, + "auto_close": { + "description": "Project auto close", + "type": "boolean" + }, "project_id": { "description": "Project UUID", "type": ["string", "null"], @@ -56,6 +60,18 @@ PROJECT_UPDATE_SCHEMA = { "description": "Path of the project on the server (work only with --local)", "type": ["string", "null"] }, + "auto_close": { + "description": "Project auto close when client cut off the notifications feed", + "type": "boolean" + }, + "auto_open": { + "description": "Project open when GNS3 start", + "type": "boolean" + }, + "auto_start": { + "description": "Project start when opened", + "type": "boolean" + } }, "additionalProperties": False, } @@ -90,6 +106,18 @@ PROJECT_OBJECT_SCHEMA = { "status": { "description": "Project status Read only", "enum": ["opened", "closed"] + }, + "auto_close": { + "description": "Project auto close when client cut off the notifications feed", + "type": "boolean" + }, + "auto_open": { + "description": "Project open when GNS3 start", + "type": "boolean" + }, + "auto_start": { + "description": "Project start when opened", + "type": "boolean" } }, "additionalProperties": False, diff --git a/tests/controller/test_project.py b/tests/controller/test_project.py index 771f8ac2..f528a29f 100644 --- a/tests/controller/test_project.py +++ b/tests/controller/test_project.py @@ -59,7 +59,16 @@ def test_affect_uuid(): def test_json(tmpdir): p = Project(name="Test") - assert p.__json__() == {"name": "Test", "project_id": p.id, "path": p.path, "status": "opened", "filename": "Test.gns3"} + assert p.__json__() == { + "name": "Test", + "project_id": p.id, + "path": p.path, + "status": "opened", + "filename": "Test.gns3", + "auto_start": False, + "auto_close": False, + "auto_open": False + } def test_update(controller, async_run):