-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnova-util.sh
executable file
·259 lines (214 loc) · 5.81 KB
/
nova-util.sh
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
#!/bin/bash
#
# @(#)$Id$
#
# Utility to create/delete instances on OpenStack
#
# The following are set as default
# - flavor m1.large
# - image OS1_rhel-guest-image-7.1-20150224.0.x86_64.qcow2
#
# Depending on the RC file vars use :
# - tenant RHMAP (public)
# - user mobileqe
# - pwd 3b73947641f1
# for reference - list of flavors
# m1.miq
# m1.small
# m1.large
# c3.2xlarge
# c3.large
# c3.mxlarge
# c3.xlarge
# m1.tiny
# m1.medium
# m3.large
# m3.medium
# m3.xlarge
# r3.large
# t2.medium
# t2.micro
# t2.small
# 209.132.183.44 xmlrpc.rhn.redhat.com
# 23.204.148.218 content-xmlrpc.rhn.redhat.com
# 209.132.183.49 subscription.rhn.redhat.com
# 209.132.182.33 repository.jboss.org
# 209.132.182.63 registry.access.redhat.com
# for a list of images use
# nova image-list
clear
cmds=( create createServer remove removeKey removeSecGroup useRc )
# define convenience functions
function updateTime() {
TIME=$(date +%T)
NOW="\033[0;96m[ $(date +%Y-%m-%d) ${TIME} ]\033[0m"
DEBUG="${NOW} \033[0;95mDEBUG\033[0m :"
INFO="${NOW} \033[0;94mINFO\033[0m :"
ERROR="${NOW} \033[0;91mERROR\033[0m :"
}
KEYPAIR=ose31pb
SECGROUP=ose31sec
#INSTANCES=(master-osev31 node1-osev31 node2-osev31 node3-osev31)
INSTANCES=(master-osev31 node1-osev31)
#RHEL_IMAGE=_OS1_rhel-guest-image-7.1
RHEL_IMAGE=rhel-guest-image-7.1-20150224.0.x86_64
function usage() {
echo -e "${INFO} Usage \n"
echo -e " \033[0;93m./nova-util.sh create\033[0m"
echo -e " \033[0;93m./nova-util.sh remove\033[0m"
echo -e " \033[0;93m./nova-util.sh removeKey\033[0m"
echo -e " \033[0;93m./nova-util.sh removeSecGroup\033[0m"
echo -e " \033[0;93m./nova-util.sh useRc <downloaded rc file>\033[0m"
echo " "
}
function create() {
# used for testing
# overides the previous set values
if [ "$1" = "test" ]
then
KEYPAIR=abckp
SECGROUP=abc
INSTANCES=(abc-test1 abc-test2)
echo -e "${INFO} Using test parameters"
else
echo -e "${INFO} No params"
fi
echo -e "${INFO} Creating ssh key pair on openstack saved in the ~/.ssh directory"
# generate a key-pair
nova keypair-add ${KEYPAIR} > ~/.ssh/${KEYPAIR}.pem
chmod 600 ~/.ssh/${KEYPAIR}.pem
nova keypair-list
sleep 5;
echo -e "${INFO} Creating new security group ${SECGROUP}"
#create security group
nova secgroup-create ${SECGROUP} 'Openshift v3.1 on OpenStack'
image=$(nova image-list | grep ${RHEL_IMAGE} | awk '{print $2}')
flavor=$(nova flavor-list | grep m1.large | awk '{print $2}')
if [ -z "$image" ]
then
echo -e "${ERROR} Image not found '_OS1_rhel-guest-image-7.1 '"
exit 1
fi
if [ -z "$flavor" ]
then
echo -e "${ERROR} Flavor not found 'm1.large'"
exit 1
fi
echo -e "${DEBUG} Image found ${image}"
echo -e "${DEBUG} flavor found ${flavor}"
echo -e "${INFO} Adding rules to ${SECGROUP}"
nova secgroup-add-rule ${SECGROUP} icmp -1 -1 0.0.0.0/0
nova secgroup-add-rule ${SECGROUP} tcp 22 22 0.0.0.0/0
nova secgroup-add-rule ${SECGROUP} tcp 53 53 0.0.0.0/0
nova secgroup-add-rule ${SECGROUP} tcp 80 80 0.0.0.0/0
nova secgroup-add-rule ${SECGROUP} tcp 443 443 0.0.0.0/0
nova secgroup-add-rule ${SECGROUP} tcp 1936 1936 0.0.0.0/0
nova secgroup-add-rule ${SECGROUP} tcp 4001 4001 0.0.0.0/0
nova secgroup-add-rule ${SECGROUP} tcp 7001 7001 0.0.0.0/0
nova secgroup-add-rule ${SECGROUP} tcp 8443 8444 0.0.0.0/0
nova secgroup-add-rule ${SECGROUP} tcp 10250 10250 0.0.0.0/0
nova secgroup-add-rule ${SECGROUP} tcp 24224 24224 0.0.0.0/0
nova secgroup-add-rule ${SECGROUP} udp 53 53 0.0.0.0/0
nova secgroup-add-rule ${SECGROUP} udp 4789 4789 0.0.0.0/0
nova secgroup-add-rule ${SECGROUP} udp 24224 24224 0.0.0.0/0
for i in ${INSTANCES[@]}; do
echo -e "${INFO} Launching instance ${i}"
nova boot --flavor ${flavor} --image ${image} --security-groups ${SECGROUP},default --key-name ${KEYPAIR} ${i}
sleep 10;
done
nova list
}
function createServer() {
updateTime
image=$(nova image-list | grep ${RHEL_IMAGE} | awk '{print $2}')
flavor=$(nova flavor-list | grep m1.large | awk '{print $2}')
echo -e "${DEBUG} --image ${image} "
for i in ${INSTANCES[@]}; do
echo -e "${INFO} Launching instance ${i}"
nova boot --flavor ${flavor} --image ${image} --security-groups ${SECGROUP},default --key-name ${KEYPAIR} ${i}
sleep 10;
done
nova list
}
function remove() {
# used for testing
# overides the previous set values
if [ "$1" = "test" ]
then
KEYPAIR=abckp
SECGROUP=abc
INSTANCES=(abc-test1 abc-test2)
echo -e "${INFO} Using test parameters"
fi
for i in ${INSTANCES[@]}; do
echo -e "${INFO} Deleting instance ${i}"
nova delete ${i}
done
}
function removeKey() {
# used for testing
# overides the previous set values
if [ "$1" = "test" ]
then
KEYPAIR=abckp
SECGROUP=abc
INSTANCES=(abc-test1 abc-test2)
echo -e "${INFO} Using test parameters"
fi
echo -e "${INFO} Deleting keypair ${KEYPAIR}"
nova keypair-delete ${KEYPAIR}
}
function removeSecGroup() {
# used for testing
# overides the previous set values
if [ "$1" = "test" ]
then
KEYPAIR=abckp
SECGROUP=abc
INSTANCES=(abc-test1 abc-test2)
echo -e "${INFO} Using test parameters"
fi
echo -e "${INFO} Deleting security group ${SECGROUP}"
nova secgroup-delete ${SECGROUP}
}
updateTime
flag=false
if [ "$#" -eq 0 ]
then
usage
exit 1
else
for var in "${cmds[@]}"
do
if [ "${var}" = "${1}" ]
then
flag=true
fi
done
if [ "${flag}" = "false" ]
then
usage
exit 1
fi
case ${1} in
create)
create ${2}
;;
createServer)
createServer ${2}
;;
remove)
remove ${2}
;;
removeKey)
removeKey ${2}
;;
removeSecGroup)
removeSecGroup ${2}
;;
useRc)
source ${2}
exit 0
;;
esac
fi