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

lvroyce at linux.vnet.ibm.com lvroyce at linux.vnet.ibm.com
Thu Sep 4 09:25: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 | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/kimchi/model/storagevolumes.py b/src/kimchi/model/storagevolumes.py
index 91abc81..a6c7c9f 100644
--- a/src/kimchi/model/storagevolumes.py
+++ b/src/kimchi/model/storagevolumes.py
@@ -73,13 +73,19 @@ class StorageVolumesModel(object):
             raise InvalidParameter('KCHVOL0001E', {'name': params['name']})
 
         upload_file = params['file']
+        f_len = upload_file.fp.length
+        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('%s/%s' % (f_len, size), True)
             f.close()
         except Exception as e:
             raise OperationFailed('KCHVOL0007E',
@@ -88,9 +94,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