diff options
author | chenjiankun <chenjiankun1@huawei.com> | 2017-07-21 02:09:03 +0000 |
---|---|---|
committer | chenjiankun <chenjiankun1@huawei.com> | 2017-07-21 02:09:03 +0000 |
commit | f4319e7750c5e444c4a5d02df32bcbab372c6dfa (patch) | |
tree | f1d9233caaa0575da3d9bd37f473f7ed80b52c9c /api/resources/v2/images.py | |
parent | acc000cff316fa9883217121a3c30b0e2145a363 (diff) |
Add API(v2) to load images
JIRA: YARDSTICK-751
API: /api/v2/yardstick/images/action
METHOD: POST
PARAMS:
{
'action': 'load_image'
}
Change-Id: I9554f35c679ae2a861c7922080aa54a1ffc5bac7
Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
Diffstat (limited to 'api/resources/v2/images.py')
-rw-r--r-- | api/resources/v2/images.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/api/resources/v2/images.py b/api/resources/v2/images.py new file mode 100644 index 000000000..dc996742f --- /dev/null +++ b/api/resources/v2/images.py @@ -0,0 +1,44 @@ +import logging +import subprocess +import threading + +from api import ApiResource +from yardstick.common.utils import result_handler +from yardstick.common.utils import source_env +from yardstick.common import constants as consts + +LOG = logging.getLogger(__name__) +LOG.setLevel(logging.DEBUG) + + +class V2Images(ApiResource): + + def post(self): + return self._dispatch_post() + + def load_image(self, args): + thread = threading.Thread(target=self._load_images) + thread.start() + return result_handler(consts.API_SUCCESS, {}) + + def _load_images(self): + LOG.info('source openrc') + source_env(consts.OPENRC) + + LOG.info('clean images') + cmd = [consts.CLEAN_IMAGES_SCRIPT] + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, + cwd=consts.REPOS_DIR) + _, err = p.communicate() + if p.returncode != 0: + LOG.error('clean image failed: %s', err) + + LOG.info('load images') + cmd = [consts.LOAD_IMAGES_SCRIPT] + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, + cwd=consts.REPOS_DIR) + _, err = p.communicate() + if p.returncode != 0: + LOG.error('load image failed: %s', err) + + LOG.info('Done') |