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

nova boot ${SERVERNAME} \
--image ubuntu-16.04-amd64 \
--user-data ${SERVERNAME}.yaml \
--key-name "Sebastian Rojo" \
--flavor m1.ubuntu.tiny.sd \
--min-count 1 \
--max-count 1 \
--security-groups default \
--availability-zone nuczone \
--nic net-id=7a9ae8e9-8425-4084-94cc-fb70c069e957,v4-fixed-ip=172.16.253.10

for RUN in {1..50}; do
    if [ "$(nova show ${SERVERNAME} | awk '/status/ {print $4}')" == "ACTIVE" ]
    then
      nova show ${SERVERNAME}
      echo "${SERVERNAME} Active. Attahing config..."
      nova volume-attach ${SERVERNAME} 3ff2f076-8de8-4c3b-b244-450914ba0569 /dev/vdb
      exit 0
    else
      echo "VM ${SERVERNAME} is not active yet"
      sleep 2
    fi
done
