#!/bin/bash
echo "Creating VM otrs.docker.sapian.com.co"

nova boot otrs.docker.sapian.com.co \
--image c20d53a4-9e6a-4835-b571-16983772aec9 \
--user-data otrs.docker.sapian.com.co.yaml \
--key-name "Sebastian Rojo" \
--flavor m1.medium.sd \
--num-instances 1 \
--security-groups default \
--nic net-id=41f72a3e-eecf-4c85-aec5-0007ad1a0201,v4-fixed-ip=192.168.204.43

for RUN in {1..20}; do
    if [ "$(nova show otrs.docker.sapian.com.co | awk '/status/ {print $4}')" == "ACTIVE" ]
    then
      echo "otrs.docker.sapian.com.co Active. Attahing config..."
      nova volume-attach otrs.docker.sapian.com.co 30468151-61a0-47c1-82e7-f16b625066fc /dev/vdb
      nova add-floating-ip otrs.docker.sapian.com.co 172.16.253.110
      exit 0
    else
      echo "VM otrs.docker.sapian.com.co is not active yet"
      sleep 2
    fi
done
