From 59c82e26df0c05be5c6a2a3e37f27a3aee43224d Mon Sep 17 00:00:00 2001 From: Jeremy Date: Tue, 3 Feb 2015 18:40:13 -0700 Subject: [PATCH] Use project_id instead of project_uuid for the API. --- gns3server/handlers/vpcs_handler.py | 2 +- gns3server/modules/project_manager.py | 14 +++++++------- gns3server/modules/virtualbox/virtualbox_vm.py | 2 +- gns3server/modules/vpcs/vpcs_vm.py | 2 +- gns3server/schemas/virtualbox.py | 8 ++++---- gns3server/schemas/vpcs.py | 8 ++++---- tests/api/test_virtualbox.py | 8 ++++---- tests/api/test_vpcs.py | 16 ++++++++-------- 8 files changed, 30 insertions(+), 30 deletions(-) diff --git a/gns3server/handlers/vpcs_handler.py b/gns3server/handlers/vpcs_handler.py index a63f475a..cbd78c83 100644 --- a/gns3server/handlers/vpcs_handler.py +++ b/gns3server/handlers/vpcs_handler.py @@ -44,7 +44,7 @@ class VPCSHandler: vpcs = VPCS.instance() vm = yield from vpcs.create_vm(request.json["name"], - request.json["project_uuid"], + request.json["project_id"], request.json.get("uuid"), console=request.json.get("console"), startup_script=request.json.get("startup_script")) diff --git a/gns3server/modules/project_manager.py b/gns3server/modules/project_manager.py index edcfe425..1aa264b1 100644 --- a/gns3server/modules/project_manager.py +++ b/gns3server/modules/project_manager.py @@ -42,23 +42,23 @@ class ProjectManager: cls._instance = cls() return cls._instance - def get_project(self, project_uuid): + def get_project(self, uuid): """ Returns a Project instance. - :param project_uuid: Project UUID + :param uuid: Project UUID :returns: Project instance """ try: - UUID(project_uuid, version=4) + UUID(uuid, version=4) except ValueError: - raise aiohttp.web.HTTPBadRequest(text="{} is not a valid UUID".format(project_uuid)) + raise aiohttp.web.HTTPBadRequest(text="{} is not a valid UUID".format(uuid)) - if project_uuid not in self._projects: - raise aiohttp.web.HTTPNotFound(text="Project UUID {} doesn't exist".format(project_uuid)) - return self._projects[project_uuid] + if uuid not in self._projects: + raise aiohttp.web.HTTPNotFound(text="Project UUID {} doesn't exist".format(uuid)) + return self._projects[uuid] def create_project(self, **kwargs): """ diff --git a/gns3server/modules/virtualbox/virtualbox_vm.py b/gns3server/modules/virtualbox/virtualbox_vm.py index a5a126c6..018527c1 100644 --- a/gns3server/modules/virtualbox/virtualbox_vm.py +++ b/gns3server/modules/virtualbox/virtualbox_vm.py @@ -79,7 +79,7 @@ class VirtualBoxVM(BaseVM): return {"name": self.name, "uuid": self.uuid, "console": self.console, - "project_uuid": self.project.uuid, + "project_id": self.project.uuid, "vmname": self.vmname, "headless": self.headless, "enable_remote_console": self.enable_remote_console, diff --git a/gns3server/modules/vpcs/vpcs_vm.py b/gns3server/modules/vpcs/vpcs_vm.py index 7f4c4aa8..ce930410 100644 --- a/gns3server/modules/vpcs/vpcs_vm.py +++ b/gns3server/modules/vpcs/vpcs_vm.py @@ -107,7 +107,7 @@ class VPCSVM(BaseVM): return {"name": self.name, "uuid": self.uuid, "console": self._console, - "project_uuid": self.project.uuid, + "project_id": self.project.uuid, "script_file": self.script_file, "startup_script": self.startup_script} diff --git a/gns3server/schemas/virtualbox.py b/gns3server/schemas/virtualbox.py index 713d6f74..1898a280 100644 --- a/gns3server/schemas/virtualbox.py +++ b/gns3server/schemas/virtualbox.py @@ -32,7 +32,7 @@ VBOX_CREATE_SCHEMA = { "description": "VirtualBox VM instance ID (for project created before GNS3 1.3)", "type": "integer" }, - "project_uuid": { + "project_id": { "description": "Project UUID", "type": "string", "minLength": 36, @@ -86,7 +86,7 @@ VBOX_CREATE_SCHEMA = { }, }, "additionalProperties": False, - "required": ["name", "vmname", "linked_clone", "project_uuid"], + "required": ["name", "vmname", "linked_clone", "project_id"], } VBOX_UPDATE_SCHEMA = { @@ -211,7 +211,7 @@ VBOX_OBJECT_SCHEMA = { "maxLength": 36, "pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" }, - "project_uuid": { + "project_id": { "description": "Project UUID", "type": "string", "minLength": 36, @@ -256,5 +256,5 @@ VBOX_OBJECT_SCHEMA = { }, }, "additionalProperties": False, - "required": ["name", "uuid", "project_uuid"] + "required": ["name", "uuid", "project_id"] } diff --git a/gns3server/schemas/vpcs.py b/gns3server/schemas/vpcs.py index b4841034..fae10fe9 100644 --- a/gns3server/schemas/vpcs.py +++ b/gns3server/schemas/vpcs.py @@ -37,7 +37,7 @@ VPCS_CREATE_SCHEMA = { "maxLength": 36, "pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" }, - "project_uuid": { + "project_id": { "description": "Project UUID", "type": "string", "minLength": 36, @@ -56,7 +56,7 @@ VPCS_CREATE_SCHEMA = { }, }, "additionalProperties": False, - "required": ["name", "project_uuid"] + "required": ["name", "project_id"] } VPCS_UPDATE_SCHEMA = { @@ -162,7 +162,7 @@ VPCS_OBJECT_SCHEMA = { "maximum": 65535, "type": "integer" }, - "project_uuid": { + "project_id": { "description": "Project UUID", "type": "string", "minLength": 36, @@ -179,5 +179,5 @@ VPCS_OBJECT_SCHEMA = { }, }, "additionalProperties": False, - "required": ["name", "uuid", "console", "project_uuid"] + "required": ["name", "uuid", "console", "project_id"] } diff --git a/tests/api/test_virtualbox.py b/tests/api/test_virtualbox.py index 4c7a7e5c..08783af3 100644 --- a/tests/api/test_virtualbox.py +++ b/tests/api/test_virtualbox.py @@ -25,7 +25,7 @@ def vm(server, project): response = server.post("/virtualbox", {"name": "VMTEST", "vmname": "VMTEST", "linked_clone": False, - "project_uuid": project.uuid}) + "project_id": project.uuid}) assert mock.called assert response.status == 201 return response.json @@ -37,11 +37,11 @@ def test_vbox_create(server, project): response = server.post("/virtualbox", {"name": "VM1", "vmname": "VM1", "linked_clone": False, - "project_uuid": project.uuid}, + "project_id": project.uuid}, example=True) assert response.status == 201 assert response.json["name"] == "VM1" - assert response.json["project_uuid"] == project.uuid + assert response.json["project_id"] == project.uuid def test_vbox_get(server, project, vm): @@ -49,7 +49,7 @@ def test_vbox_get(server, project, vm): assert response.status == 200 assert response.route == "/virtualbox/{uuid}" assert response.json["name"] == "VMTEST" - assert response.json["project_uuid"] == project.uuid + assert response.json["project_id"] == project.uuid def test_vbox_start(server, vm): diff --git a/tests/api/test_vpcs.py b/tests/api/test_vpcs.py index 56c970a2..7304f143 100644 --- a/tests/api/test_vpcs.py +++ b/tests/api/test_vpcs.py @@ -23,17 +23,17 @@ from unittest.mock import patch @pytest.fixture(scope="module") def vm(server, project): - response = server.post("/vpcs", {"name": "PC TEST 1", "project_uuid": project.uuid}) + response = server.post("/vpcs", {"name": "PC TEST 1", "project_id": project.uuid}) assert response.status == 201 return response.json def test_vpcs_create(server, project): - response = server.post("/vpcs", {"name": "PC TEST 1", "project_uuid": project.uuid}, example=True) + response = server.post("/vpcs", {"name": "PC TEST 1", "project_id": project.uuid}, example=True) assert response.status == 201 assert response.route == "/vpcs" assert response.json["name"] == "PC TEST 1" - assert response.json["project_uuid"] == project.uuid + assert response.json["project_id"] == project.uuid assert response.json["script_file"] is None @@ -42,24 +42,24 @@ def test_vpcs_get(server, project, vm): assert response.status == 200 assert response.route == "/vpcs/{uuid}" assert response.json["name"] == "PC TEST 1" - assert response.json["project_uuid"] == project.uuid + assert response.json["project_id"] == project.uuid def test_vpcs_create_startup_script(server, project): - response = server.post("/vpcs", {"name": "PC TEST 1", "project_uuid": project.uuid, "startup_script": "ip 192.168.1.2\necho TEST"}) + response = server.post("/vpcs", {"name": "PC TEST 1", "project_id": project.uuid, "startup_script": "ip 192.168.1.2\necho TEST"}) assert response.status == 201 assert response.route == "/vpcs" assert response.json["name"] == "PC TEST 1" - assert response.json["project_uuid"] == project.uuid + assert response.json["project_id"] == project.uuid assert response.json["startup_script"] == "ip 192.168.1.2\necho TEST" def test_vpcs_create_port(server, project, free_console_port): - response = server.post("/vpcs", {"name": "PC TEST 1", "project_uuid": project.uuid, "console": free_console_port}) + response = server.post("/vpcs", {"name": "PC TEST 1", "project_id": project.uuid, "console": free_console_port}) assert response.status == 201 assert response.route == "/vpcs" assert response.json["name"] == "PC TEST 1" - assert response.json["project_uuid"] == project.uuid + assert response.json["project_id"] == project.uuid assert response.json["console"] == free_console_port