#!/bin/bash
SERVERNAME=windowstest
#CONFIG_VOLUME=607f5a0d-1514-4e19-8b04-1a6dc0d497d1

echo "Creating VM ${SERVERNAME}"

openstack server create  \
--image "Windows Server 2016 Standard" \
--user-data data-${SERVERNAME}.yaml \
--key-name "Sebastian Rojo" \
--flavor m1.medium.ld \
--min 1 \
--max 1 \
--security-group DefaultSapian \
--security-group Windows \
--availability-zone mzone \
--nic net-id=7a9ae8e9-8425-4084-94cc-fb70c069e957 \
--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
