1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-29 02:08:10 +00:00

Use project_id instead of project_uuid for the API.

This commit is contained in:
Jeremy 2015-02-03 18:40:13 -07:00
parent d2699f051d
commit 59c82e26df
8 changed files with 30 additions and 30 deletions

View File

@ -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"))

View File

@ -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):
"""

View File

@ -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,

View File

@ -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}

View File

@ -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"]
}

View File

@ -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"]
}

View File

@ -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):

View File

@ -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