[Kimchi-devel] [PATCHv3 6/7] Storage volume upload: Adding progress to task message

lvroyce0210 at gmail.com lvroyce0210 at gmail.com
Wed Sep 3 11:58:52 UTC 2014


From: Royce Lv <lvroyce at linux.vnet.ibm.com>

Periodically update current written bytes to task message
so that UI can query the latest progress of volume uploading.

Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
---
 src/kimchi/model/storagevolumes.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/kimchi/model/storagevolumes.py b/src/kimchi/model/storagevolumes.py
index 91abc81..7794b32 100644
--- a/src/kimchi/model/storagevolumes.py
+++ b/src/kimchi/model/storagevolumes.py
@@ -73,13 +73,18 @@ class StorageVolumesModel(object):
             raise InvalidParameter('KCHVOL0001E', {'name': params['name']})
 
         upload_file = params['file']
+        pool = StoragePoolModel.get_storagepool(pool_name, self.conn)
         try:
+            size = 0
             f = open(file_path, 'wb')
+            pool.refresh()
             while True:
                 data = upload_file.file.read(8192)
                 if not data:
                         break
+                size += len(data)
                 f.write(data)
+                cb(size, True)
             f.close()
         except Exception as e:
             raise OperationFailed('KCHVOL0007E',
@@ -88,9 +93,7 @@ class StorageVolumesModel(object):
                                    'err': e.message})
 
         # Refresh to make sure volume can be found in following lookup
-        pool = StoragePoolModel.get_storagepool(pool_name, self.conn)
         pool.refresh()
-        cb('', True)
 
     def _create_volume_with_capacity(self, cb, params):
         pool_name = params.pop('pool')
-- 
1.8.3.2




More information about the Kimchi-devel mailing list