From: Royce Lv <lvroyce(a)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(a)linux.vnet.ibm.com>
Signed-off-by: Crístian Viana <vianac(a)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