#!/bin/bash
SERVERNAME=erfassen-02-med
echo "Creating VM ${SERVERNAME}"

openstack server create  \
--image pfSense-CE-2.4.5-amd64 \
--key-name "sebastian_rojo_at_sapian" \
--flavor m1.small.16d \
--min 1 \
--max 1 \
--nic net-id=f87fda8f-4d9c-4fef-8931-0e2c47d2742e \
--nic net-id=886ca8cf-6b6e-4fb8-947e-44080574b1c5,v4-fixed-ip=190.217.58.212 \
--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 volume show ${CONFIG_VOLUME}
      # openstack server show ${SERVERNAME}
      exit 0
    else
      echo "VM ${SERVERNAME} is not active yet"
      sleep 2
    fi
done
