forked from progmaticlab/ffu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.sh
executable file
·78 lines (72 loc) · 2.1 KB
/
functions.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
#!/bin/bash -eu
function run_ssh() {
local user=$1
local addr=$2
local ssh_key=${3:-''}
local command=$4
local ssh_opts='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o PasswordAuthentication=no'
if [[ -n "$ssh_key" ]] ; then
ssh_opts+=" -i $ssh_key"
fi
echo ------------------------- Running on $user@$addr -----------------------------------
echo --- Command: $command
ssh ${user}@${addr} ${command}
if [ $? -ne 0 ]
then
echo ===================== FAIL: ${command}
echo Exiting
exit 1
else
echo --------------------- Command ${command} finished successfull
fi
}
function run_ssh_undercloud() {
run_ssh $SSH_USER $mgmt_ip $ssh_private_key "$@"
}
function wait_ssh() {
local user=$1
local addr=$2
local ssh_key=${3:-''}
local max_iter=${4:-120}
local iter=0
local ssh_opts='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o PasswordAuthentication=no'
if [[ -n "$ssh_key" ]] ; then
ssh_opts+=" -i $ssh_key"
fi
local tf=$(mktemp)
sleep 60
while ! scp $ssh_opts -B $tf ${user}@${addr}:/tmp/ ; do
if (( iter >= max_iter )) ; then
echo "Could not connect to VM $addr"
exit 1
fi
echo "Waiting for VM $addr..."
sleep 30
((++iter))
done
echo "Node is back!"
}
function reboot_and_wait_undercloud() {
local ssh_opts='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o PasswordAuthentication=no'
if [[ -n "$ssh_private_key" ]] ; then
ssh_opts+=" -i $ssh_private_key"
fi
echo "Rebooting undercloud"
ssh ${SSH_USER}@${mgmt_ip} 'sudo reboot' || true
wait_ssh $SSH_USER $mgmt_ip $ssh_private_key
}
function reboot_and_wait_overcloud_node() {
local ip=$1
local user=${2:-'heat-admin'}
local ssh_opts='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o PasswordAuthentication=no'
echo "Rebooting overcloud node $ip"
ssh ${user}@${ip} 'sudo reboot' || true
wait_ssh $user $ip
}
function checkForVariable() {
local env_var=$(declare -p "$1")
if ! [[ -v $1 && $env_var =~ ^declare\ -x ]]; then
echo "Error: Define $1 environment variable"
exit 1
fi
}