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

nova boot ${SERVERNAME} \
--image c20d53a4-9e6a-4835-b571-16983772aec9 \
--user-data ${SERVERNAME}.yaml \
--key-name "Sebastian Rojo" \
--flavor m1.ubuntu.noswap.tiny \
--num-instances 1 \
--security-groups default \
--nic net-id=7a9ae8e9-8425-4084-94cc-fb70c069e957,v4-fixed-ip=172.16.253.137 \

for RUN in {1..50}; do
    if [ "$(nova show ${SERVERNAME} | awk '/status/ {print $4}')" == "ACTIVE" ]
    then
      echo "${SERVERNAME} Active. Attahing /var/www/dialbox-repo/ volume..."
      nova volume-attach ${SERVERNAME} e5a985bc-331f-4db9-9e14-8dfe361ef219 /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
