#!/bin/bash
SERVERNAME=install.dialbox.sapian.com.co
echo "Creating VM ${SERVERNAME}"

nova boot ${SERVERNAME} \
--image CentOS-7-x86_64-NetInstall-1503.iso \
 --block-device source=blank,dest=volume,size=5,shutdown=preserve \
--user-data ${SERVERNAME}.yaml \
--key-name "Sebastian Rojo" \
--flavor m1.dialbox.small  \
--num-instances 1 \
--security-groups default \
--nic net-id=41f72a3e-eecf-4c85-aec5-0007ad1a0201 \


for RUN in {1..50}; do
    if [ "$(nova show ${SERVERNAME} | awk '/status/ {print $4}')" == "ACTIVE" ]
    then
      echo "${SERVERNAME} Active...."
      #nova volume-attach ${SERVERNAME} 1ae85df6-956a-43d3-9113-fa04a4cb987e /dev/vdb
      #nova add-floating-ip ${SERVERNAME} 172.16.253.107
      nova show ${SERVERNAME}
      exit 0
    else
      echo "VM ${SERVERNAME} is not active yet"
      sleep 2
    fi
done
