diff options
author | zhang ab <zhanganbing@chinamobile.com> | 2018-03-26 05:56:18 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-03-26 05:56:18 +0000 |
commit | 5b3243c40df8e83a56205c8b835aed762eba2cfa (patch) | |
tree | aa50472443fc963c7c2dc098be3a8a3517541f34 | |
parent | 5d22436abc1ca86f2fa419483a0e6464e890b90a (diff) | |
parent | cc17e08c2d68899c2356b8ae6d7e9b89cb371b4b (diff) |
Merge "using multi thread for uploading images"
-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) |