|
1 | 1 | #!/usr/bin/env bash
|
2 | 2 |
|
3 |
| -function wait_until_iface_ready |
4 |
| -{ |
5 |
| - IFACE=$1 |
| 3 | +STATE_DB_IDX="6" |
6 | 4 |
|
7 |
| - echo "Waiting until interface $IFACE is up..." |
8 |
| - |
9 |
| - # Wait for the interface to come up (i.e., 'ip link show' returns 0) |
10 |
| - until ip link show dev $IFACE up > /dev/null 2>&1; do |
11 |
| - sleep 1 |
12 |
| - done |
| 5 | +PORT_TABLE_PREFIX="PORT_TABLE" |
| 6 | +VLAN_TABLE_PREFIX="VLAN_TABLE" |
| 7 | +LAG_TABLE_PREFIX="LAG_TABLE" |
13 | 8 |
|
14 |
| - echo "Interface $IFACE is up" |
| 9 | +function wait_until_iface_ready |
| 10 | +{ |
| 11 | + TABLE_PREFIX=$1 |
| 12 | + IFACE=$2 |
15 | 13 |
|
16 |
| - echo "Waiting until interface $IFACE has an IPv4 address..." |
| 14 | + echo "Waiting until interface $IFACE is ready..." |
17 | 15 |
|
18 |
| - # Wait until the interface gets assigned an IPv4 address |
| 16 | + # Wait for the interface to come up |
| 17 | + # (i.e., interface is present in STATE_DB and state is "ok") |
19 | 18 | while true; do
|
20 |
| - IP=$(ip -4 addr show dev $IFACE | grep "inet " | awk '{ print $2 }' | cut -d '/' -f1) |
21 |
| - |
22 |
| - if [ -n "$IP" ]; then |
| 19 | + RESULT=$(redis-cli -n ${STATE_DB_IDX} HGET "${TABLE_PREFIX}|${IFACE}" "state" 2> /dev/null) |
| 20 | + if [ x"$RESULT" == x"ok" ]; then |
23 | 21 | break
|
24 | 22 | fi
|
25 | 23 |
|
26 | 24 | sleep 1
|
27 | 25 | done
|
28 | 26 |
|
29 |
| - echo "Interface $IFACE is configured with IP $IP" |
| 27 | + echo "Interface ${IFACE} is ready!" |
30 | 28 | }
|
31 | 29 |
|
32 | 30 |
|
33 |
| -# Wait for all interfaces to come up and have IPv4 addresses assigned |
34 |
| -wait_until_iface_ready Vlan1000 |
35 |
| -wait_until_iface_ready PortChannel01 |
36 |
| -wait_until_iface_ready PortChannel01 |
37 |
| -wait_until_iface_ready PortChannel02 |
38 |
| -wait_until_iface_ready PortChannel02 |
39 |
| -wait_until_iface_ready PortChannel03 |
40 |
| -wait_until_iface_ready PortChannel03 |
41 |
| -wait_until_iface_ready PortChannel04 |
42 |
| -wait_until_iface_ready PortChannel04 |
| 31 | +# Wait for all interfaces to be up and ready |
| 32 | +wait_until_iface_ready ${VLAN_TABLE_PREFIX} Vlan1000 |
| 33 | +wait_until_iface_ready ${LAG_TABLE_PREFIX} PortChannel01 |
| 34 | +wait_until_iface_ready ${LAG_TABLE_PREFIX} PortChannel01 |
| 35 | +wait_until_iface_ready ${LAG_TABLE_PREFIX} PortChannel02 |
| 36 | +wait_until_iface_ready ${LAG_TABLE_PREFIX} PortChannel02 |
| 37 | +wait_until_iface_ready ${LAG_TABLE_PREFIX} PortChannel03 |
| 38 | +wait_until_iface_ready ${LAG_TABLE_PREFIX} PortChannel03 |
| 39 | +wait_until_iface_ready ${LAG_TABLE_PREFIX} PortChannel04 |
| 40 | +wait_until_iface_ready ${LAG_TABLE_PREFIX} PortChannel04 |
43 | 41 |
|
0 commit comments