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 7 - (view) (download) (as text)

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

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

Powered By FusionForge