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)
This commit is contained in:
Sergii Golovatiuk 2023-03-31 17:59:11 +02:00 committed by Lukas Bezdicka
parent 1bd9fd41b0
commit 15be9e74e2
3 changed files with 42 additions and 3 deletions

View File

@ -6,7 +6,20 @@ if [[ ! -s {{ working_dir }}/vm_ip.sh ]]; then
{% if workload_sriov | bool %} {% 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 echo export VM_IP=$(openstack server list -f json | jq -r -c '.[0]["Networks"]' | cut -d"=" -f2) > {{ working_dir }}/vm_ip.sh
{% else %} {% else %}
echo export VM_IP=$(openstack floating ip list -f json | jq -r -c '.[] | select(.Port) | .["Floating IP Address"]' | head -1) > {{ working_dir }}/vm_ip.sh #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 %} {% endif %}
fi fi

View File

@ -9,7 +9,20 @@ else
{% if workload_sriov | bool %} {% 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 echo export VM_IP=$(openstack server list -f json | jq -r -c '.[0]["Networks"]' | cut -d"=" -f2) > {{ working_dir }}/vm_ip.sh
{% else %} {% else %}
echo export VM_IP=$(openstack floating ip list -f json | jq -r -c '.[] | select(.Port) | .["Floating IP Address"]' | head -1) > {{ working_dir }}/vm_ip.sh #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 %} {% endif %}
source {{ working_dir }}/vm_ip.sh source {{ working_dir }}/vm_ip.sh
fi fi

View File

@ -8,7 +8,20 @@ else
{% if workload_sriov | bool %} {% 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 echo export VM_IP=$(openstack server list -f json | jq -r -c '.[0]["Networks"]' | cut -d"=" -f2) > {{ working_dir }}/vm_ip.sh
{% else %} {% else %}
echo export VM_IP=$(openstack floating ip list -f json | jq -r -c '.[] | select(.Port) | .["Floating IP Address"]' | head -1) > {{ working_dir }}/vm_ip.sh #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 %} {% endif %}
source {{ working_dir }}/vm_ip.sh source {{ working_dir }}/vm_ip.sh
fi fi