/start /stop and /suspend API for VM via container

This commit is contained in:
Julien Duponchelle committed 2016-04-12 18:02:36 +02:00
1 parent ad7ca86f32
commit 2055cdea5e
5 files changed
+144 -1

No files matched your search

+21
View File
@@ -110,6 +110,27 @@ class VM:
else:
self._properties[key] = value
@asyncio.coroutine
def start(self):
"""
Start a VM
"""
yield from self._hypervisor.post("/projects/{}/{}/vms/{}/start".format(self._project.id, self._vm_type, self._id))
@asyncio.coroutine
def stop(self):
"""
Stop a VM
"""
yield from self._hypervisor.post("/projects/{}/{}/vms/{}/stop".format(self._project.id, self._vm_type, self._id))
@asyncio.coroutine
def suspend(self):
"""
Suspend a VM
"""
yield from self._hypervisor.post("/projects/{}/{}/vms/{}/suspend".format(self._project.id, self._vm_type, self._id))
@asyncio.coroutine
def post(self, path, data={}):
"""
@@ -47,3 +47,66 @@ class VMHandler:
vm = yield from project.addVM(hypervisor, request.json.pop("vm_id", None), **request.json)
response.set_status(201)
response.json(vm)
@classmethod
@Route.post(
r"/projects/{project_id}/vms/{vm_id}/start",
parameters={
"project_id": "UUID for the project",
"vm_id": "UUID for the VM"
},
status_codes={
201: "Instance created",
400: "Invalid request"
},
description="Start a VM instance",
output=VM_OBJECT_SCHEMA)
def start(request, response):
project = Controller.instance().getProject(request.match_info["project_id"])
vm = project.getVM(request.match_info["vm_id"])
yield from vm.start()
response.set_status(201)
response.json(vm)
@classmethod
@Route.post(
r"/projects/{project_id}/vms/{vm_id}/stop",
parameters={
"project_id": "UUID for the project",
"vm_id": "UUID for the VM"
},
status_codes={
201: "Instance created",
400: "Invalid request"
},
description="Start a VM instance",
output=VM_OBJECT_SCHEMA)
def stop(request, response):
project = Controller.instance().getProject(request.match_info["project_id"])
vm = project.getVM(request.match_info["vm_id"])
yield from vm.stop()
response.set_status(201)
response.json(vm)
@classmethod
@Route.post(
r"/projects/{project_id}/vms/{vm_id}/suspend",
parameters={
"project_id": "UUID for the project",
"vm_id": "UUID for the VM"
},
status_codes={
201: "Instance created",
400: "Invalid request"
},
description="Start a VM instance",
output=VM_OBJECT_SCHEMA)
def suspend(request, response):
project = Controller.instance().getProject(request.match_info["project_id"])
vm = project.getVM(request.match_info["vm_id"])
yield from vm.suspend()
response.set_status(201)
response.json(vm)