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

Crístian Viana vianac at linux.vnet.ibm.com
Fri Sep 5 16:44:55 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>
Signed-off-by: Crístian Viana <vianac at linux.vnet.ibm.com>
---
 src/kimchi/model/storagevolumes.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/kimchi/model/storagevolumes.py b/src/kimchi/model/storagevolumes.py
index 7a188d2..ef8e684 100644
--- a/src/kimchi/model/storagevolumes.py
+++ b/src/kimchi/model/storagevolumes.py
@@ -92,13 +92,17 @@ class StorageVolumesModel(object):
             raise InvalidParameter('KCHVOL0001E', {'name': params['name']})
 
         upload_file = params['file']
+        f_len = upload_file.fp.length
         try:
+            size = 0
             with open(file_path, 'wb') as f:
                 while True:
                     data = upload_file.file.read(8192)
                     if not data:
                         break
+                    size += len(data)
                     f.write(data)
+                    cb('%s/%s' % (size, f_len))
         except Exception as e:
             raise OperationFailed('KCHVOL0007E',
                                   {'name': params['name'],
-- 
1.9.3




More information about the Kimchi-devel mailing list