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

openstack server create  \
--image ubuntu-16.04-amd64 \
--user-data ${SERVERNAME}.yaml \
--key-name "Sebastian Rojo" \
--flavor m1.medium.md \
--min 1 \
--max 1 \
--security-group default \
--availability-zone nuczone \
--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..."
      #nova volume-attach ${SERVERNAME} ba890df0-ecf4-46c1-b96e-d5c68046e0f0 /dev/vdb
      #nova volume-attach ${SERVERNAME} 131b0e35-73db-4c20-9c68-99944a0bb0e8 /dev/vdc
      exit 0
    else
      echo "VM ${SERVERNAME} is not active yet"
      sleep 2
    fi
done
