#!/bin/bash
SERVERNAME=test-12-novanuc-guest
#CONFIG_VOLUME=e5f9238b-e325-4102-98d8-3db8f02e6d5b

echo "Creating VM ${SERVERNAME}"

openstack server create  \
--image "cirros-0.3.4" \
--key-name "Sebastian Rojo" \
--flavor "m1.tiny" \
--min 1 \
--max 1 \
--security-group DefaultSapian \
--availability-zone novatest:novanuc12.sapian.com.co \
--nic net-id=c07e3167-96d8-42e2-8c58-a423e2295200 \
--wait \
${SERVERNAME}

# for RUN in {1..50}; do
#     if [ "$(openstack server show ${SERVERNAME} | awk '/status/ {print $4}')" == "ACTIVE" ]
#     then
#       openstack server show ${SERVERNAME}
#       echo "${SERVERNAME} Active. Attahing CONFIG_VOLUME ${CONFIG_VOLUME}..."
#       #openstack server add volume --device /dev/vdb ${SERVERNAME} ${CONFIG_VOLUME}
#       #openstack server add floating ip ${SERVERNAME} 172.16.253.108
#       openstack volume show ${CONFIG_VOLUME}
#       openstack server show ${SERVERNAME}
#       exit 0
#     else
#       echo "VM ${SERVERNAME} is not active yet"
#       sleep 2
#     fi
# done
