API for creating a VM

This commit is contained in:
Julien Duponchelle committed 2016-03-10 21:51:29 +01:00
1 parent 65de1b7b5e
commit 4326d412f9
14 files changed
+405 -48

No files matched your search

+17
View File
@@ -18,6 +18,8 @@
import asyncio
from uuid import UUID, uuid4
from .vm import VM
class Project:
"""
@@ -42,6 +44,7 @@ class Project:
self._path = path
self._temporary = temporary
self._hypervisors = set()
self._vms = {}
@property
def name(self):
@@ -64,6 +67,20 @@ class Project:
self._hypervisors.add(hypervisor)
yield from hypervisor.post("/projects", self)
@asyncio.coroutine
def addVM(self, hypervisor, vm_id, **kwargs):
"""
Create a vm or return an existing vm
:param kwargs: See the documentation of VM
"""
if vm_id not in self._vms:
vm = VM(self, hypervisor, vm_id=vm_id, **kwargs)
yield from vm.create()
self._vms[vm.id] = vm
return vm
return self._vms[vm_id]
@asyncio.coroutine
def close(self):
for hypervisor in self._hypervisors: