#!/bin/bash

set -e

function header() {
  echo
  echo
  echo $1
  echo --------------------------
}

port=${PORT:-43273}
base="http://localhost:$port/token/__test__"
count=${COUNT:-20}
header "Connecting to $base for $count creates"

seq=${SEQ:-$(date +%s)}

for ((i=1;i<=$count;i++));
do
  gear=$seq
  curl "$base/container?u=1&d=1&i=$seq&r=$gear&t=openshift%2Fbusybox-http-app" -X PUT -d '{"ports":[{"internal":8080}]}'
  echo
  seq=$[seq+1]
done

header "See the gear slice"
systemctl status gear.slice

echo
echo 'You can delete the artifacts generated by this script by stopping the daemon, running "geard -clean",'
echo 'and then deleting /var/lib/containers/*'
