[Kimchi-devel] [PATCH 4/6] Create VMs asynchronously: Backend
Christy Perez
christy at linux.vnet.ibm.com
Tue Apr 28 19:06:09 UTC 2015
Signed-off-by: Christy Perez <christy at linux.vnet.ibm.com>
---
src/kimchi/control/vms.py | 4 ++--
src/kimchi/model/vms.py | 27 ++++++++++++++++++++++++---
2 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/src/kimchi/control/vms.py b/src/kimchi/control/vms.py
index 6352a26..a40b56e 100644
--- a/src/kimchi/control/vms.py
+++ b/src/kimchi/control/vms.py
@@ -17,13 +17,13 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-from kimchi.control.base import Collection, Resource
+from kimchi.control.base import AsyncCollection, Resource
from kimchi.control.utils import internal_redirect, UrlSubNode
from kimchi.control.vm import sub_nodes
@UrlSubNode('vms', True)
-class VMs(Collection):
+class VMs(AsyncCollection):
def __init__(self, model):
super(VMs, self).__init__(model)
self.resource = VM
diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py
index 5f8c3da..9786063 100644
--- a/src/kimchi/model/vms.py
+++ b/src/kimchi/model/vms.py
@@ -79,9 +79,9 @@ def __init__(self, **kargs):
self.conn = kargs['conn']
self.objstore = kargs['objstore']
self.caps = CapabilitiesModel(**kargs)
+ self.task = TaskModel(**kargs)
def create(self, params):
- conn = self.conn.get()
t_name = template_name_from_uri(params['template'])
vm_uuid = str(uuid.uuid4())
vm_list = self.get_list()
@@ -102,7 +102,26 @@ def create(self, params):
raise InvalidOperation("KCHVM0005E")
t.validate()
+ taskid = add_task(u'/vms/%s' % name,
+ self._create_task, self.objstore,
+ {'vm_uuid': vm_uuid, 'template': t, 'name': name})
+
+ return self.task.lookup(taskid)
+
+ def _create_task(self, cb, params):
+ """
+ params: A dict with the following values:
+ - vm_uuid: The UUID of the VM being created
+ - template: The template being used to create the VM
+ - name: The name for the new VM
+ """
+
+ vm_uuid = params['vm_uuid']
+ t = params['template']
+ name = params['name']
+ conn = self.conn.get()
+ cb('Storing VM icon')
# Store the icon for displaying later
icon = t.info.get('icon')
if icon:
@@ -117,6 +136,7 @@ def create(self, params):
# If storagepool is SCSI, volumes will be LUNs and must be passed by
# the user from UI or manually.
+ cb('Provisioning storage for new VM')
vol_list = []
if t._get_storage_type() not in ["iscsi", "scsi"]:
vol_list = t.fork_vm_storage(vm_uuid)
@@ -128,6 +148,7 @@ def create(self, params):
graphics=graphics,
volumes=vol_list)
+ cb('Defining new VM')
try:
conn.defineXML(xml.encode('utf-8'))
except libvirt.libvirtError as e:
@@ -138,10 +159,10 @@ def create(self, params):
raise OperationFailed("KCHVM0007E", {'name': name,
'err': e.get_error_message()})
+ cb('Updating VM metadata')
VMModel.vm_update_os_metadata(VMModel.get_vm(name, self.conn), t.info,
self.caps.metadata_support)
-
- return name
+ cb('OK', True)
def get_list(self):
return VMsModel.get_vms(self.conn)
--
2.1.0
More information about the Kimchi-devel
mailing list