forked from crc-org/crc-cloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.sh
73 lines (62 loc) · 1.38 KB
/
common.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
#!/bin/sh
pr_info() {
if [[ $WORKING_MODE == "C" ]]
then
echo "[INF] $1" | (tee -a $LOG_FILE 2>/dev/null)
else
echo "[INF] $1" | (tee -a $TEARDOWN_LOGFILE 2>/dev/null)
fi
}
pr_error() {
if [[ $WORKING_MODE == "C" ]]
then
echo "[ERR] $1" | (tee -a $LOG_FILE 2>/dev/null)
else
echo "[ERR] $1" | (tee -a $TEARDOWN_LOGFILE 2>/dev/null)
fi
}
pr_end() {
if [[ $WORKING_MODE == "C" ]]
then
echo "[END] $1" | (tee -a $LOG_FILE 2>/dev/null)
else
echo "[END] $1" | (tee -a $TEARDOWN_LOGFILE 2>/dev/null)
fi
}
stop_if_failed(){
EXIT_CODE=$1
MESSAGE=$2
if [[ $EXIT_CODE != 0 ]]
then
pr_error "$MESSAGE"
exit $EXIT_CODE
fi
}
check_ssh(){
$NC -z $1 $SSH_PORT > /dev/null 2>&1
return $?
}
wait_instance_readiness(){
RES=1
while [[ $RES != 0 ]]
do
check_ssh $1
RES=$?
sleep 1
pr_info "waiting sshd to become ready on $1, hang on...."
done
}
get_instance_id_aws() {
$JQ -r '.Instances[0].InstanceId' $1
}
get_instance_public_ip_aws(){
INSTANCE_IP=""
while [ -z $INSTANCE_IP ]
do
INSTANCE_IP=`$AWS ec2 describe-instances --instance-ids $1 --query 'Reservations[*].Instances[*].PublicIpAddress' --output text`
done
echo "$INSTANCE_IP"
}
get_instance_private_ip_aws(){
$JQ -r '.Instances[0].PrivateIpAddress' $1
}