summaryrefslogtreecommitdiffstats
path: root/dovetail/utils
diff options
context:
space:
mode:
authorMatthewLi <matthew.lijun@huawei.com>2017-05-08 05:28:15 -0400
committerMatthewLi <matthew.lijun@huawei.com>2017-05-08 06:34:51 -0400
commitc9df73bbec1a69abc04d0a4acac75aefd5842b0f (patch)
treeabbed115131b17388949b7c60d31f5c2e0275f43 /dovetail/utils
parentb878b9407ecf605eb57a5a1c53c30a0d90da5ca7 (diff)
store/load offline docker images
JIRA: DOVETAIL-423 usage: 1.cd ${DOVETAIL_HOME}/dovetail/utils/offline 2.edit config.yaml as needed 3.on onsite host, <python download.py> --> save docker images to defined path 4.on offline host, <python load.py> ---> load docker images to offline env 5.this can be easily extended to other images beside docker images Change-Id: I97d843e154ecf8d66cafb9ea9594fe73343ee591 Signed-off-by: MatthewLi <matthew.lijun@huawei.com>
Diffstat (limited to 'dovetail/utils')
-rw-r--r--dovetail/utils/offline/config.yaml22
-rwxr-xr-xdovetail/utils/offline/download.py47
-rwxr-xr-xdovetail/utils/offline/load.py35
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()