/
install.py
144 lines (123 loc) · 4.91 KB
/
install.py
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import os
import re
import copy
import tempfile
from decimal import *
from fabfile.config import *
from fabfile.utils.fabos import *
from fabfile.tasks.install import yum_install, apt_install
def apt_install_overwrite(debs):
cmd = 'DEBIAN_FRONTEND=noninteractive apt-get -y --force-yes --allow-unauthenticated -o Dpkg::Options::="--force-overwrite" -o Dpkg::Options::="--force-confnew" install '
if detect_ostype() in ['ubuntu']:
for deb in debs:
sudo(cmd + deb)
@task
@parallel(pool_size=20)
@roles('all')
def install_storage_pkg_all(pkg):
"""Installs any rpm/deb in storage-master/storage-compute nodes."""
execute('install_storage_pkg_node', pkg, env.host_string)
@task
def install_storage_pkg_node(pkg, *args):
"""Installs any rpm/deb in storage-master/storage-compute node."""
for host_string in args:
with settings(host_string=host_string, warn_only=True):
build = get_build('contrail-storage-packages')
if build and build in pkg:
print "Package %s already installed in the node(%s)." % (pkg, host_string)
continue
pkg_name = os.path.basename(pkg)
temp_dir= tempfile.mkdtemp()
sudo('mkdir -p %s' % temp_dir)
put(pkg, '%s/%s' % (temp_dir, pkg_name), use_sudo=True)
if pkg.endswith('.rpm'):
sudo("yum --disablerepo=* -y localinstall %s/%s" % (temp_dir, pkg_name))
elif pkg.endswith('.deb'):
sudo("dpkg -i %s/%s" % (temp_dir, pkg_name))
@task
@EXECUTE_TASK
@roles('storage-master')
def install_storage_master():
"""Installs storage pkgs in all nodes defined in storage-master role."""
execute("install_storage_master_node", env.host_string)
@task
def install_storage_master_node(*args):
"""Installs storage pkgs in one or list of nodes. USAGE:fab install_openstack_storage_node:user@1.1.1.1,user@2.2.2.2"""
for host_string in args:
with settings(host_string=host_string):
pkg = ['contrail-storage']
if detect_ostype() == 'ubuntu':
apt_install_overwrite(pkg)
else:
yum_install(pkg)
@task
@EXECUTE_TASK
@roles('webui')
def install_storage_webui():
"""Installs storage webui pkgs in all nodes defined in webui role."""
if env.roledefs['webui']:
execute("install_storage_webui_node", env.host_string)
@task
def install_storage_webui_node(*args):
"""Installs storage pkgs in one or list of nodes. USAGE:fab install_storage_webui:user@1.1.1.1,user@2.2.2.2"""
for host_string in args:
with settings(host_string=host_string):
pkg = ['contrail-web-storage']
if detect_ostype() == 'ubuntu':
apt_install_overwrite(pkg)
else:
yum_install(pkg)
@task
@EXECUTE_TASK
@roles('storage-compute')
def install_storage_compute():
"""Installs storage pkgs in all nodes defined in storage-compute role."""
execute("install_storage_compute_node", env.host_string)
@task
def install_storage_compute_node(*args):
"""Installs storage pkgs in one or list of nodes. USAGE:fab install_compute_storage_node:user@1.1.1.1,user@2.2.2.2"""
for host_string in args:
with settings(host_string=host_string):
pkg = ['contrail-storage']
if detect_ostype() == 'ubuntu':
apt_install_overwrite(pkg)
else:
yum_install(pkg)
@task
@EXECUTE_TASK
@roles('all')
def create_storage_repo():
execute('create_storage_repo_node', env.host_string)
@task
def create_storage_repo_node(*args):
for host_string in args:
with settings(host_string=host_string, warn_only=True):
sudo("sudo /opt/contrail/contrail_packages/setup_storage.sh")
@roles('build')
@task
def install_storage():
"""Installs required storage packages in nodes as per the role definition.
"""
execute(create_storage_repo)
execute(install_storage_master)
execute(install_storage_compute)
execute(install_storage_webui)
@task
@roles('build')
def upgrade_storage(from_rel, pkg):
"""upgrades contrail-storage pkgs in all nodes."""
from_rel = get_release('contrail-storage-packages')
to_rel = sudo('dpkg --info %s |grep Version: | cut -d\':\' -f 2'
%(pkg)).split('-')[0]
from_build = get_build('contrail-storage-packages').split('~')[0]
to_build = sudo('dpkg --info %s |grep Version: | cut -d\':\' -f 2'
%(pkg)).split('-')[1].split('~')[0]
if (Decimal(to_rel) > Decimal(from_rel)) or \
(Decimal(to_rel) == Decimal(from_rel) and \
Decimal(to_build) > Decimal(from_build)):
execute('install_storage_pkg_all', pkg)
execute('install_storage')
execute('setup_upgrade_storage')
else:
raise RuntimeError("Downgrade not supported. Current version - %s~%s, New version - %s~%s"
%(from_rel, from_build, to_rel, to_build))