|
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 |
| 31 | +# Wait for all interfaces to be up and ready |
34 | 32 | {% for (name, prefix) in INTERFACE %} |
35 | | -wait_until_iface_ready {{ name }} |
| 33 | +wait_until_iface_ready ${PORT_TABLE_PREFIX} {{ name }} |
36 | 34 | {% endfor %} |
37 | 35 | {% for (name, prefix) in VLAN_INTERFACE %} |
38 | | -wait_until_iface_ready {{ name }} |
| 36 | +wait_until_iface_ready ${VLAN_TABLE_PREFIX} {{ name }} |
39 | 37 | {% endfor %} |
40 | 38 | {% for (name, prefix) in PORTCHANNEL_INTERFACE %} |
41 | | -wait_until_iface_ready {{ name }} |
| 39 | +wait_until_iface_ready ${LAG_TABLE_PREFIX} {{ name }} |
42 | 40 | {% endfor %} |
0 commit comments