Creating a new storage volume may take a long time, especially for the
download and upload features which will be implemented soon. Instead of
waiting for the create operation to finish, return a Task so the client
can fetch its status later.
Use an AsyncTask to create new storage volumes.
Signed-off-by: Crístian Viana <vianac(a)linux.vnet.ibm.com>
---
src/kimchi/control/storagevolumes.py | 4 ++--
src/kimchi/model/storagevolumes.py | 3 +++
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/control/storagevolumes.py b/src/kimchi/control/storagevolumes.py
index 327bf75..79170ee 100644
--- a/src/kimchi/control/storagevolumes.py
+++ b/src/kimchi/control/storagevolumes.py
@@ -18,11 +18,11 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import kimchi.template
-from kimchi.control.base import Collection, Resource
+from kimchi.control.base import AsyncCollection, Collection, Resource
from kimchi.control.utils import get_class_name, model_fn
-class StorageVolumes(Collection):
+class StorageVolumes(AsyncCollection):
def __init__(self, model, pool):
super(StorageVolumes, self).__init__(model)
self.resource = StorageVolume
diff --git a/src/kimchi/model/storagevolumes.py b/src/kimchi/model/storagevolumes.py
index 2c3e7a8..bd9dbc9 100644
--- a/src/kimchi/model/storagevolumes.py
+++ b/src/kimchi/model/storagevolumes.py
@@ -28,6 +28,7 @@ from kimchi.exception import MissingParameter, NotFoundError,
OperationFailed
from kimchi.isoinfo import IsoImage
from kimchi.model.storagepools import StoragePoolModel
from kimchi.utils import kimchi_log
+from kimchi.model.tasks import TaskModel
from kimchi.model.vms import VMsModel, VMModel
from kimchi.vmdisks import get_vm_disk, get_vm_disk_list
@@ -42,6 +43,7 @@ class StorageVolumesModel(object):
def __init__(self, **kargs):
self.conn = kargs['conn']
self.objstore = kargs['objstore']
+ self.task = TaskModel(**kargs)
def create(self, pool_name, params):
vol_source = ['file', 'url', 'capacity']
@@ -58,6 +60,7 @@ class StorageVolumesModel(object):
return create_func(pool_name, params)
+ # TODO: this function must be updated to return a Task
def _create_volume_with_capacity(self, pool_name, params):
vol_xml = """
<volume>
--
1.9.3