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

nova boot ${SERVERNAME} \
--image DialBox-4.0.2-x86_64 \
--user-data ${SERVERNAME}.yaml \
--key-name "Sebastian Rojo" \
--flavor m1.dialbox.tiny \
--num-instances 1 \
--security-groups default \
--nic net-id=7a9ae8e9-8425-4084-94cc-fb70c069e957,v4-fixed-ip=172.16.253.138 \

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