-
Notifications
You must be signed in to change notification settings - Fork 3
/
common
217 lines (171 loc) · 4.05 KB
/
common
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
#!/bin/bash
RDO_URL="http://rdo.fedorapeople.org/openstack"
IMG_TYPES="centos6 centos7 rhel6 rhel7 fedora20"
RDO_RELEASES="icehouse juno"
RHOS_RELEASES="5 6"
ssh="ssh -txq"
VIRSH="sudo virsh"
txtund=$(tput sgr 0 1 2> /dev/null) # Underline
txtbld=$(tput bold 2> /dev/null) # Bold
txtred=$(tput setaf 1 2> /dev/null) # Red
txtgrn=$(tput setaf 2 2> /dev/null) # Green
txtylw=$(tput setaf 3 2> /dev/null) # Yellow
txtblu=$(tput setaf 4 2> /dev/null) # Blue
txtpur=$(tput setaf 5 2> /dev/null) # Purple
txtcyn=$(tput setaf 6 2> /dev/null) # Cyan
txtwht=$(tput setaf 7 2> /dev/null) # White
txtrst=$(tput sgr0 2> /dev/null) # Text reset
do_die() {
echo -e "${txtrst}"
if ! [ -z "$(jobs)" ]; then
kill %1
fi
echo "Exiting on user request"
exit 1
}
do_exit_error() {
exit 1
}
# trap keyboard interrupt (control-c)
trap do_die SIGINT SIGTERM SIGQUIT
ssh-clean() {
ssh-keygen -R $1 2> /dev/null
ip=$(gethostip -d $1)
test -n "$ip" && ssh-keygen -R $ip 2> /dev/null
}
error() {
local msg="$1"
[ -z "$msg" ] && msg="Error. Aborting."
echo "${txtred}$msg${txtrst}" 1>&2
trap do_exit_error EXIT
type -t print_help && print_help 1>&2
exit 1
}
info() {
echo "${txtcyn}$1${txtrst}"
}
warn() {
echo "${txtylw}$1${txtrst}"
}
waitkey() {
echo
echo -ne "${txtblu}"
echo $1
echo -ne "${txtcya}"
read -p "Press any key to continue... " -n1 -s
echo -ne "${txtrst}"
echo
}
sleepwait() {
echo -ne "${txtblu}"
echo -n "Sleeping"
for i in `seq 1 $1`; do
echo -n "."
sleep 1
done
echo " Done"
echo -ne "${txtrst}"
}
pingwait() {
local host=$(echo $1 | cut -d'@' -f2)
echo -ne "${txtpur}"
echo -n "Ping waiting for $host."
until ping -c 1 $host > /dev/null 2>&1; do
echo -n "."
sleep 1
done
echo -ne "${txtblu}"
echo " $host is up!"
echo -ne "${txtrst}"
}
sshwait() {
local host=$1
pingwait $host
echo -ne "${txtpur}"
echo -n "SSH waiting for $host."
until ssh -txq $host uptime > /dev/null 2>&1; do
echo -n "."
sleep 1
done
echo -ne "${txtblu}"
echo " $host is up!"
echo -ne "${txtrst}"
}
virsh_shutdown_wait() {
local host=$1
echo -ne "${txtpur}"
echo -n "virsh domstate waiting for $host."
$VIRSH domstate $host > /dev/null 2>&1 || { echo " No Host"; return; }
until $VIRSH domstate $host | grep "shut off" > /dev/null 2>&1; do
echo -n "."
sleep 1
done
echo -ne "${txtblu}"
echo " $host is down!"
echo -ne "${txtrst}"
}
addhost() {
local host=$1
local ip=$2
sudo sed -i -e /$host/d -e /$ip/d /etc/hosts
echo -e "$ip\t\t$host" | sudo tee -a /etc/hosts
}
getsub() {
local type=$1
local sub=100
for t in $IMG_TYPES; do
if [ "$t" == "$type" ]; then
echo $sub
return
fi
sub=$(( $sub + 1 ))
done
error "os type '$type' not recognized. Please pick one of: $IMG_TYPES"
}
checktype() {
local type=$1
getsub $type > /dev/null
}
foreach_host() {
local type=$1
local count=$2
local command=$3
for i in `seq 1 $count`; do
image="${type}$i"
$command $image
done
}
foreach_hostssh() {
local type=$1
local count=$2
local command=$3
for i in `seq 1 $count`; do
image="${type}$i"
$ssh admin@$image $command
done
}
sshwait_hosts() {
local type=$1
local count=$2
for i in `seq 1 $count`; do
image="${type}$i"
sshwait admin@$image
done
}
osvariant() {
local type=$1
[ "$type" == "centos6" ] && type="rhel6"
[ "$type" == "centos7" ] && type="rhel7"
echo $type
}
refresh-storage-pools() {
for pool in $($VIRSH pool-list | grep active | awk '{print $1}'); do
$VIRSH pool-refresh $pool
done
}
use_nested_virt() {
grep "Y" /sys/module/kvm_intel/parameters/nested > /dev/null 2>&1
if [ $? == 0 ]; then
echo "--cpu SandyBridge,match=exact,require=vmx"
fi
}