-
Notifications
You must be signed in to change notification settings - Fork 17
/
configure
executable file
·60 lines (52 loc) · 1.59 KB
/
configure
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
#!/bin/bash
#
# Tell a switch to fetch configuration from TFTP.
#
# Wait until it responds to SNMP and wait until the transfer is complete.
#
ID=$RANDOM
IP=$1
CNT=0
while [ true ];
do
snmpget -Ov -v 2c -c private $IP 1.3.6.1.2.1.1.5.0 &> /dev/null
if [ "$?" = "0" ]; then
break
fi
CNT=$(($CNT + 1))
if [ "$CNT" = 20 ]; then
SWITCH=$(redis-cli --raw get $IP)
NETWORKNAME=$(redis-cli --raw get networkname-$IP)
echo "Timeout waiting for SNMP for $IP ($SWITCH). Network: $NETWORKNAME" \
| logger -p error -t configure
exit 1
fi
echo "Waiting for SNMP ..."
sleep 5
done
snmpset -v 2c -c private $IP .1.3.6.1.4.1.9.9.96.1.1.1.1.2.$ID i 1
snmpset -v 2c -c private $IP .1.3.6.1.4.1.9.9.96.1.1.1.1.3.$ID i 1
snmpset -v 2c -c private $IP .1.3.6.1.4.1.9.9.96.1.1.1.1.4.$ID i 4
snmpset -v 2c -c private $IP .1.3.6.1.4.1.9.9.96.1.1.1.1.5.$ID a 192.168.40.10
snmpset -v 2c -c private $IP .1.3.6.1.4.1.9.9.96.1.1.1.1.6.$ID s BASE-confg
snmpset -v 2c -c private $IP .1.3.6.1.4.1.9.9.96.1.1.1.1.14.$ID i 1
RET=2
CNT=0
while [ "$RET" = "2" ];
do
echo "Waiting for switch to apply configuration ..."
sleep 10
RET=$(snmpget -Ov -v 2c -c private $IP \
.1.3.6.1.4.1.9.9.96.1.1.1.1.10.$ID | cut -f 2 -d ' ')
CNT=$(($CNT + 1))
if [ "$CNT" = 6 ]; then
echo "Timeout waiting for switch to apply configuration for $IP." \
| logger -p error -t configure
exit 1
fi
done
echo "Return: $RET"
snmpset -v 2c -c private $IP .1.3.6.1.4.1.9.9.96.1.1.1.1.14.$ID i 6
SWITCH=$(redis-cli --raw get $IP)
echo "Successfully pushed configuration to $SWITCH ($IP)" \
| logger -t configure