summaryrefslogtreecommitdiffstats
path: root/dovetail/prepare_env.py
blob: 3ddf75bc5703e023e8de371afed8d98f9131fc0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
#
# grakiss.wanglei@huawei.com
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
#

import platform

import utils.dovetail_utils as dt_utils


def get_os_lower():
    """Get distro name.

    :returns: return distro name as a string
    """
    platform_os = platform.dist()[0]
    return platform_os.lower()


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


def main():
    """Dovetail prepare env main"""

    os_name = get_os_lower()
    cmd = "sudo %s -y install %s python-pip" \
        % (get_install_bin(os_name), get_docker_pkgname(os_name))
    dt_utils.exec_cmd(cmd)

    cmd = "sudo pip install click pyyaml jinja2"
    dt_utils.exec_cmd(cmd)


if __name__ == '__main__':
    main()