-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenstack_functions.sh
89 lines (82 loc) · 1.7 KB
/
openstack_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
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/bash
#
# Check that this script is not loaded second time
if [[ -v OPENSTACK_FUNCTIONS ]]
then
echo "The file openstack_functions has been already sourced"
echo "Can not proceed"
exit 0
fi
#
# Get OpenStack credentials
if [ ! -f ./admin-openrc.sh ]
then
echo "Can not find ./admin-openrc.sh"
echo "Can not proceed"
exit 0
fi
source ./admin-openrc.sh
#
# Constants and a configuration
#
vms_list=()
if [[ -v vms0 ]]
then
vms_list=("${vms0[@]}")
fi
ports_list=()
if [[ -v ports0 ]]
then
ports_list=("${ports0[@]}")
fi
##
## @val_in_array determines whether a given string value is
## stored in any element of the given array
function val_in_array(){
local all_args=("$@")
local val=$1
local arr=("${all_args[@]:1}")
for a in ${arr[@]}
do
if [ "$a" = "$val" ]
then
echo "yes"
return
fi
done
echo "no"
}
##
## @plus_port connects a TF's VMI (virtual machine interface) to the
## given OpenStack's VM (virtual machine)
function plus_port(){
args=("$@")
q=0
for port in ${args[@]}
do
if [ `val_in_array $port ${ports_list[@]}` = "yes" ];
then
openstack server add port ${vms_list[$q]} $port
fi
q=`expr $q + 1`
done
}
##
## @minus port disconnects a TF's VMI (virtual machine interface) to the
## given OpenStack's VM (virtual machine)
function minus_port(){
local args=("$@")
local q=0
for port in ${args[@]}
do
if [ `val_in_array $port ${ports_list[@]}` = "yes" ];
then
openstack server remove port ${vms_list[$q]} $port
fi
q=`expr $q + 1`
done
}
export OPENSTACK_FUNCTIONS=
#
#END-OF-FILE
#