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

#--image "Debian Jessie 64-bit 8.7.2" \
#--nic net-id=e0b1f231-fa1c-4e90-b648-fc27c3f3e8a0,v4-fixed-ip=181.143.4.68 \

nova boot ${SERVERNAME} \
--image "Debian Jessie 64-bit 8.7.2" \
--user-data ${SERVERNAME}.yaml \
--key-name "Sebastian Rojo" \
--flavor m1.medium.sd \
--min-count 1 \
--max-count 1 \
--security-groups default \
--availability-zone nuczone \
--nic net-id=8049ebb5-4bf6-4e6e-a814-ff3ecefae975 \
--nic net-id=e0b1f231-fa1c-4e90-b648-fc27c3f3e8a0,v4-fixed-ip=181.143.4.68

for RUN in {1..50}; do
    if [ "$(nova show ${SERVERNAME} | awk '/status/ {print $4}')" == "ACTIVE" ]
    then
      nova show ${SERVERNAME}
      exit 0
    else
      echo "VM ${SERVERNAME} is not active yet"
      sleep 2
    fi
done
