tripleo-upgrade/templates/l3_agent_wait_ping.sh.j2
Sergii Golovatiuk 15be9e74e2 Refactor FIP extraction
"openstack server list" produces different output for different OSP
versions.

This change gets the very last IP from "openstack server list" which
will be the last IP of last active network and uses it for finding
correspondent Floating IP. Regexp extract IPv4 or IPv6 IP allowing to
have diffent formats of output.

Change-Id: I2a0706ed55fd99458d43ec34406ea6398dfe5c1d
(cherry picked from commit 12671705b2)
2023-04-03 23:16:53 +02:00

40 lines
1.6 KiB
Django/Jinja

#!/bin/bash
#
# Script that wait for the vm to be ready
if [ -f {{ working_dir }}/vm_ip.sh ]; then
source {{ working_dir }}/vm_ip.sh
else
{% if workload_sriov | bool %}
echo export VM_IP=$(openstack server list -f json | jq -r -c '.[0]["Networks"]' | cut -d"=" -f2) > {{ working_dir }}/vm_ip.sh
{% else %}
#openstack server list --status ACTIVE -c Networks -f value produces different results in different OSP versions
#OSP10,13,16
#openstack server list --status ACTIVE -c Networks -f value
#internal_net_6f58c1ef02=192.168.0.13, 10.0.0.159
#internal_net_7c845f5f18=192.168.0.13, 10.0.0.173
#OSP17+
#{'internal_net_93bd647902': ['192.168.0.22', '10.0.0.159']}
#{'internal_net_7c845a1e74': ['192.168.0.13', '10.0.0.173']}
#IPv6 IPs are also possible
#
#Next line extracts last ip from all active networks and finds correspondant floating IP
echo export VM_IP=$(openstack floating ip list -c 'Floating IP Address' -f value | \
grep "$(openstack server list --status ACTIVE -c Networks -f value | \
grep -Eo '(([0-9a-fA-F]{1,4}:+){3,7}[0-9a-fA-F]{1,4})|(([0-9]{1,3}[\.]){3}[0-9]{1,3})' | tail -1)") > {{ working_dir }}/vm_ip.sh
{% endif %}
source {{ working_dir }}/vm_ip.sh
fi
# Block 1 minute for the fip to be ready.
cpt=1
while ! ping -c 1 -w 1 "${VM_IP}"; do
echo "Waiting for fip to be ready ... for $cpt seconds"
if [ $cpt -gt 60 ]; then
echo "The fip ${VM_IP} took more than 1 minute to be available, aborting"
exit 1
fi
sleep 1
cpt=$((cpt+1))
done