1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-13 20:08:55 +00:00

APi for listing VM in controller

This commit is contained in:
Julien Duponchelle 2016-04-20 14:38:14 +02:00
parent c8c61f2ae8
commit f6593663b5
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
6 changed files with 53 additions and 2 deletions

View File

@ -58,7 +58,7 @@ class ComputeHandler:
def list(request, response):
controller = Controller.instance()
response.json([ c for c in controller.computes.values() ])
response.json([c for c in controller.computes.values()])
@classmethod
@Route.post(

View File

@ -51,6 +51,17 @@ class ProjectHandler:
response.set_status(201)
response.json(project)
@classmethod
@Route.get(
r"/projects",
description="List projects",
status_codes={
200: "List of projects",
})
def list_projects(request, response):
controller = Controller.instance()
response.json([ p for p in controller.projects.values() ])
@classmethod
@Route.get(
r"/projects/{project_id}",

View File

@ -48,6 +48,22 @@ class VMHandler:
response.set_status(201)
response.json(vm)
@classmethod
@Route.get(
r"/projects/{project_id}/vms",
parameters={
"project_id": "UUID for the project"
},
status_codes={
200: "List of VMS",
},
description="List VMs of a project")
def list_vms(request, response):
controller = Controller.instance()
project = controller.getProject(request.match_info["project_id"])
response.json([ v for v in project.vms.values() ])
@classmethod
@Route.put(
r"/projects/{project_id}/vms/{vm_id}",

View File

@ -63,4 +63,3 @@ def test_compute_list(http_controller, controller):
'user': 'julien'
}
]

View File

@ -75,6 +75,13 @@ def test_create_project_with_uuid(http_controller):
assert response.json["name"] == "test"
def test_list_projects(http_controller, tmpdir):
http_controller.post("/projects", {"name": "test", "path": str(tmpdir), "project_id": "00010203-0405-0607-0809-0a0b0c0d0e0f"})
response = http_controller.get("/projects", example=True)
assert response.status == 200
projects = response.json
assert projects[0]["name"] == "test"
def test_commit_project(http_controller, project):
with asyncio_patch("gns3server.controller.project.Project.commit", return_value=True) as mock:
response = http_controller.post("/projects/{project_id}/commit".format(project_id=project.id), example=True)

View File

@ -72,6 +72,24 @@ def test_create_vm(http_controller, tmpdir, project, compute):
assert "name" not in response.json["properties"]
def test_list_vm(http_controller, tmpdir, project, compute):
response = MagicMock()
response.json = {"console": 2048}
compute.post = AsyncioMagicMock(return_value=response)
response = http_controller.post("/projects/{}/vms".format(project.id), {
"name": "test",
"vm_type": "vpcs",
"compute_id": "example.com",
"properties": {
"startup_script": "echo test"
}
})
response = http_controller.get("/projects/{}/vms".format(project.id), example=True)
assert response.status == 200
assert response.json[0]["name"] == "test"
def test_update_vm(http_controller, tmpdir, project, compute, vm):
response = MagicMock()
response.json = {"console": 2048}