[Kimchi-devel] [PATCH v2 3/3] storagevolume: Add download progress to task
Crístian Viana
vianac at linux.vnet.ibm.com
Thu Sep 4 13:46:56 UTC 2014
The download operation can take a long time, so it's nice to have some
way to track its current progress.
Update the task's message with the number of bytes downloaded. The
format is "<bytes downloaded>/<total bytes>". If the number of bytes
cannot be read from the remote URL, <total bytes> will be "-".
Signed-off-by: Crístian Viana <vianac at linux.vnet.ibm.com>
---
src/kimchi/model/storagevolumes.py | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/kimchi/model/storagevolumes.py b/src/kimchi/model/storagevolumes.py
index fac34d5..a1c8c9a 100644
--- a/src/kimchi/model/storagevolumes.py
+++ b/src/kimchi/model/storagevolumes.py
@@ -138,6 +138,9 @@ class StorageVolumesModel(object):
with contextlib.closing(urllib2.urlopen(url)) as response,\
open(file_path, 'w') as volume_file:
+ remote_size = response.info().getheader('Content-Length', '-')
+ downloaded_size = 0
+
try:
while True:
chunk_data = response.read(DOWNLOAD_CHUNK_SIZE)
@@ -145,6 +148,8 @@ class StorageVolumesModel(object):
break
volume_file.write(chunk_data)
+ downloaded_size += len(chunk_data)
+ cb('%s/%s' % (downloaded_size, remote_size))
except Exception, e:
raise OperationFailed('KCHVOL0007E', {'name': name,
'pool': pool_name,
--
1.9.3
More information about the Kimchi-devel
mailing list