diff options
author | hongbo tian <hongbo.tianhongbo@huawei.com> | 2017-05-11 02:03:33 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-05-11 02:03:33 +0000 |
commit | 4c254bc9dc3ea11daf22d408f331930b8e063227 (patch) | |
tree | 55d23a8f0ac008b2d3ad8064180a37dd4e096b89 | |
parent | e8e815b8b288437e058d8fa4acda22b71726fe34 (diff) | |
parent | c9df73bbec1a69abc04d0a4acac75aefd5842b0f (diff) |
Merge "store/load offline docker images"
-rw-r--r-- | dovetail/utils/offline/config.yaml | 22 | ||||
-rwxr-xr-x | dovetail/utils/offline/download.py | 47 | ||||
-rwxr-xr-x | dovetail/utils/offline/load.py | 35 |
3 files changed, 104 insertions, 0 deletions
diff --git a/dovetail/utils/offline/config.yaml b/dovetail/utils/offline/config.yaml new file mode 100644 index 00000000..ced42296 --- /dev/null +++ b/dovetail/utils/offline/config.yaml @@ -0,0 +1,22 @@ +--- +docker_images: + dovetail: + domain: opnfv + tag: latest + store_name: image_dovetail.docker + functest: + domain: opnfv + tag: latest + store_name: image_functest.docker + yardstick: + domain: opnfv + tag: latest + store_name: image_yardstick.docker + testapi: + domain: opnfv + tag: latest + store_name: image_testapi.docker + mongo: + tag: 3.5 + store_name: image_mongo.docker +docker_save_path: /home/opnfv/dovetail/results/ diff --git a/dovetail/utils/offline/download.py b/dovetail/utils/offline/download.py new file mode 100755 index 00000000..cda4ecca --- /dev/null +++ b/dovetail/utils/offline/download.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python + +import os +import yaml + +import dovetail.utils.dovetail_utils as dt_utils + + +class download(object): + + def __init__(self): + self.curr_path = os.path.dirname(os.path.abspath(__file__)) + with open(os.path.join(self.curr_path, 'config.yaml')) as f: + self.config = yaml.safe_load(f) + + def main(self): + keys = self.config.keys() + if 'docker_save_path' in keys: + save_path = self.config['docker_save_path'] + else: + save_path = self.curr_path + print "save files to path %s" % save_path + if 'docker_images' in keys: + for key, value in self.config['docker_images'].items(): + if value is not None: + tag = str(self.config['docker_images'][key]['tag']) + if 'domain' in self.config['docker_images'][key]: + domain = self.config['docker_images'][key]['domain'] + image_name = ''.join([domain, '/', key, ':', tag]) + else: + image_name = ''.join([key, ':', tag]) + cmd = 'sudo docker pull %s' % image_name + dt_utils.exec_cmd(cmd) + if not os.path.exists(save_path): + os.makedirs(save_path) + StoreName = self.config['docker_images'][key]['store_name'] + image_save_path = ''.join([save_path, StoreName]) + cmd = 'sudo docker save -o %s %s' % \ + (image_save_path, image_name) + dt_utils.exec_cmd(cmd) + cmd = 'sudo chmod og+rw %s' % image_save_path + dt_utils.exec_cmd(cmd) + + +if __name__ == '__main__': + download = download() + download.main() diff --git a/dovetail/utils/offline/load.py b/dovetail/utils/offline/load.py new file mode 100755 index 00000000..9ddf6596 --- /dev/null +++ b/dovetail/utils/offline/load.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +import os +import yaml + +import dovetail.utils.dovetail_utils as dt_utils + + +class load(object): + def __init__(self): + self.curr_path = os.path.dirname(os.path.abspath(__file__)) + with open(os.path.join(self.curr_path, 'config.yaml')) as f: + self.config = yaml.safe_load(f) + + def main(self): + keys = self.config.keys() + if 'docker_save_path' in keys: + save_path = self.config['docker_save_path'] + else: + save_path = self.curr_path + if 'docker_images' in keys: + for key, value in self.config['docker_images'].items(): + if value is not None: + name = self.config['docker_images'][key]['store_name'] + image_save_path = ''.join([save_path, name]) + if os.path.isfile(image_save_path): + cmd = 'sudo docker load -i %s' % (image_save_path) + dt_utils.exec_cmd(cmd) + else: + print "file %s not exists" % image_save_path + + +if __name__ == '__main__': + load = load() + load.main() |