#!/bin/bash
#
# Script which start an ICMP connectivity check on the first in use
# floating IP during upgrade

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 %}
    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
    {% endif %}
    source {{ working_dir }}/vm_ip.sh
fi
ping -D ${VM_IP} >> ~/ping_results_$(date +%Y%m%d%H%M).log &
