Signed-off-by: Christy Perez <christy(a)linux.vnet.ibm.com>
---
src/kimchi/control/vms.py | 4 ++--
src/kimchi/model/vms.py | 28 +++++++++++++++++++++++++---
2 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/src/kimchi/control/vms.py b/src/kimchi/control/vms.py
index 5068b7c..8a31dc0 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 1ae841d..e5b0aa7 100644
--- a/src/kimchi/model/vms.py
+++ b/src/kimchi/model/vms.py
@@ -80,6 +80,7 @@ def __init__(self, **kargs):
self.conn = kargs['conn']
self.objstore = kargs['objstore']
self.caps = CapabilitiesModel(**kargs)
+ self.task = TaskModel(**kargs)
@staticmethod
def _update_guests_stats(names, conn):
@@ -183,7 +184,6 @@ def _get_disk_io_rate(vm_uuid, dom, seconds):
'diskWrKB': diskWrKB})
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()
@@ -205,6 +205,26 @@ def create(self, params):
t.validate()
+ taskid = add_task(u'/vms/%s/create' % 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:
@@ -219,6 +239,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)
@@ -231,6 +252,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:
@@ -241,10 +263,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