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

Annotation of /virt-cluster/create_vcoc.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 16 - (view) (download) (as text)

1 : agomez 16 #!/bin/bash
2 :    
3 :     #
4 :     # BonFIRE Virtual Clusters on Federated Clouds Demonstration Kit
5 :     #
6 :     # Copyright (c) Fundacion Centro Tecnologico de Supercomputacion de Galicia 2012
7 :     #
8 :     # License Apache Software
9 :     #
10 :     # The research leading to these results has received funding from
11 :     # the European Community's Seventh Framework Programme (FP7/2007-2013)
12 :     # under agreement number 257386
13 :     #
14 :     # This software is provided with ABSOLUTELY NO WARRANTY
15 :     #
16 :     #
17 :     # Before you use this script, you must configure restfully
18 :     #
19 :    
20 :     #
21 :     # Get the username from the restfully configuration.
22 :     #
23 :     USER=`grep user ~/.restfully/api.bonfire-project.eu.yml | cut -f2 -d:`
24 :     USER=`echo $USER`
25 :    
26 :     #
27 :     # Where the JSON file is saved
28 :     #
29 :     DEFDIR=../examples
30 :     DEFFILEJSON=$DEFDIR/vcoc.json
31 :     DEFFILEOVF=$DEFDIR/vcoc.ovf
32 :     #
33 :     # Where the BonFIRE portal is
34 :     #
35 :     APISERVER=https://api.bonfire-project.eu
36 :    
37 :     #
38 :     # Location
39 :     #
40 :     LOCATION=fr-inria
41 :    
42 :     #
43 :     # Version
44 :     #
45 :     VERSION=0.1
46 :     WANNAME="BonFIRE WAN"
47 :    
48 :     URI=0
49 :     N=1
50 :     OVF=0
51 :    
52 :    
53 :     function usage
54 :     {
55 :     echo $0 [-o] [-n N] [-u] [-h] [file]
56 :     echo where:
57 :     echo "-o Use OVF format. Default is JSON"
58 :     echo "-n N user N computing machines for cluster. Defualt=1"
59 :     echo "-u Use URIs instead of names for storages"
60 :     echo "-h Print this help"
61 :     echo "file An alternative name for the file. Default vcoc.json if JSON is created and VCOC.ovf if OVF ED is created"
62 :     }
63 :     function geturi
64 :     {
65 :     user=$1
66 :     pass=$2
67 :     name=$3
68 :     URI=`curl -k -i -s ${APISERVER}/locations/${LOCATION}/storages --user $user:$pass | grep $name | cut -f2 -d\"`
69 :     echo $URI
70 :     }
71 :     function getnet
72 :     {
73 :     user=$1
74 :     pass=$2
75 :     shift 2
76 :     name=$*
77 :     URI=`curl -k -i -s ${APISERVER}/locations/${LOCATION}/networks --user $user:$pass | grep "$name" | cut -f2 -d\"`
78 :     echo $URI
79 :     }
80 :    
81 :     function getpass
82 :     {
83 :     if [ ! -e ~/.restfully/api.bonfire-project.eu.yml ]
84 :     then
85 :     echo
86 :     else
87 :     echo `grep password ~/.restfully/api.bonfire-project.eu.yml | cut -f 2 -d:`
88 :     fi
89 :     }
90 :     function getuser
91 :     {
92 :     if [ ! -e ~/.restfully/api.bonfire-project.eu.yml ]
93 :     then
94 :     echo
95 :     else
96 :     echo `grep username ~/.restfully/api.bonfire-project.eu.yml | cut -f 2 -d:`
97 :     fi
98 :     }
99 :    
100 :    
101 :     while getopts ":on:uh" optname
102 :     do
103 :     case "$optname" in
104 :     "o")
105 :     OVF=1
106 :     echo "Option not yet supported"
107 :     exit
108 :     ;;
109 :     "n")
110 :     N=${OPTARG}
111 :     ;;
112 :     "u")
113 :     URI=1
114 :     ;;
115 :     "?")
116 :     echo "Unknown option $OPTARG"
117 :     usage
118 :     exit
119 :     ;;
120 :     "h")
121 :     usage
122 :     exit
123 :     ;;
124 :     ":")
125 :     echo "Option $OPTARG needs a parameter"
126 :     usage
127 :     exit
128 :     ;;
129 :     *)
130 :     # Should not occur
131 :     usage
132 :     exit
133 :     ;;
134 :     esac
135 :     done
136 :    
137 :     shift `expr $OPTIND - 1`
138 :     FILE=$1
139 :     [ $OVF -eq 0 ] && FILE=${1:-$DEFFILEJSON}
140 :     [ $OVF -eq 1 ] && FILE=${1:-$DEFFILEOVF}
141 :    
142 :     USER=`getuser`
143 :     PASSWORD=`getpass`
144 :     USER=${USER:-'NONE'}
145 :     PASSWORD=${PASSWORD:-'NONE'}
146 :     if [ "$USER" = "NONE" ] || [ "$PASSWORD" = "NONE" ]
147 :     then
148 :     echo "You must configure restfully before using this script"
149 :     exit
150 :     fi
151 :    
152 :     VOLUMENAME=${USER}_volume-1GB-empty
153 :     MASTERNAME=VirtualClusterMaster-${USER}-v$VERSION
154 :     CLIENTNAME=VirtualClusterClient-${USER}-v$VERSION
155 :    
156 :    
157 :     VOLUME=`geturi $USER $PASSWORD $VOLUMENAME`
158 :     VOLUME=${VOLUME:-'NONE'}
159 :     MASTER=`geturi $USER $PASSWORD $MASTERNAME`
160 :     MASTER=${MASTER:-'NONE'}
161 :     CLIENT=`geturi $USER $PASSWORD $CLIENTNAME`
162 :     CLIENT=${CLIENT:-'NONE'}
163 :     WAN=`getnet $USER $PASSWORD $WANNAME`
164 :     WANURI=${WAN:-'NONE'}
165 :     if [ "$WANURI" = "NONE" ]
166 :     then
167 :     echo "BonFIRE WAN not found!!!"
168 :     exit
169 :     fi
170 :    
171 :     if [ "$VOLUME" = "NONE" ] || [ "$MASTER" = "NONE" ] || [ "$CLIENT" = "NONE" ]
172 :     then
173 :     echo "You must create the volumes first"
174 :     exit
175 :     fi
176 :    
177 :    
178 :     VOL=@$VOLUMENAME
179 :     [ $URI -eq 1 ] && VOL=${APISERVER}$VOLUME
180 :     MAS=@$MASTERNAME
181 :     [ $URI -eq 1 ] && MAS=${APISERVER}$MASTER
182 :     CLI=@$CLIENTNAME
183 :     [ $URI -eq 1 ] && CLI=${APISERVER}$CLIENT
184 :     WAN=@$WANNAME
185 :     [ $URI -eq 1 ] && WAN=${APISERVER}$WANURI
186 :    
187 :    
188 :     #
189 :     # Now Create the JSON file
190 :     #
191 :     echo { > $FILE
192 :     echo \"name\": \"Virtual Cluster Demo Experiment\", >> $FILE
193 :     echo \"description\": \"Demo Virtual Cluster\", >> $FILE
194 :    
195 :     #
196 :     # Minutes for the experiment
197 :     #
198 :     echo \"duration\": 180, >> $FILE
199 :     echo \"resources\": [ >> $FILE
200 :     echo { >> $FILE
201 :    
202 :     #
203 :     # The master of the custer is defined
204 :     # It includes the master defined VM plus an additional storage
205 :     # You must create both before execute this script using:
206 :     # Master VM: build-master.rb
207 :     # Storage : build-storages.rb
208 :     #
209 :     echo " " \"compute\": { >> $FILE
210 :     echo " " \"name\": \"master\", >> $FILE
211 :     echo " " \"description\": \"Virtual Cluster Master\", >> $FILE
212 :     echo " " \"instanceType\": \"small\", >> $FILE
213 :     echo " " \"locations\": [\"fr-inria\"], >> $FILE
214 :     echo " " \"resources\": [ >> $FILE
215 :     echo " " { \"storage\": \"${MAS}\"}, >> $FILE
216 :     echo " " { \"storage\": \"${VOL}\"}, >> $FILE
217 :     echo " " { \"network\": \"${WAN}\"} >> $FILE
218 :     echo " " ], >> $FILE
219 :     echo " " \"contexts\": [ >> $FILE
220 :     echo " " { >> $FILE
221 :     echo " " } >> $FILE
222 :     echo " "] >> $FILE
223 :     echo " " } >> $FILE
224 :    
225 :     #
226 :     # Now, the compute element is added
227 :     #
228 :     # Previously, you must execute the build-client.rb script, so VM image is ready.
229 :     #
230 :     i=0
231 :     while [ $i -lt $N ]
232 :     do
233 :     echo }, >> $FILE # ENDS previous element
234 :     echo { >> $FILE
235 :     echo " " \"compute\": { >> $FILE
236 :     echo " " \"name\": \"client-$i\", >> $FILE
237 :     echo " " \"description\": \"Virtual Cluster Client\", >> $FILE
238 :     echo " " \"instanceType\": \"small\", >> $FILE
239 :     echo " " \"locations\": [\"fr-inria\"], >> $FILE
240 :     echo " " \"resources\": [ >> $FILE
241 :     echo " " { \"storage\": \"${CLI}\"}, >> $FILE
242 :     echo " " { \"network\": \"${WAN}\"} >> $FILE
243 :     echo " " ], >> $FILE
244 :     echo " " \"contexts\": [ >> $FILE
245 :     echo " " { >> $FILE
246 :     echo " " } >> $FILE
247 :     echo " " ] >> $FILE
248 :     echo " " } >> $FILE
249 :     i=`expr $i + 1`
250 :     done
251 :     echo } >> $FILE
252 :     echo ] >> $FILE
253 :     echo } >> $FILE
254 :     echo >> $FILE
255 :    
256 :    
257 :     echo JSON file $FILE has been created

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

Powered By FusionForge