-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevtest.sh
executable file
·100 lines (73 loc) · 2.79 KB
/
devtest.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
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
PREFIX=$(dirname $0)
if [ ! -e $PREFIX'/sdi.conf' ]; then
echo "ERROR: The $PREFIX/sdi.conf file does not exist or can not be accessed"
exit 1
fi
source $PREFIX'/sdi.conf'
#test if config is loaded
if test $? != 0; then
echo "ERROR: failed to load $PREFIX/sdi.conf file (status.sh)"
exit 1
fi
CLASSES=$(ls $CLASSESDIR)
HOST_CHOSEN=0
HOST_DESTINO=null
chose_host(){
for CLASS in $CLASSES; do
printf "INICIO \n"
if [ $HOST_CHOSEN -eq 0 ]; then
printf "DEBUG A \n"
cat $CLASSESDIR/$CLASS | \
while read HOST; do
printf "DEBUG B ($HOST) \n"
# verifica se esta online
IS_UP="$(tail -1 $DATADIR/$HOST/status | awk -F' ' '{print $2}' )"
if [ $IS_UP = "ONLINE" ]; then
printf "DEBUG C \n"
# verifica se suporta docker
DOCKER="$(tail -1 $DATADIR/$HOST/checkdocker | awk -F' ' '{print $2}' )"
if [ $DOCKER = "SUPPORT" ]; then
printf "DEBUG D \n"
# verifica se esta abaixo do limite de containers por maquina
if [ ! -f $DATADIR/$HOST/".qtdcontainers" ]; then
printf "DEBUG E ($HOST) \n"
HOST_CHOSEN=1
HOST_DESTINO=$HOST
printf "Host_chosen: $HOST_CHOSEN\n"
printf "DESTINO: "$HOST_DESTINO"\n"
#echo 1 > $DATADIR/$HOST/".qtdcontainers"
break
else
printf "DEBUG F ($HOST) \n"
QTD_CONT="$(cat $DATADIR/$HOST/".qtdcontainers")"
if [ $QTD_CONT -lt $MAX_CONTAINERS_BY_HOST ];then
printf "DEBUG G ($HOST) \n"
HOST_CHOSEN=1
HOST_DESTINO=$HOST
let QTD_CONT=$QTD_CONT+1;
#echo $QTD_CONT > $DATADIR/$HOST/".qtdcontainers"
break
fi
fi
fi
fi
done
printf "SAIU DEBUG A \n"
printf "Host_chosen: $HOST_CHOSEN\n"
fi
printf "FIM 1 \n"
printf "Host_chosen: $HOST_CHOSEN\n"
done
printf "FIM 2 \n"
printf "Host_chosen: $HOST_CHOSEN\n"
}
chose_host;
#printf "O container sera enviado para o cliente $HOST_DESTINO\n"
printf "DESTINO: "$HOST_DESTINO"\n"
if [ $HOST_CHOSEN -eq 1 ]; then
printf $HOST_DESTINO
else
printf "nada selecionado"
fi
printf "\n"