This repository has been archived by the owner on Apr 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 100
/
vsm-controller.changed
executable file
·266 lines (230 loc) · 7.54 KB
/
vsm-controller.changed
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#!/bin/bash
# Copyright 2014 Intel Corporation, All Rights Reserved.
# Licensed under the Apache License, Version 2.0 (the"License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
set -e
TOPDIR=$(cd $(dirname "$0") && pwd)
TEMP=`mktemp`; rm -rfv $TEMP >/dev/null; mkdir -p $TEMP;
#---------------------------------------------
# Usage
#---------------------------------------------
function usage() {
cat << EOF
Usage: vsm-controller
Simple installation:
Controller Node: vsm-controller -r controller [-m mysql_root_password] [-k old_key_file]
All in one: vsm-controller -r allinone [-m mysql_root_password] [-k old_key_file]
EOF
if [[ $1 -gt 0 ]]; then
cat << EOF
Self-Designed installation:
Step 1: create file file_name.rc with content.
VSM_CONTROLLER_IP=192.168.111.1
VSM_ROLE=controller
MYSQL_ROOT_PASSWORD=mysqlpassword
RABBITMQ_PASSWORD=password_a
MYSQL_KEYSTONE_PASSWORD=password_b
ADMIN_PASSWORD=password_c
MYSQL_VSM_PASSWORD=password_d
KEYSTONE_VSM_SERVICE_PASSWORD=password_e
MYSQL_DASHBOARD_PASSWORD=password_f
VSM_OLD_KEY_FILE=/etc/vsm/hostname.key
Step 2: vsm-controller -f file_name.rc
EOF
fi
cat << EOF
Options:
--help | -h
Print usage information.
--remove | --clean
Remove all the VSM packages and configuration files.
-r | --role
Set the role of this host.
{controller,allinone}
-f | --config-file
Configuratoin file path. If you use this parameter, you may ignore other parameters.
-c | --controller-ip
Controller IP address. If you have mutilple IP, you can prefer one IP manually.
-m | --mysql
MySQL root user password.
-k | --key-file [Ignore this paramter at now.]
Old key file. We must use private key file here.
-p | --password
password for manage other agents.
Put it in /etc/vsmdeploy/deployrc
--keystone-host
The ip of the keystone server. If you provide the keystone-host,
you should provide keystone-admin-token, too.
--keystone-admin-token
The admin_token can be found in /etc/keystone/keystone.conf.
EOF
exit 0
}
#---------------------------------------------
# Clear installtion
#---------------------------------------------
function remove() {
apt-get remove -y keystone python-keystone python-keystoneclient
apt-get remove -y python-vsmclient vsm vsm-dashboard
rm -rf /etc/vsm
rm -rf /etc/vsm-dashboard
rm -rf /usr/share/vsm-dashboard
rm -rf /etc/httpd/conf.d/vsm-dashboard.conf
rm -rf /etc/keystone
rm -rf /etc/init.d/vsm-*
rm -rf /etc/init.d/*keystone*
apt-get remove -y vsm-deploy
exit 0
}
#---------------------------------------------
# Read Parameters.
#---------------------------------------------
VSM_CONTROLLER_IP=""
VSM_ROLE="controller"
VSM_OLD_KEY_FILE=""
VSM_RC_FILE=""
MYSQL_ROOT_PASSWORD=""
if [[ $# -eq 1 ]]; then
if [[ -e $1 ]]; then
echo "You should use as: vsm-controller -f config_file_path"
exit 0
fi
fi
ADMIN_PASSWORD=""
while [ $# -gt 0 ]; do
case "$1" in
-h) usage ;;
--help) usage 1;;
--remove) remove ;;
--clean) remove ;;
-m|--mysql) shift; MYSQL_ROOT_PASSWORD=$1 ;;
-r|--role) shift; VSM_ROLE=$1 ;;
-f|--config-file) shift; VSM_RC_FILE=$1 ;;
-c|--controller-ip) shift; VSM_CONTROLLER_IP=$1 ;;
-k|--token) shift; VSM_OLD_KEY_FILE=$1 ;;
-p|--password) shift; AGENT_PASSWORD=$1;;
--keystone-host) shift; KEYSTONE_HOST=$1 ;;
--keystone-admin-token) shift; ADMIN_TOKEN=$1 ;;
*) shift ;;
esac
shift
done
#---------------------------------------------
# Check Parameters.
#---------------------------------------------
mkdir -p /etc/vsmdeploy/
if [[ ! $MYSQL_ROOT_PASSWORD ]]; then
if [[ -e /etc/mysql/my.cnf ]]; then
if [[ `cat /etc/mysql/my.cnf | grep firsttime | wc -l` -gt 0 ]]; then
if [[ -e /etc/vsmdeploy/deployrc ]]; then
MYSQL_ROOT_PASSWORD=`cat /etc/vsmdeploy/deployrc |
grep MYSQL_ROOT_PASSWORD |
awk -F "=" '{print $2}'`
MYSQL_VSM_PASSWORD=`cat /etc/vsmdeploy/deployrc |
grep MYSQL_VSM_PASSWORD |
awk -F "=" '{print $2}'`
else
if [[ -e ~/.mysql_password ]]; then
source ~/.mysql_password
else
echo "You have installed and set MySQL ROOT password before."
echo "Please provide it by -m|--mysql parameter."
exit 0
fi
fi
fi
fi
fi
#---------------------------------------------
# Check Parameters.
#---------------------------------------------
if [[ -e $VSM_RC_FILE ]]; then
source $VSM_RC_FILE
fi
echo $VSM_CONTROLLER_IP
test_cnt=0
for x in controller allinone; do
if [[ $VSM_ROLE == $x ]]; then
let test_cnt=test_cnt+1
fi
done
if [[ $test_cnt -eq 0 ]]; then
cat << ________EOF
ERROR: You can just set you role in {controller|allinone}
________EOF
exit 0
fi
#---------------------------------------------
# Check Parameters.
#---------------------------------------------
function set_password {
var=$1; msg=$2
pw=${!var}
localrc=/etc/vsmdeploy/deployrc
if [ ! $pw ]; then
if [ ! -e $localrc ]; then
touch $localrc
fi
pw=" "
if [ ! $pw ]; then
pw=`openssl rand -hex 10`
fi
eval "$var=$pw"
fi
sed -i "s,$var=.*,$var=$pw,g" $localrc
}
#---------------------------------------------
# Controller
#---------------------------------------------
#HOST_IP=`hostname -I | awk '{print $2}'`
HOST_IP=`getip`
VSM_CONTROLLER_IP=${VSM_CONTROLLER_IP:-$HOST_IP}
if [[ $VSM_ROLE == "controller" ]]; then
file=/etc/vsmdeploy/deployrc
cp -rf $TOPDIR/tools/controllerrc $file
sed -i "s,%CONTROLLER_IP%,$VSM_CONTROLLER_IP,g" $file
if [[ $KEYSTONE_HOST ]]; then
sed -i "s,%KEYSTONE_HOST%,$KEYSTONE_HOST,g" $file
else
sed -i "s,%KEYSTONE_HOST%,$VSM_CONTROLLER_IP,g" $file
fi
set_password MYSQL_ROOT_PASSWORD
set_password RABBITMQ_PASSWORD
set_password MYSQL_KEYSTONE_PASSWORD
set_password ADMIN_PASSWORD
set_password AGENT_PASSWORD
set_password ADMIN_TOKEN
set_password MYSQL_VSM_PASSWORD
set_password KEYSTONE_VSM_SERVICE_PASSWORD
set_password MYSQL_DASHBOARD_PASSWORD
set_password VSM_HTTPS_PASSWORD
#[[ -e /etc/init.d/vsm-agent ]] && service vsm-agent stop
vsm_agent_status=$(service vsm-agent status|grep running | wc -l)
if [ $vsm_agent_status -gt 0]; then
service vsm-agent stop
fi
fi
if [[ $VSM_ROLE == "allinone" ]]; then
file=/etc/vsmdeploy/deployrc
cp -rf $TOPDIR/tools/allinonerc $file
sed -i "s,%CONTROLLER_IP%,$VSM_CONTROLLER_IP,g" $file
set_password MYSQL_ROOT_PASSWORD
set_password RABBITMQ_PASSWORD
set_password MYSQL_KEYSTONE_PASSWORD
set_password ADMIN_PASSWORD
set_password AGENT_PASSWORD
set_password ADMIN_TOKEN
set_password MYSQL_VSM_PASSWORD
set_password KEYSTONE_VSM_SERVICE_PASSWORD
set_password MYSQL_DASHBOARD_PASSWORD
set_password VSM_HTTPS_PASSWORD
fi
[[ -e /usr/local/bin/vsm-installer ]] && vsm-installer /etc/vsmdeploy/deployrc