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 5 - (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 :     ;;
94 :     "n")
95 :     N=${OPTARG}
96 :     ;;
97 :     "u")
98 :     URI=1
99 :     ;;
100 :     "?")
101 :     echo "Unknown option $OPTARG"
102 :     usage
103 :     exit
104 :     ;;
105 :     "h")
106 :     usage
107 :     exit
108 :     ;;
109 :     ":")
110 :     echo "Option $OPTARG needs a parameter"
111 :     usage
112 :     exit
113 :     ;;
114 :     *)
115 :     # Should not occur
116 :     usage
117 :     exit
118 :     ;;
119 :     esac
120 :     done
121 :    
122 :     shift `expr $OPTIND - 1`
123 :     FILE=$1
124 :     [ $OVF -eq 0 ] && FILE=${1:-$DEFFILEJSON}
125 :     [ $OVF -eq 1 ] && FILE=${1:-$DEFFILEOVF}
126 :    
127 :     USER=`getuser`
128 :     PASSWORD=`getpass`
129 :     USER=${USER:-'NONE'}
130 :     PASSWORD=${PASSWORD:-'NONE'}
131 :     if [ "$USER" = "NONE" ] || [ "$PASSWORD" = "NONE" ]
132 :     then
133 :     echo "You must configure restfully before using this script"
134 :     exit
135 :     fi
136 :    
137 :     VOLUMENAME=${USER}_volume-1GB-empty
138 :     MASTERNAME=VirtualClusterMaster-${USER}-v$VERSION
139 :     CLIENTNAME=VirtualClusterClient-${USER}-v$VERSION
140 :    
141 :    
142 :     VOLUME=`geturi $USER $PASSWORD $VOLUMENAME`
143 :     VOLUME=${VOLUME:-'NONE'}
144 :     MASTER=`geturi $USER $PASSWORD $MASTERNAME`
145 :     MASTER=${MASTER:-'NONE'}
146 :     CLIENT=`geturi $USER $PASSWORD $CLIENTNAME`
147 :     CLIENT=${CLIENT:-'NONE'}
148 :     WAN=`getnet $USER $PASSWORD $WANNAME`
149 :     WANURI=${WAN:-'NONE'}
150 :     if [ "$WANURI" = "NONE" ]
151 :     then
152 :     echo "BonFIRE WAN not found!!!"
153 :     exit
154 :     fi
155 :    
156 :     if [ "$VOLUME" = "NONE" ] || [ "$MASTER" = "NONE" ] || [ "$CLIENT" = "NONE" ]
157 :     then
158 :     echo "You must create the volumes first"
159 :     exit
160 :     fi
161 :    
162 :    
163 :     VOL=@$VOLUMENAME
164 :     [ $URI -eq 1 ] && VOL=${APISERVER}$VOLUME
165 :     MAS=@$MASTERNAME
166 :     [ $URI -eq 1 ] && MAS=${APISERVER}$MASTER
167 :     CLI=@$CLIENTNAME
168 :     [ $URI -eq 1 ] && CLI=${APISERVER}$CLIENT
169 :     WAN=@$WANNAME
170 :     [ $URI -eq 1 ] && WAN=${APISERVER}$WANURI
171 :    
172 :    
173 :     #
174 :     # Now Create the JSON file
175 :     #
176 :     echo { > $FILE
177 :     echo \"name\": \"Virtual Cluster Demo Experiment\", >> $FILE
178 :     echo \"description\": \"Demo Virtual Cluster\", >> $FILE
179 :    
180 :     #
181 :     # Minutes for the experiment
182 :     #
183 :     echo \"duration\": 180, >> $FILE
184 :     echo \"resources\": [ >> $FILE
185 :     echo { >> $FILE
186 :    
187 :     #
188 :     # The master of the custer is defined
189 :     # It includes the master defined VM plus an additional storage
190 :     # You must create both before execute this script using:
191 :     # Master VM: build-master.rb
192 :     # Storage : build-storages.rb
193 :     #
194 :     echo " " \"compute\": { >> $FILE
195 :     echo " " \"name\": \"master\", >> $FILE
196 :     echo " " \"description\": \"Virtual Cluster Master\", >> $FILE
197 :     echo " " \"instanceType\": \"small\", >> $FILE
198 :     echo " " \"locations\": [\"fr-inria\"], >> $FILE
199 :     echo " " \"resources\": [ >> $FILE
200 :     echo " " { \"storage\": \"${MAS}\"}, >> $FILE
201 :     echo " " { \"storage\": \"${VOL}\"}, >> $FILE
202 :     echo " " { \"network\": \"${WAN}\"} >> $FILE
203 :     echo " " ], >> $FILE
204 :     echo " " \"contexts\": [ >> $FILE
205 :     echo " " { >> $FILE
206 :     echo " " } >> $FILE
207 :     echo " "] >> $FILE
208 :     echo " " } >> $FILE
209 :     echo }, >> $FILE
210 :    
211 :     #
212 :     # Now, the compute element is added
213 :     #
214 :     # Previously, you must execute the build-client.rb script, so VM image is ready.
215 :     #
216 :     echo { >> $FILE
217 :     echo " " \"compute\": { >> $FILE
218 :     echo " " \"name\": \"client\", >> $FILE
219 :     echo " " \"description\": \"Virtual Cluster Client\", >> $FILE
220 :     echo " " \"instanceType\": \"small\", >> $FILE
221 :     echo " " \"locations\": [\"fr-inria\"], >> $FILE
222 :     echo " " \"resources\": [ >> $FILE
223 :     echo " " { \"storage\": \"${CLI}\"}, >> $FILE
224 :     echo " " { \"network\": \"${WAN}\"} >> $FILE
225 :     echo " " ], >> $FILE
226 :     echo " " \"contexts\": [ >> $FILE
227 :     echo " " { >> $FILE
228 :     echo " " } >> $FILE
229 :     echo " " ] >> $FILE
230 :     echo " " } >> $FILE
231 :     echo } >> $FILE
232 :     echo ] >> $FILE
233 :     echo } >> $FILE
234 :     echo >> $FILE
235 :    
236 :    
237 :     echo JSON file $FILE has been created

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

Powered By FusionForge