-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcheck_openstack.sh
84 lines (72 loc) · 2.24 KB
/
check_openstack.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
#!/bin/sh
#set -x # enable debug
set -e # quit on first error
# validate parameters
if [ $# -lt 3 ]
then
echo
echo "Checks if openstack environment is up and running."
echo
echo "Usage: check_openstack.sh <ec2_secret_key> <ec2_access_key> <ec2_url>"
echo
echo "<ec2_secret_key> - EC2 secret key"
echo "<ec2_access_key> - EC2 access key"
echo "<ec2_url> - EC2 service URL"
echo
exit 2
fi
ec2_secret_key=$1
ec2_access_key=$2
ec2_url=$3
# first add one machine
new_machine_id=`euca-run-instances ami-00000002 -t m1.tiny -a "$ec2_access_key" -s "$ec2_secret_key" -U "$ec2_url" | grep INSTANCE | awk -F ' ' '{ print $2 }'`
if [ -z "$new_machine_id" ]
then
echo "CRITICAL: Unable to add linux instance"
exit 2
fi
start_time=$(date +%s)
# now we check status of machine
machine_status=`euca-describe-instances "$new_machine_id" -a "$ec2_access_key" -s "$ec2_secret_key" -U "$ec2_url" | grep INSTANCE | awk -F ' ' '{ print $6 }'`
machine_was_running="false"
if [ -z "$machine_status" -o "$machine_status" != "running" ]
then
start_time=$(date +%s)
time_diff=$(($(date +%s)-$start_time))
while [ $time_diff -lt 300 ]
do
time_diff=$(($(date +%s)-$start_time))
# give openstack some time to create machine
sleep 5
machine_status=`euca-describe-instances "$new_machine_id" -a "$ec2_access_key" -s "$ec2_secret_key" -U "$ec2_url" | grep INSTANCE | awk -F ' ' '{ print $6 }'`
if [ "$machine_status" = "running" ]
then
machine_was_running="true"
break
fi
done
else
machine_was_running="true"
fi
# delete machine, no metter what is the status
`euca-terminate-instances "$new_machine_id" -a "$ec2_access_key" -s "$ec2_secret_key" -U "$ec2_url" | grep INSTANCE | awk -F ' ' '{ print $6 }'`
# sleep while machine is being terminated
sleep 20
# make sure that machine is deleted
machine_status=`euca-describe-instances "$new_machine_id" -a "$ec2_access_key" -s "$ec2_secret_key" -U "$ec2_url" | grep INSTANCE | awk -F ' ' '{ print $6 }'`
if [ -z "$machine_status" ]
then
# machine deleted
if [ "$machine_was_running" = "true" ]
then
echo "OK: Openstack working."
exit 0
else
echo "CRITICAL: Unable to start linux instance"
exit 2
fi
else
# machine not deleted
echo "CRITICAL: Unable to delete linux instance"
exit 2
fi