diff options
author | Bin Sun <bins@vmware.com> | 2018-03-26 10:21:29 +0800 |
---|---|---|
committer | Bin Sun <bins@vmware.com> | 2018-03-26 10:37:11 +0800 |
commit | cc17e08c2d68899c2356b8ae6d7e9b89cb371b4b (patch) | |
tree | f359939be24aae0e8cd6a80109bde8a56e9ebe33 /vio | |
parent | dab42d91cc09da3b4193ee32853e15fbaef7b61b (diff) |
using multi thread for uploading images
Change-Id: I6712db3fadce8238106252b1f29383f7810236e9
Issue-ID: MULTICLOUD-155
Signed-off-by: Bin Sun <bins@vmware.com>
Diffstat (limited to 'vio')
-rw-r--r-- | vio/vio/pub/vim/vimapi/glance/OperateImage.py | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/vio/vio/pub/vim/vimapi/glance/OperateImage.py b/vio/vio/pub/vim/vimapi/glance/OperateImage.py index b26a184..ddb7ba2 100644 --- a/vio/vio/pub/vim/vimapi/glance/OperateImage.py +++ b/vio/vio/pub/vim/vimapi/glance/OperateImage.py @@ -15,14 +15,12 @@ import logging import threading import urllib2 - from vio.pub.msapi import extsys from vio.pub.vim.vimapi.baseclient import baseclient from vio.swagger import image_utils logger = logging.getLogger(__name__) - running_threads = {} running_thread_lock = threading.Lock() @@ -108,10 +106,47 @@ class OperateImage(baseclient): image = self.glance(self.param).create_image_file(file_name, image_type) - self.glance(self.param).upload_image(open(file_dest), image) + upload_image_file_thread = imagefileThread(vimid, tenantid, + image, file_dest) + logger.debug("launch thread to upload image: %s" % image.id) + running_thread_lock.acquire() + running_threads[image.id] = image.id + running_thread_lock.release() + try: + upload_image_file_thread.start() + except Exception: + pass return image def download_vim_image(self, image): image_data = self.glance(self.param).download_image(image) return image_data + + +class imagefileThread(threading.Thread): + def __init__(self, vimid, tenantid, image, file_dest): + + threading.Thread.__init__(self) + self.imageid = image.id + self.vimid = vimid + self.tenantid = tenantid + self.image = image + self.file_dest = file_dest + + def run(self): + + logger.debug("start imagethread") + self.transfer_image_file(self.vimid, self.tenantid, + self.image, self.file_dest) + running_thread_lock.acquire() + running_threads.pop(self.imageid) + running_thread_lock.release() + + def transfer_image_file(self, vimid, tenantid, image, file_dest): + logger.debug("Image----transfer_image") + vim_info = extsys.get_vim_by_id(vimid) + vim_info['tenant'] = tenantid + param = image_utils.sdk_param_formatter(vim_info) + client = baseclient() + client.glance(param).upload_image(open(file_dest), image) |