From 509b171b06dc66143a92774a42ef3ad4be93e1ac Mon Sep 17 00:00:00 2001 From: grossmj Date: Fri, 30 Mar 2018 23:01:37 +0700 Subject: [PATCH] Allow to have projects with the same name in different locations. --- gns3server/controller/__init__.py | 9 ++++++--- gns3server/controller/topology.py | 4 ++++ tests/test_topologies.py | 2 +- tests/topologies/1_5_qemu/after/testqemu.gns3 | 2 +- .../topologies/1_5_virtualbox/after/1_5_virtualbox.gns3 | 2 +- tests/topologies/1_5_vmware/after/1_5_vmware.gns3 | 2 +- tests/topologies/2_0_vmware/after/1_5_vmware.gns3 | 2 +- 7 files changed, 15 insertions(+), 8 deletions(-) diff --git a/gns3server/controller/__init__.py b/gns3server/controller/__init__.py index fe3ab2f0..7e162d14 100644 --- a/gns3server/controller/__init__.py +++ b/gns3server/controller/__init__.py @@ -535,7 +535,7 @@ class Controller: return compute_id in self._computes @asyncio.coroutine - def add_project(self, project_id=None, name=None, **kwargs): + def add_project(self, project_id=None, name=None, path=None, **kwargs): """ Creates a project or returns an existing project @@ -547,8 +547,11 @@ class Controller: if project_id not in self._projects: for project in self._projects.values(): if name and project.name == name: - raise aiohttp.web.HTTPConflict(text='Project name "{}" already exists'.format(name)) - project = Project(project_id=project_id, controller=self, name=name, **kwargs) + if path and path == project.path: + raise aiohttp.web.HTTPConflict(text='Project "{}" already exists in location "{}"'.format(name, path)) + else: + raise aiohttp.web.HTTPConflict(text='Project "{}" already exists'.format(name)) + project = Project(project_id=project_id, controller=self, name=name, path=path, **kwargs) self._projects[project.id] = project return self._projects[project.id] return self._projects[project_id] diff --git a/gns3server/controller/topology.py b/gns3server/controller/topology.py index fba3e40b..85a9fcbc 100644 --- a/gns3server/controller/topology.py +++ b/gns3server/controller/topology.py @@ -183,6 +183,10 @@ def _convert_2_1_0(topo, topo_path): if "properties" in node: if node["node_type"] in ("qemu", "vmware", "virtualbox"): if "acpi_shutdown" in node["properties"]: + if node["properties"]["acpi_shutdown"] is True: + node["properties"]["on_close"] = "save_vm_sate" + else: + node["properties"]["on_close"] = "power_off" del node["properties"]["acpi_shutdown"] if "save_vm_state" in node["properties"]: del node["properties"]["save_vm_state"] diff --git a/tests/test_topologies.py b/tests/test_topologies.py index 313dfd3f..0dcf16a4 100644 --- a/tests/test_topologies.py +++ b/tests/test_topologies.py @@ -100,7 +100,7 @@ def test_convert(directory, tmpdir): def compare_dict(path, source, reference): """ - Compare two dictionnary of a topology + Compare two dictionary of a topology """ assert isinstance(source, dict), "Source is not a dict in {}".format(path) for key in source: diff --git a/tests/topologies/1_5_qemu/after/testqemu.gns3 b/tests/topologies/1_5_qemu/after/testqemu.gns3 index db3d15c4..c011b753 100644 --- a/tests/topologies/1_5_qemu/after/testqemu.gns3 +++ b/tests/topologies/1_5_qemu/after/testqemu.gns3 @@ -34,7 +34,7 @@ "port_segment_size": 0, "first_port_name": null, "properties": { - "acpi_shutdown": false, + "on_close": "power_off", "adapter_type": "e1000", "adapters": 1, "boot_priority": "c", diff --git a/tests/topologies/1_5_virtualbox/after/1_5_virtualbox.gns3 b/tests/topologies/1_5_virtualbox/after/1_5_virtualbox.gns3 index ba17e46d..052050e1 100644 --- a/tests/topologies/1_5_virtualbox/after/1_5_virtualbox.gns3 +++ b/tests/topologies/1_5_virtualbox/after/1_5_virtualbox.gns3 @@ -35,7 +35,7 @@ "first_port_name": null, "properties": { "linked_clone": false, - "acpi_shutdown": false, + "on_close": "power_off", "adapter_type": "Intel PRO/1000 MT Desktop (82540EM)", "adapters": 1, "headless": false, diff --git a/tests/topologies/1_5_vmware/after/1_5_vmware.gns3 b/tests/topologies/1_5_vmware/after/1_5_vmware.gns3 index 8238605c..ba1f9fac 100644 --- a/tests/topologies/1_5_vmware/after/1_5_vmware.gns3 +++ b/tests/topologies/1_5_vmware/after/1_5_vmware.gns3 @@ -35,7 +35,7 @@ "first_port_name": null, "properties": { "linked_clone": false, - "acpi_shutdown": false, + "on_close": "power_off", "adapter_type": "e1000", "adapters": 1, "headless": false, diff --git a/tests/topologies/2_0_vmware/after/1_5_vmware.gns3 b/tests/topologies/2_0_vmware/after/1_5_vmware.gns3 index 98a25f62..77501c89 100644 --- a/tests/topologies/2_0_vmware/after/1_5_vmware.gns3 +++ b/tests/topologies/2_0_vmware/after/1_5_vmware.gns3 @@ -34,7 +34,7 @@ "port_segment_size": 0, "first_port_name": null, "properties": { - "acpi_shutdown": false, + "on_close": "power_off", "adapter_type": "e1000", "adapters": 1, "headless": false,