#!/bin/bash
#
# This is a helper to get tripleo-cd admins to deploy testenvs repeatably.
set -eux
set -o pipefail

if [ -z "${1:-}" ] ; then
    echo "Please supply the IP of the overcloud controller as the first parameter"
    exit 1
fi


GEARMANHOST=${2:-192.168.1.1}
PUBLICINTERFACE=${3:-eth2}

if heat stack-show testenv > /dev/null; then
    HEAT_OP=update
else
    HEAT_OP=create
fi
python /opt/stack/tripleo-heat-templates/tripleo_heat_merge/merge.py \
    --scale testenv=10 --output testenv-workers-built.yaml \
    /opt/stack/tripleo-ci/heat-templates/testenv-workers.yaml
heat stack-$HEAT_OP \
    -f testenv-workers-built.yaml \
    -P AuthPassword=$(awk '$1=="tripleo-ci" { print $2 }' < /os-asserted-users) \
    -P AuthUrl=http://$1:5000/v2.0 \
    -P GearmanHost=$GEARMANHOST \
    -P NetworkName=tripleo-bm-test \
    -P PublicInterface=$PUBLICINTERFACE \
    -P Hosts="$1 ci-overcloud.tripleo.org" \
    testenv

