#!/bin/bash
SERVERNAME=apache
echo "Creating VM ${SERVERNAME}"

nova boot ${SERVERNAME} \
--image ubuntu-16.04-amd64 \
--user-data ${SERVERNAME}.yaml \
--key-name "Sebastian Rojo" \
--flavor  m1.medium.md \
--min-count 1 \
--max-count 1 \
--security-groups default,WebApp \
--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. Attahing  mariadb-dump-backups volume..."
      #nova volume-attach ${SERVERNAME} mariadb-dump-backups /dev/vdb
      #nova add-floating-ip ${SERVERNAME} 172.16.253.104
      nova show ${SERVERNAME}
      exit 0
    else
      echo "VM ${SERVERNAME} is not active yet"
      sleep 2
    fi
done
