--- virt-cluster/create_vcoc.sh 2012/08/30 12:48:07 9 +++ virt-cluster/create_vcoc.sh 2012/08/31 10:40:38 10 @@ -1,257 +1,257 @@ -#!/bin/bash - -# -# BonFIRE Virtual Clusters on Federated Clouds Demonstration Kit -# -# Copyright (c) Fundacion Centro Tecnologico de Supercomputacion de Galicia 2012 -# -# License GPL Version 3 -# -# The research leading to these results has received funding from -# the European Community's Seventh Frameqork Programme (FP7/2007-2013) -# under agreement number 257386 -# -# This software is provided with ABSOLUTELY NO WARRANTY -# -# -# Before you use this script, you must configure restfully -# - -# -# Get the username from the restfully configuration. -# -USER=`grep user ~/.restfully/api.bonfire-project.eu.yml | cut -f2 -d:` -USER=`echo $USER` - -# -# Where the JSON file is saved -# -DEFDIR=../examples -DEFFILEJSON=$DEFDIR/vcoc.json -DEFFILEOVF=$DEFDIR/vcoc.ovf -# -# Where the BonFIRE portal is -# -APISERVER=https://api.bonfire-project.eu - -# -# Location -# -LOCATION=fr-inria - -# -# Version -# -VERSION=0.1 -WANNAME="BonFIRE WAN" - -URI=0 -N=1 -OVF=0 - - -function usage -{ - echo $0 [-o] [-n N] [-u] [-h] [file] - echo where: - echo "-o Use OVF format. Default is JSON" - echo "-n N user N computing machines for cluster. Defualt=1" - echo "-u Use URIs instead of names for storages" - echo "-h Print this help" - echo "file An alternative name for the file. Default vcoc.json if JSON is created and VCOC.ovf if OVF ED is created" -} -function geturi -{ - user=$1 - pass=$2 - name=$3 - URI=`curl -k -i -s ${APISERVER}/locations/${LOCATION}/storages --user $user:$pass | grep $name | cut -f2 -d\"` - echo $URI -} -function getnet -{ - user=$1 - pass=$2 - shift 2 - name=$* - URI=`curl -k -i -s ${APISERVER}/locations/${LOCATION}/networks --user $user:$pass | grep "$name" | cut -f2 -d\"` - echo $URI -} - -function getpass -{ - if [ ! -e ~/.restfully/api.bonfire-project.eu.yml ] - then - echo - else - echo `grep password ~/.restfully/api.bonfire-project.eu.yml | cut -f 2 -d:` - fi -} -function getuser -{ - if [ ! -e ~/.restfully/api.bonfire-project.eu.yml ] - then - echo - else - echo `grep username ~/.restfully/api.bonfire-project.eu.yml | cut -f 2 -d:` - fi -} - - -while getopts ":on:uh" optname - do - case "$optname" in - "o") - OVF=1 - echo "Option not yet supported" - exit - ;; - "n") - N=${OPTARG} - ;; - "u") - URI=1 - ;; - "?") - echo "Unknown option $OPTARG" - usage - exit - ;; - "h") - usage - exit - ;; - ":") - echo "Option $OPTARG needs a parameter" - usage - exit - ;; - *) - # Should not occur - usage - exit - ;; - esac - done - -shift `expr $OPTIND - 1` -FILE=$1 -[ $OVF -eq 0 ] && FILE=${1:-$DEFFILEJSON} -[ $OVF -eq 1 ] && FILE=${1:-$DEFFILEOVF} - -USER=`getuser` -PASSWORD=`getpass` -USER=${USER:-'NONE'} -PASSWORD=${PASSWORD:-'NONE'} -if [ "$USER" = "NONE" ] || [ "$PASSWORD" = "NONE" ] -then - echo "You must configure restfully before using this script" - exit -fi - -VOLUMENAME=${USER}_volume-1GB-empty -MASTERNAME=VirtualClusterMaster-${USER}-v$VERSION -CLIENTNAME=VirtualClusterClient-${USER}-v$VERSION - - -VOLUME=`geturi $USER $PASSWORD $VOLUMENAME` -VOLUME=${VOLUME:-'NONE'} -MASTER=`geturi $USER $PASSWORD $MASTERNAME` -MASTER=${MASTER:-'NONE'} -CLIENT=`geturi $USER $PASSWORD $CLIENTNAME` -CLIENT=${CLIENT:-'NONE'} -WAN=`getnet $USER $PASSWORD $WANNAME` -WANURI=${WAN:-'NONE'} -if [ "$WANURI" = "NONE" ] -then - echo "BonFIRE WAN not found!!!" - exit -fi - -if [ "$VOLUME" = "NONE" ] || [ "$MASTER" = "NONE" ] || [ "$CLIENT" = "NONE" ] -then - echo "You must create the volumes first" - exit -fi - - -VOL=@$VOLUMENAME -[ $URI -eq 1 ] && VOL=${APISERVER}$VOLUME -MAS=@$MASTERNAME -[ $URI -eq 1 ] && MAS=${APISERVER}$MASTER -CLI=@$CLIENTNAME -[ $URI -eq 1 ] && CLI=${APISERVER}$CLIENT -WAN=@$WANNAME -[ $URI -eq 1 ] && WAN=${APISERVER}$WANURI - - -# -# Now Create the JSON file -# -echo { > $FILE -echo \"name\": \"Virtual Cluster Demo Experiment\", >> $FILE -echo \"description\": \"Demo Virtual Cluster\", >> $FILE - -# -# Minutes for the experiment -# -echo \"duration\": 180, >> $FILE -echo \"resources\": [ >> $FILE -echo { >> $FILE - -# -# The master of the custer is defined -# It includes the master defined VM plus an additional storage -# You must create both before execute this script using: -# Master VM: build-master.rb -# Storage : build-storages.rb -# -echo " " \"compute\": { >> $FILE -echo " " \"name\": \"master\", >> $FILE -echo " " \"description\": \"Virtual Cluster Master\", >> $FILE -echo " " \"instanceType\": \"small\", >> $FILE -echo " " \"locations\": [\"fr-inria\"], >> $FILE -echo " " \"resources\": [ >> $FILE -echo " " { \"storage\": \"${MAS}\"}, >> $FILE -echo " " { \"storage\": \"${VOL}\"}, >> $FILE -echo " " { \"network\": \"${WAN}\"} >> $FILE -echo " " ], >> $FILE -echo " " \"contexts\": [ >> $FILE -echo " " { >> $FILE -echo " " } >> $FILE -echo " "] >> $FILE -echo " " } >> $FILE - -# -# Now, the compute element is added -# -# Previously, you must execute the build-client.rb script, so VM image is ready. -# -i=0 -while [ $i -lt $N ] -do - echo }, >> $FILE # ENDS previous element - echo { >> $FILE - echo " " \"compute\": { >> $FILE - echo " " \"name\": \"client-$i\", >> $FILE - echo " " \"description\": \"Virtual Cluster Client\", >> $FILE - echo " " \"instanceType\": \"small\", >> $FILE - echo " " \"locations\": [\"fr-inria\"], >> $FILE - echo " " \"resources\": [ >> $FILE - echo " " { \"storage\": \"${CLI}\"}, >> $FILE - echo " " { \"network\": \"${WAN}\"} >> $FILE - echo " " ], >> $FILE - echo " " \"contexts\": [ >> $FILE - echo " " { >> $FILE - echo " " } >> $FILE - echo " " ] >> $FILE - echo " " } >> $FILE - i=`expr $i + 1` -done - echo } >> $FILE - echo ] >> $FILE -echo } >> $FILE - echo >> $FILE - - -echo JSON file $FILE has been created +#!/bin/bash + +# +# BonFIRE Virtual Clusters on Federated Clouds Demonstration Kit +# +# Copyright (c) Fundacion Centro Tecnologico de Supercomputacion de Galicia 2012 +# +# License GPL Version 3 +# +# The research leading to these results has received funding from +# the European Community's Seventh Framework Programme (FP7/2007-2013) +# under agreement number 257386 +# +# This software is provided with ABSOLUTELY NO WARRANTY +# +# +# Before you use this script, you must configure restfully +# + +# +# Get the username from the restfully configuration. +# +USER=`grep user ~/.restfully/api.bonfire-project.eu.yml | cut -f2 -d:` +USER=`echo $USER` + +# +# Where the JSON file is saved +# +DEFDIR=../examples +DEFFILEJSON=$DEFDIR/vcoc.json +DEFFILEOVF=$DEFDIR/vcoc.ovf +# +# Where the BonFIRE portal is +# +APISERVER=https://api.bonfire-project.eu + +# +# Location +# +LOCATION=fr-inria + +# +# Version +# +VERSION=0.1 +WANNAME="BonFIRE WAN" + +URI=0 +N=1 +OVF=0 + + +function usage +{ + echo $0 [-o] [-n N] [-u] [-h] [file] + echo where: + echo "-o Use OVF format. Default is JSON" + echo "-n N user N computing machines for cluster. Defualt=1" + echo "-u Use URIs instead of names for storages" + echo "-h Print this help" + echo "file An alternative name for the file. Default vcoc.json if JSON is created and VCOC.ovf if OVF ED is created" +} +function geturi +{ + user=$1 + pass=$2 + name=$3 + URI=`curl -k -i -s ${APISERVER}/locations/${LOCATION}/storages --user $user:$pass | grep $name | cut -f2 -d\"` + echo $URI +} +function getnet +{ + user=$1 + pass=$2 + shift 2 + name=$* + URI=`curl -k -i -s ${APISERVER}/locations/${LOCATION}/networks --user $user:$pass | grep "$name" | cut -f2 -d\"` + echo $URI +} + +function getpass +{ + if [ ! -e ~/.restfully/api.bonfire-project.eu.yml ] + then + echo + else + echo `grep password ~/.restfully/api.bonfire-project.eu.yml | cut -f 2 -d:` + fi +} +function getuser +{ + if [ ! -e ~/.restfully/api.bonfire-project.eu.yml ] + then + echo + else + echo `grep username ~/.restfully/api.bonfire-project.eu.yml | cut -f 2 -d:` + fi +} + + +while getopts ":on:uh" optname + do + case "$optname" in + "o") + OVF=1 + echo "Option not yet supported" + exit + ;; + "n") + N=${OPTARG} + ;; + "u") + URI=1 + ;; + "?") + echo "Unknown option $OPTARG" + usage + exit + ;; + "h") + usage + exit + ;; + ":") + echo "Option $OPTARG needs a parameter" + usage + exit + ;; + *) + # Should not occur + usage + exit + ;; + esac + done + +shift `expr $OPTIND - 1` +FILE=$1 +[ $OVF -eq 0 ] && FILE=${1:-$DEFFILEJSON} +[ $OVF -eq 1 ] && FILE=${1:-$DEFFILEOVF} + +USER=`getuser` +PASSWORD=`getpass` +USER=${USER:-'NONE'} +PASSWORD=${PASSWORD:-'NONE'} +if [ "$USER" = "NONE" ] || [ "$PASSWORD" = "NONE" ] +then + echo "You must configure restfully before using this script" + exit +fi + +VOLUMENAME=${USER}_volume-1GB-empty +MASTERNAME=VirtualClusterMaster-${USER}-v$VERSION +CLIENTNAME=VirtualClusterClient-${USER}-v$VERSION + + +VOLUME=`geturi $USER $PASSWORD $VOLUMENAME` +VOLUME=${VOLUME:-'NONE'} +MASTER=`geturi $USER $PASSWORD $MASTERNAME` +MASTER=${MASTER:-'NONE'} +CLIENT=`geturi $USER $PASSWORD $CLIENTNAME` +CLIENT=${CLIENT:-'NONE'} +WAN=`getnet $USER $PASSWORD $WANNAME` +WANURI=${WAN:-'NONE'} +if [ "$WANURI" = "NONE" ] +then + echo "BonFIRE WAN not found!!!" + exit +fi + +if [ "$VOLUME" = "NONE" ] || [ "$MASTER" = "NONE" ] || [ "$CLIENT" = "NONE" ] +then + echo "You must create the volumes first" + exit +fi + + +VOL=@$VOLUMENAME +[ $URI -eq 1 ] && VOL=${APISERVER}$VOLUME +MAS=@$MASTERNAME +[ $URI -eq 1 ] && MAS=${APISERVER}$MASTER +CLI=@$CLIENTNAME +[ $URI -eq 1 ] && CLI=${APISERVER}$CLIENT +WAN=@$WANNAME +[ $URI -eq 1 ] && WAN=${APISERVER}$WANURI + + +# +# Now Create the JSON file +# +echo { > $FILE +echo \"name\": \"Virtual Cluster Demo Experiment\", >> $FILE +echo \"description\": \"Demo Virtual Cluster\", >> $FILE + +# +# Minutes for the experiment +# +echo \"duration\": 180, >> $FILE +echo \"resources\": [ >> $FILE +echo { >> $FILE + +# +# The master of the custer is defined +# It includes the master defined VM plus an additional storage +# You must create both before execute this script using: +# Master VM: build-master.rb +# Storage : build-storages.rb +# +echo " " \"compute\": { >> $FILE +echo " " \"name\": \"master\", >> $FILE +echo " " \"description\": \"Virtual Cluster Master\", >> $FILE +echo " " \"instanceType\": \"small\", >> $FILE +echo " " \"locations\": [\"fr-inria\"], >> $FILE +echo " " \"resources\": [ >> $FILE +echo " " { \"storage\": \"${MAS}\"}, >> $FILE +echo " " { \"storage\": \"${VOL}\"}, >> $FILE +echo " " { \"network\": \"${WAN}\"} >> $FILE +echo " " ], >> $FILE +echo " " \"contexts\": [ >> $FILE +echo " " { >> $FILE +echo " " } >> $FILE +echo " "] >> $FILE +echo " " } >> $FILE + +# +# Now, the compute element is added +# +# Previously, you must execute the build-client.rb script, so VM image is ready. +# +i=0 +while [ $i -lt $N ] +do + echo }, >> $FILE # ENDS previous element + echo { >> $FILE + echo " " \"compute\": { >> $FILE + echo " " \"name\": \"client-$i\", >> $FILE + echo " " \"description\": \"Virtual Cluster Client\", >> $FILE + echo " " \"instanceType\": \"small\", >> $FILE + echo " " \"locations\": [\"fr-inria\"], >> $FILE + echo " " \"resources\": [ >> $FILE + echo " " { \"storage\": \"${CLI}\"}, >> $FILE + echo " " { \"network\": \"${WAN}\"} >> $FILE + echo " " ], >> $FILE + echo " " \"contexts\": [ >> $FILE + echo " " { >> $FILE + echo " " } >> $FILE + echo " " ] >> $FILE + echo " " } >> $FILE + i=`expr $i + 1` +done + echo } >> $FILE + echo ] >> $FILE +echo } >> $FILE + echo >> $FILE + + +echo JSON file $FILE has been created