Log In | Get Help   
Home My Page Projects Code Snippets Project Openings BonFIRE VCOC Demonstration Kit
Summary Activity SCM Files Wiki
[bonfiredemokit] View of /virt-cluster/create_vcoc.sh
[bonfiredemokit] / virt-cluster / create_vcoc.sh Repository:
ViewVC logotype

View of /virt-cluster/create_vcoc.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10 - (download) (as text) (annotate)
Fri Aug 31 10:40:38 2012 UTC (11 years, 9 months ago) by agomez
File size: 6233 byte(s)
Corrected minor error in license text
Powerpoint presentation to show how to use the software (also in PDF).
#!/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

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge