1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-25 16:28:11 +00:00

Reload VM

This commit is contained in:
Julien Duponchelle 2016-04-18 16:57:02 +02:00
parent b01d974f91
commit 6c11ad5fa6
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
4 changed files with 45 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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