-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_devstack.sh
More file actions
executable file
·235 lines (210 loc) · 6.54 KB
/
my_devstack.sh
File metadata and controls
executable file
·235 lines (210 loc) · 6.54 KB
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
#!/bin/bash
# ==========================================================
# Script installs: devstaick
# Assume Ubuntu 16.04, ubuntu user available.
# See help to display all the options.
# Devstack configuration:: MariaDB, RabbitMQ, master branch,
# default passwords to secure123.
# =========================================================
# Uncomment the following line to debug
# set -o xtrace
#=================================================
# GLOBAL VARIABLES DEFINITION
#=================================================
# release branch
# branch='stable/liberty'
_branch="master"
_dest_path="/opt/stack/devstack"
# openstack component password
_password='secure123'
# Additional configurations
_added_lines=''
# Proxy to use for the installation
_proxy=''
# User for installation
STACK_USER='ubuntu'
_added_lines=''
# token
_token=`openssl rand -hex 10`
# ============================= Processes devstack installation options ============================
function PrintHelp {
echo " "
echo "Script installs devstack - different configurations available."
echo " "
echo "Usage:"
echo " ./install_devstack [--basic|--branch <branch>|--ceph|--heat|--password <pwd>|--swift|--proxy <http://<proxy-server>:<port>|--help]"
echo " "
echo " --basic Installs devstack with minimal configuration."
echo " --branch Use given branch for installation e.g stable/liberty."
echo " --ceph Configure devstack with ceph cluster."
echo " --heat Add heat project."
echo " --password Use given password for devstack DBs,Queue, etc."
echo " --proxy Uses the given proxy for the full installation"
echo " --repo (TobeImplemented)Installs devstack packages from given repo(s)."
echo " --swift Add swift project."
echo " --user User to install devstack. Defaults to ubuntu."
echo " User must exist, belong to sudoers and no password ask for sudo."
echo " "
echo " --help Prints current help text. "
echo " "
exit 1
}
function PrintError {
echo "***************************" >&2
echo "* Error: $1" >&2
echo " See ./install_devstack --help" >&2
echo "***************************" >&2
exit 1
}
# If no parameter passed print help
if [ -z "${1}" ]; then
PrintHelp
fi
while [[ ${1} ]]; do
case "${1}" in
--basic)
# minimal installation hence no extra stuff
shift
;;
--branch)
# Installs a specific branch
if [[ -z "${2}" || "${2}" == --* ]]; then
PrintError "Missing branch name."
else
_branch="${2}"
fi
shift
;;
--ceph)
read -r -d '' lines << EOM
#
# CEPH
# -------
enable_plugin ceph https://github.com/openstack/devstack-plugin-ceph
EOM
_added_lines="$_added_lines"$'\n'"$lines"
;;
--heat)
read -r -d '' lines << EOM
#
# HEAT
#
enable_service h-eng
enable_service h-api
enable_service h-api-cfn
enable_service h-api-cw
EOM
_added_lines="$_added_lines"$'\n'"$lines"
;;
--password)
# Use specific password for common objetcs
if [[ -z "${2}" || "${2}" == --* ]]; then
PrintError "Missing password."
else
_password="${2}"
fi
shift
;;
--proxy)
# Install devstack with server behind proxy
if [[ -z "${2}" || "${2}" == --* ]]; then
PrintError "Missing proxy. Expected: http://<server>:<port>"
else
_original_proxy="${2}"
echo "Acquire::http::Proxy \"${2}\";" >> /etc/apt/apt.conf
npx="127.0.0.1,localhost,10.0.0.0/8,192.168.0.0/16"
_proxy="http_proxy=${2} https_proxy=${2} no_proxy=${npx}"
_proxy="$_proxy HTTP_PROXY=${2} HTTPS_PROXY=${2} NO_PROXY=${npx}"
fi
shift
;;
--repo)
# TODO configuration to be implemented
echo "--repo is under development :("
;;
--swift)
read -r -d '' lines << EOM
#
# SWIFT
# -------
enable_service s-proxy s-object s-container s-account
EOM
_added_lines="$_added_lines"$'\n'"$lines"
;;
--user)
# Use specific user as stack user
if [[ -z "${2}" || "${2}" == --* || $(id -u "${2}" > /dev/null 2>&1; echo $?) == 1 ]]; then
PrintError "Missing stack user ${2}. User must exist, belong to sudoers, and no password for sudo."
else
STACK_USER="${2}"
fi
shift
;;
--help|-h)
PrintHelp
;;
*)
PrintError "Invalid Argument: $1."
esac
shift
done
# ============================================================================================
# Make sure using root user
if [ "$EUID" -ne "0" ]; then
PrintError "This script must be run as root."
fi
# ====================================
# Begin Instalation and Configuration:
# ====================================
# Install software pre-requisites
eval $_proxy apt-get update -y
# Install git
eval $_proxy apt-get -y install sudo git
#=================================================
# BASIC DEVSTACK
#=================================================
umask 022
# Clone devstack project with correct branch
# Into path - defatult to /opt/stack/devstack
if [[ ! -d $_dest_path ]];then
eval $_proxy git clone https://git.openstack.org/openstack-dev/devstack -b $_branch $_dest_path
fi
cd "$_dest_path"
# Create local.conf file
if [ ! -f local.conf ]; then
token=$(openssl rand -hex 10)
cat <<EOL >local.conf
[[local|localrc]]
HOST_IP=$(ip route get 8.8.8.8 | awk '{ print $NF; exit }')
ADMIN_PASSWORD=${_password}
DATABASE_PASSWORD=${_password}
RABBIT_PASSWORD=${_password}
SERVICE_PASSWORD=${_password}
SERVICE_TOKEN=${token}
ENABLE_DEBUG_LOG_LEVEL=False
DATA_DIR=/home/${STACK_USER}/data
# Use https
GIT_BASE=https://git.openstack.org
USE_PYTHON3=True
PYTHON3_VERSION=3
LOGDIR=/tmp/logs
REQUIREMENTS_DIR=/home/${STACK_USER}/requirements
SERVICE_DIR=/tmp/status
EOL
# Additional Projects Configuration
echo "$_added_lines" >> local.conf
fi
# Configure git to use https instead of git
#su $STACK_USER -c "git config --global url.\"https://\".insteadOf git://"
# Run Devstack install command [stack.sh]
if [ $(id -u "${STACK_USER}" > /dev/null 2>&1; echo $?) == 0 ]; then
chown -R $STACK_USER:$STACK_USER $_dest_path -v
else
PrintError "User $STACK_USER does not exist. Fix it and try again"
fi
eval $_proxy su $STACK_USER -c "./stack.sh"
# Clean up _proxy from apt if added
if [[ ! -z "${_original_proxy}" ]]; then
scaped_str=$(echo $_original_proxy | sed -s 's/[\/&]/\\&/g')
sed -i "/$scaped_str/c\\" /etc/apt/apt.conf
fi