|
1 | 1 | #!/usr/bin/env bash
|
2 | 2 |
|
3 |
| -function wait_until_iface_exists |
| 3 | +function wait_until_iface_ready |
4 | 4 | {
|
5 | 5 | IFACE=$1
|
6 | 6 |
|
7 |
| - echo "Waiting for interface ${IFACE}..." |
| 7 | + echo "Waiting until interface $IFACE is up..." |
8 | 8 |
|
9 | 9 | # Wait for the interface to come up (i.e., 'ip link show' returns 0)
|
10 |
| - until ip link show $IFACE > /dev/null 2>&1; do |
| 10 | + until ip link show dev $IFACE up > /dev/null 2>&1; do |
11 | 11 | sleep 1
|
12 | 12 | done
|
13 | 13 |
|
14 |
| - echo "Interface ${IFACE} is created" |
| 14 | + echo "Interface $IFACE is up" |
| 15 | + |
| 16 | + echo "Waiting until interface $IFACE has an IPv4 address..." |
| 17 | + |
| 18 | + # Wait until the interface gets assigned an IPv4 address |
| 19 | + 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 |
| 23 | + break |
| 24 | + fi |
| 25 | + |
| 26 | + sleep 1 |
| 27 | + done |
| 28 | + |
| 29 | + echo "Interface $IFACE is configured with IP $IP" |
15 | 30 | }
|
16 | 31 |
|
17 | 32 |
|
18 |
| -# Wait for all interfaces to come up before starting the DHCP relay |
| 33 | +# Wait for all interfaces to come up and have IPv4 addresses assigned |
19 | 34 | {% for (name, prefix) in INTERFACE %}
|
20 |
| -wait_until_iface_exists {{ name }} |
| 35 | +wait_until_iface_ready {{ name }} |
21 | 36 | {% endfor %}
|
22 | 37 | {% for (name, prefix) in VLAN_INTERFACE %}
|
23 |
| -wait_until_iface_exists {{ name }} |
| 38 | +wait_until_iface_ready {{ name }} |
24 | 39 | {% endfor %}
|
25 | 40 | {% for (name, prefix) in PORTCHANNEL_INTERFACE %}
|
26 |
| -wait_until_iface_exists {{ name }} |
| 41 | +wait_until_iface_ready {{ name }} |
27 | 42 | {% endfor %}
|
0 commit comments