diff --git a/gns3server/controller/vm.py b/gns3server/controller/vm.py index 23ca7840..79b4b33c 100644 --- a/gns3server/controller/vm.py +++ b/gns3server/controller/vm.py @@ -131,6 +131,13 @@ class VM: """ yield from self.post("/suspend") + @asyncio.coroutine + def reload(self): + """ + Suspend a VM + """ + yield from self.post("/suspend") + @asyncio.coroutine def post(self, path, data=None): """ diff --git a/gns3server/handlers/api/controller/vm_handler.py b/gns3server/handlers/api/controller/vm_handler.py index dd259cbc..5bb4fac5 100644 --- a/gns3server/handlers/api/controller/vm_handler.py +++ b/gns3server/handlers/api/controller/vm_handler.py @@ -110,3 +110,24 @@ class VMHandler: yield from vm.suspend() response.set_status(201) response.json(vm) + + @classmethod + @Route.post( + r"/projects/{project_id}/vms/{vm_id}/reload", + parameters={ + "project_id": "UUID for the project", + "vm_id": "UUID for the VM" + }, + status_codes={ + 201: "Instance created", + 400: "Invalid request" + }, + description="Reload a VM instance", + output=VM_OBJECT_SCHEMA) + def reload(request, response): + + project = Controller.instance().getProject(request.match_info["project_id"]) + vm = project.getVM(request.match_info["vm_id"]) + yield from vm.reload() + response.set_status(201) + response.json(vm) diff --git a/tests/controller/test_vm.py b/tests/controller/test_vm.py index d36ccaf9..645cb010 100644 --- a/tests/controller/test_vm.py +++ b/tests/controller/test_vm.py @@ -110,6 +110,14 @@ def test_suspend(vm, compute, project, async_run): compute.post.assert_called_with("/projects/{}/vpcs/vms/{}/suspend".format(vm.project.id, vm.id)) +def test_reload(vm, compute, project, async_run): + + compute.post = AsyncioMagicMock() + + async_run(vm.reload()) + compute.post.assert_called_with("/projects/{}/vpcs/vms/{}/reload".format(vm.project.id, vm.id)) + + def test_create_without_console(vm, compute, project, async_run): """ None properties should be send. Because it can mean the emulator doesn"t support it diff --git a/tests/handlers/api/controller/test_vm.py b/tests/handlers/api/controller/test_vm.py index ead90f73..3dd314a8 100644 --- a/tests/handlers/api/controller/test_vm.py +++ b/tests/handlers/api/controller/test_vm.py @@ -97,3 +97,12 @@ def test_suspend_vm(http_controller, tmpdir, project, compute, vm): response = http_controller.post("/projects/{}/vms/{}/suspend".format(project.id, vm.id), example=True) assert response.status == 201 assert response.json["name"] == vm.name + + +def test_reload_vm(http_controller, tmpdir, project, compute, vm): + response = MagicMock() + compute.post = AsyncioMagicMock() + + response = http_controller.post("/projects/{}/vms/{}/reload".format(project.id, vm.id), example=True) + assert response.status == 201 + assert response.json["name"] == vm.name