#!/bin/env bash

set -euo pipefail

if [[ ! -s {{ working_dir }}/fip.sh ]]; then
    echo export FIP=$(openstack floating ip list -f json | jq -r -c '.[] | select(.Port) | .["Floating IP Address"]' | head -1) > {{ working_dir }}/fip.sh
fi

source {{ working_dir }}/fip.sh

while true; do
    curl --location --silent --show-error --max-time 5 \
        --write-out "HTTP Code: %{http_code}\nTotal Time: %{time_total} sec\nEffective URL: %{url_effective}\n\n" \
        http://${FIP}/ 2>/dev/null >> {{ working_dir }}/http_response.log
    sleep 1
done
