store/load offline docker images 27/34427/2
authorMatthewLi <matthew.lijun@huawei.com>
Mon, 8 May 2017 09:28:15 +0000 (05:28 -0400)
committerMatthewLi <matthew.lijun@huawei.com>
Mon, 8 May 2017 10:34:51 +0000 (06:34 -0400)
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>
dovetail/utils/offline/config.yaml [new file with mode: 0644]
dovetail/utils/offline/download.py [new file with mode: 0755]
dovetail/utils/offline/load.py [new file with mode: 0755]

diff --git a/dovetail/utils/offline/config.yaml b/dovetail/utils/offline/config.yaml
new file mode 100644 (file)
index 0000000..ced4229
--- /dev/null
@@ -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 (executable)
index 0000000..cda4ecc
--- /dev/null
@@ -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 (executable)
index 0000000..9ddf659
--- /dev/null
@@ -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()