summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhongbo tian <hongbo.tianhongbo@huawei.com>2016-11-03 07:39:52 +0000
committerGerrit Code Review <gerrit@opnfv.org>2016-11-03 07:39:52 +0000
commitc1ba7e767e022cc3491dd3590f38f440edb2e637 (patch)
tree590a0b80b0ca53e922db3de957269f5e536c8328
parentfb1dc1f24bfb410683d344529163dfe1cc721a1d (diff)
parente96b958cb480463f29c237f8aace813e613c4a82 (diff)
Merge "Add more distro support when preparing environment"
-rw-r--r--dovetail/prepare_env.py40
1 files changed, 39 insertions, 1 deletions
diff --git a/dovetail/prepare_env.py b/dovetail/prepare_env.py
index 785d5c3d..3e4d6964 100644
--- a/dovetail/prepare_env.py
+++ b/dovetail/prepare_env.py
@@ -7,13 +7,51 @@
# http://www.apache.org/licenses/LICENSE-2.0
#
+import platform
import utils.dovetail_logger as dt_logger
import utils.dovetail_utils as dt_utils
+def get_os():
+ """Get distro name.
+
+ :returns: return distro name as a string
+ """
+ return platform.dist()[0]
+
+
+def get_install_bin(os):
+ """Get install command binary.
+
+ :returns: return install command according to distro
+ """
+ if os in ['centos', 'redhat']:
+ return 'yum'
+ elif os == 'fedora':
+ return 'dnf'
+ elif os == 'ubuntu':
+ return 'apt-get'
+ else:
+ return None
+
+
+def get_docker_pkgname(os):
+ """Get docker package name.
+
+ :returns: return docker package name according to distro
+ """
+ if os in ['centos', 'fedora', 'redhat']:
+ return 'docker'
+ elif os == 'ubuntu':
+ return 'docker.io'
+ else:
+ return None
+
logger = dt_logger.Logger('prepare_env.py').getLogger()
-cmd = "sudo apt-get -y install docker.io python-pip"
+os_name = get_os()
+cmd = "sudo %s -y install %s python-pip" \
+ % (get_install_bin(os_name), get_docker_pkgname(os_name))
dt_utils.exec_cmd(cmd, logger)
cmd = "sudo pip install click pyyaml jinja2"