~ubuntu-core-dev/ubuntu/maverick/eucalyptus/devel

1 by graziano obertelli
from CVS
1
#!/bin/bash
444.1.69 by root
added license header to source files (not clc/)
2
#Copyright (c) 2009  Eucalyptus Systems, Inc.	
3
#
4
#This program is free software: you can redistribute it and/or modify
5
#it under the terms of the GNU General Public License as published by 
6
#the Free Software Foundation, only version 3 of the License.  
7
# 
8
#This file is distributed in the hope that it will be useful, but WITHOUT
9
#ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
#FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11
#for more details.  
12
#
13
#You should have received a copy of the GNU General Public License along
14
#with this program.  If not, see <http://www.gnu.org/licenses/>.
15
# 
16
#Please contact Eucalyptus Systems, Inc., 130 Castilian
17
#Dr., Goleta, CA 93101 USA or visit <http://www.eucalyptus.com/licenses/> 
18
#if you need additional information or have any questions.
19
#
20
#This file may incorporate work covered under the following copyright and
21
#permission notice:
22
#
23
#  Software License Agreement (BSD License)
24
#
25
#  Copyright (c) 2008, Regents of the University of California
26
#  
27
#
28
#  Redistribution and use of this software in source and binary forms, with
29
#  or without modification, are permitted provided that the following
30
#  conditions are met:
31
#
32
#    Redistributions of source code must retain the above copyright notice,
33
#    this list of conditions and the following disclaimer.
34
#
35
#    Redistributions in binary form must reproduce the above copyright
36
#    notice, this list of conditions and the following disclaimer in the
37
#    documentation and/or other materials provided with the distribution.
38
#
39
#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
40
#  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41
#  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
42
#  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
43
#  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44
#  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
45
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
46
#  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
47
#  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
48
#  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
49
#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. USERS OF
50
#  THIS SOFTWARE ACKNOWLEDGE THE POSSIBLE PRESENCE OF OTHER OPEN SOURCE
51
#  LICENSED MATERIAL, COPYRIGHTED MATERIAL OR PATENTED MATERIAL IN THIS
52
#  SOFTWARE, AND IF ANY SUCH MATERIAL IS DISCOVERED THE PARTY DISCOVERING
53
#  IT MAY INFORM DR. RICH WOLSKI AT THE UNIVERSITY OF CALIFORNIA, SANTA
54
#  BARBARA WHO WILL THEN ASCERTAIN THE MOST APPROPRIATE REMEDY, WHICH IN
55
#  THE REGENTS’ DISCRETION MAY INCLUDE, WITHOUT LIMITATION, REPLACEMENT
56
#  OF THE CODE SO IDENTIFIED, LICENSING OF THE CODE SO IDENTIFIED, OR
57
#  WITHDRAWAL OF THE CODE CAPABILITY TO THE EXTENT NEEDED TO COMPLY WITH
58
#  ANY SUCH LICENSES OR RIGHTS.
59
#
1 by graziano obertelli
from CVS
60
#
444.1.33 by root
added 'deregister' to euca_conf, eucalyptus-dns handling from eucalyptus.conf
61
#FAKEREG="yes"
1 by graziano obertelli
from CVS
62
1054.1.3 by Dave Walker (Daviey)
Ubuntu patches applied
63
FILE="@prefix@/etc/eucalyptus/eucalyptus.local.conf"
64
DEFAULTS_FILE="@prefix@/etc/eucalyptus/eucalyptus.conf"
444.1.398 by root
added 'import-conf' flag to euca_conf, to handle automated registration process parameter import in Ubuntu
65
IMPORTFILE=""
1 by graziano obertelli
from CVS
66
EUCALYPTUS=""
67
CC_PORT=""
68
NC_PORT=""
69
CLOUD_PORT=""
70
CLOUD_SSL_PORT=""
71
NAME=""
72
INSTANCE=""
25.1.85 by graziano obertelli
modified INSTALL to adjust to the new pacakges. Addedd -hypervisor and
73
EUCA_USER=""
74
HYPERVISOR=""
154 by graziano obertelli
added option to change dhcp user
75
DHCPD=""
76
DHCP_USER=""
198.1.169 by graziano obertelli
Small adjustement to spec files for 1.5.2.
77
BRIDGE=""
198.10.1 by graziano obertelli
Few details/minor bugs:
78
NEWNODES=""
198.1.8 by root
update euca_conf to use new cluster/node registration procedure.
79
NODEMODE=""
305 by graziano
Added stubs for new options.
80
WALRUS_MODE=""
308 by graziano
better handling of the sync the keys problem.
81
SYNC=""
305 by graziano
Added stubs for new options.
82
WALRUS=""
83
WALRUS_MODE=""
198.1.8 by root
update euca_conf to use new cluster/node registration procedure.
84
CLUSNAME=""
85
NEWCLUS=""
86
CLUSMODE=""
198.1.120 by graziano obertelli
We need to remove the semaphore on start/stop of the CC/NC. Added upgrade
87
UPGRADE_CONF=""
198.10.3 by graziano obertelli
Added -check and -setup to euca_conf:
88
SETUP=""
198.10.12 by graziano obertelli
-check now requires a parameter (cc, nc or cloud).
89
VERSION=""
198.10.3 by graziano obertelli
Added -check and -setup to euca_conf:
90
CHECK=""
444.1.322 by root
fixed TOSYNC bug
91
TOSYNC=""
198.10.12 by graziano obertelli
-check now requires a parameter (cc, nc or cloud).
92
TO_BACKUP="Y"
444.1.207 by root
added 'get-credentials' option to euca_conf for app store integration
93
CREDENTIALZIPFILE=""
198.10.11 by graziano obertelli
Trying to use rsync first (better handling of permissions) then scp.
94
SCP="`which scp 2> /dev/null`"
1054.1.3 by Dave Walker (Daviey)
Ubuntu patches applied
95
SCP_OPT=""
198.10.11 by graziano obertelli
Trying to use rsync first (better handling of permissions) then scp.
96
RSYNC="`which rsync 2> /dev/null`"
1054.1.3 by Dave Walker (Daviey)
Ubuntu patches applied
97
LOCALSYNC="N"
305 by graziano
Added stubs for new options.
98
WGET="`which wget 2> /dev/null`"
444.1.342 by graziano
better handling of --register-* in euca_conf
99
VERBOSE="N"
444.1.343 by graziano
added --list-{clusters|walruses|storages}
100
LIST=""
444.21.1 by graziano
use euca_conf to enable/disable ws starts/stop and use only one init
101
ENABLED=""
102
DISABLED=""
103
TO_START=""
104
1 by graziano obertelli
from CVS
105
106
usage () {
107
	echo "$0 [options] [<file>]"
108
	echo
198.10.10 by graziano obertelli
Modfiied the help message.
109
	echo "where <file> is the configuration file ($FILE by default)"
305 by graziano
Added stubs for new options.
110
	echo "   --help                           this message"
111
	echo "   -d <dir>                         point EUCALYPTUS to <dir>"
444.1.322 by root
fixed TOSYNC bug
112
	echo "   --no-rsync                       don't use rsync"
113
	echo "   --no-scp                         don't use scp"
444.38.11 by root
add option to skip scp interactive host key checking on register operations
114
	echo "   --skip-scp-hostcheck             skip scp interactive host keycheck"
1054.1.3 by Dave Walker (Daviey)
Ubuntu patches applied
115
	echo "   --local-sync                     force local key sync"
444.1.207 by root
added 'get-credentials' option to euca_conf for app store integration
116
	echo "   --get-credentials <zipfile>      download credentials to <zipfile>"
305 by graziano
Added stubs for new options.
117
	echo "   --register-nodes \"host host ...\" add new nodes to EUCALYPTUS"
1054.1.3 by Dave Walker (Daviey)
Ubuntu patches applied
118
	echo "   --discover-nodes                 find and add nodes on local network"
444.20.6 by graziano
Fix the error message: --delete-nodes is really --deregister-nodes. Fix
119
	echo "   --deregister-nodes \"host host ...\"   remove nodes from EUCALYPTUS"
444.29.121 by decker
add the euca_conf bits for describe nodes, add trivial completion for euca_conf
120
	echo "   --register-cluster <clustername> <host> add new cluster to EUCALYPTUS"
121
	echo "   --deregister-cluster <clustername>      remove cluster from EUCALYPTUS"
305 by graziano
Added stubs for new options.
122
	echo "   --register-walrus <host>         add walrus to EUCALYPTUS"
444.29.121 by decker
add the euca_conf bits for describe nodes, add trivial completion for euca_conf
123
	echo "   --deregister-walrus <host>       remove walrus from EUCALYPTUS"
1029 by Dustin Kirkland
Back-commit of an upload to Lucid which didn't get pushed to the
124
	echo "   --register-sc <clustername> <host>      add storage controller"
444.37.81 by root
fix euca_conf --help message for --register-sc and --deregister-sc
125
	echo "   --deregister-sc <clustername>           remove storage controller from EUCALYPTUS"
444.1.422 by graziano
Check remote walrus upong registration. (lp:436274)
126
	echo "   --list-walruses                  list registered walrus(es)"
127
	echo "   --list-clusters                  list registered CCs"
444.29.121 by decker
add the euca_conf bits for describe nodes, add trivial completion for euca_conf
128
	echo "   --list-nodes                     list registered NCs"
444.1.422 by graziano
Check remote walrus upong registration. (lp:436274)
129
	echo "   --list-scs                       list registered SCs"
444.1.322 by root
fixed TOSYNC bug
130
	echo "   --no-sync                        used only with --register-* to skip syncing keys"
305 by graziano
Added stubs for new options.
131
	echo "   --cc-port <port>                 set CC port"
132
	echo "   --nc-port <port>                 set NC port"
133
	echo "   --instances <path>               set the INSTANCE path"
444.16.119 by graziano
Added man page stub.
134
#	echo "   --cloud-port <port1> <port2>     set the 2 cloud ports"
305 by graziano
Added stubs for new options.
135
	echo "   --hypervisor <kvm|xen>           set hypervisor to use"
136
	echo "   --user <euca_user>               set the user to use"
137
	echo "   --dhcpd <dhcpd>                  set the dhcpd binary to <name>"
138
	echo "   --dhcp_user <user>               set the username to run dhcpd as"
139
	echo "   --name <var>                     returns the value or <name>"
1054.1.3 by Dave Walker (Daviey)
Ubuntu patches applied
140
	echo "   --import-conf <file>             import variables from <file> into $FILE"
305 by graziano
Added stubs for new options.
141
	echo "   --setup                          perform initial setup"
444.21.10 by graziano
Cosmetic changes.
142
	echo "   --enable {cloud|walrus|sc}       enable service at next start"
143
	echo "   --disable {cloud|walrus|sc}      disable service at next start"
444.21.1 by graziano
use euca_conf to enable/disable ws starts/stop and use only one init
144
	echo "   --check {nc|cc|cloud|sc|walrus}  pre-flight checks"
444.21.10 by graziano
Cosmetic changes.
145
#	echo "   --sync {nc|cc|cloud|sc|walrus}   pre-flight checks"
305 by graziano
Added stubs for new options.
146
	echo "   --version                        eucalyptus version"
1 by graziano obertelli
from CVS
147
	echo
148
}
149
198.10.12 by graziano obertelli
-check now requires a parameter (cc, nc or cloud).
150
# utility function to make a copy of the conf file
151
check_and_backup () {
152
	# can we write to the configuration file?
153
	if [ ! -w $1 ]; then
154
		echo "Cannot write to $1!"
155
		exit 1
156
	fi
157
158
	# let's see if we need a copy
159
	if [ "$TO_BACKUP" = "Y" ]; then
444.26.4 by graziano
We weren't checking the exit status after connecting (or trying) to the
160
		cp $1 $1.bak
198.10.12 by graziano obertelli
-check now requires a parameter (cc, nc or cloud).
161
		TO_BACKUP="N"
162
	fi
163
}
164
1 by graziano obertelli
from CVS
165
# 3 paramenter: the file, the variable name, the new value
166
change_var_value () {
198.10.12 by graziano obertelli
-check now requires a parameter (cc, nc or cloud).
167
	check_and_backup $1
532 by Colin Watson
SECURITY UPDATE: Fix temporary file vulnerability in euca_conf by using
168
	sed -i "s<^[[:blank:]#]*\(${2}\).*<\1=\"${3}\"<" $1
1 by graziano obertelli
from CVS
169
}
180 by graziano obertelli
Added uncomment: right now it's used only for not yet publicly known
170
# comment lines matching $2 ($1 is the file)
1.1.4 by graziano obertelli
This was the -2 RPMs. Added the fix for the typo in the init.d script. A
171
comment () {
198.10.12 by graziano obertelli
-check now requires a parameter (cc, nc or cloud).
172
	check_and_backup $1
532 by Colin Watson
SECURITY UPDATE: Fix temporary file vulnerability in euca_conf by using
173
	sed -i "s<^[[:blank:]]*\(${2}.*\)<#\1<" $1
1.1.4 by graziano obertelli
This was the -2 RPMs. Added the fix for the typo in the init.d script. A
174
}
180 by graziano obertelli
Added uncomment: right now it's used only for not yet publicly known
175
# comment lines matching $2 ($1 is the file)
176
uncomment () {
198.10.12 by graziano obertelli
-check now requires a parameter (cc, nc or cloud).
177
	check_and_backup $1
532 by Colin Watson
SECURITY UPDATE: Fix temporary file vulnerability in euca_conf by using
178
	sed -i "s<^[#[:blank:]]*\(${2}.*\)<\1<" $1
180 by graziano obertelli
Added uncomment: right now it's used only for not yet publicly known
179
}
1 by graziano obertelli
from CVS
180
444.1.422 by graziano
Check remote walrus upong registration. (lp:436274)
181
check_heartbeat() {
182
	local __host="$1"
183
	local __service="$2"
184
	local ret=""
185
186
	# checks
187
	if [ -z "$__host" -o -z "$__service" ]; then
188
		echo "check_heartbeat: need a host and a service!"
189
		return 1
190
	fi
191
	if [ -z "$WGET" -o ! -x "$WGET" ]; then
192
		echo "ERROR: wget is missing, cannot continue."
193
		return 1
194
	fi
195
196
	# let's talk to the host and check if something is running
444.36.2 by root
cleaned up euca_conf a bit for better error reporting, key syncing, and wgetting
197
	ret="`$WGET -q -T 10 -t 1 -O - http://${__host}:8773/services/Heartbeat`"
444.1.422 by graziano
Check remote walrus upong registration. (lp:436274)
198
	if [ "$?" != "0" -o -z "$ret" ]; then
199
		return 1
200
	fi
201
202
	# we need both ehabled and local to be true
203
	if ! echo $ret |grep "enabled=true" > /dev/null  ; then
204
		return 1
205
	elif ! echo $ret |grep "local=true"  > /dev/null ; then
206
		return 1
207
	fi
208
209
	return 0
210
}
211
444.1.342 by graziano
better handling of --register-* in euca_conf
212
check_ws() {
213
	local URL="$1"
214
	local ret=""
444.26.4 by graziano
We weren't checking the exit status after connecting (or trying) to the
215
	local soap_error=""
444.1.342 by graziano
better handling of --register-* in euca_conf
216
217
	if [ -z "$URL" ]; then
218
		echo "check_ws: need a URL!"
219
		return 1
220
	fi
221
	
222
	if [ -n "${FAKEREG}" ]; then
223
		ret=""
444.1.349 by graziano obertelli
Deregistering a non-existent cluster (or sc) will now print an error
224
	elif [ "$2" != "" ]; then
444.1.343 by graziano
added --list-{clusters|walruses|storages}
225
		if [ "$VERBOSE" = "Y" ]; then
444.29.121 by decker
add the euca_conf bits for describe nodes, add trivial completion for euca_conf
226
			echo   "$WGET -q -T 10 -t 1 -O - \"$URL\"" "|sed 's/<euca:registered>\\(.*\\)<\\/euca:registered>/\\n\\1\\n/g;s/<euca:name>/\\n>/g;s/<\\/*euca:item>//g;s/<\\/*euca:[^>]*>/ /g'|awk -F\">\" '/>/{print \"   \"$2}')"
444.1.343 by graziano
added --list-{clusters|walruses|storages}
227
		fi
444.29.121 by decker
add the euca_conf bits for describe nodes, add trivial completion for euca_conf
228
		E=$($WGET -q -T 10 -t 1 -O - "$URL"|\
229
			sed 's/<euca:registered>\(.*\)<\/euca:registered>/\n\1\n/g;s/<euca:name>/\n>/g;s/<\/*euca:item>//g;s/<\/*euca:[^>]*>/ /g'|\
230
			awk -F">" '/>/{print "   "$2}')
231
		eval "$2=\"${E}\""
444.1.342 by graziano
better handling of --register-* in euca_conf
232
	else
233
		if [ "$VERBOSE" = "Y" ]; then
444.36.2 by root
cleaned up euca_conf a bit for better error reporting, key syncing, and wgetting
234
			echo "$WGET -q -T 10 -t 1 -O - \"$URL\" |grep faultstring | sed 's:.*<faultstring>\(.*\)</faultstring>.*:\1:'"
444.1.342 by graziano
better handling of --register-* in euca_conf
235
		fi
444.36.2 by root
cleaned up euca_conf a bit for better error reporting, key syncing, and wgetting
236
		soap_error="`$WGET -q -T 10 -t 1 -O - \"$URL\"`"
444.26.4 by graziano
We weren't checking the exit status after connecting (or trying) to the
237
		ret="$?"
238
		soap_error="`echo $soap_error |grep faultstring | sed 's:.*<faultstring>\(.*\)</faultstring>.*:\1:'`"
239
		if test -n "$soap_error" ; then
240
			echo $soap_error
241
			ret="1"
242
		fi
243
	fi
244
	return $ret
444.1.342 by graziano
better handling of --register-* in euca_conf
245
}
246
444.1.322 by root
fixed TOSYNC bug
247
component_sync_keys() {
248
    local COMPONENT=""
249
    local NAME=""
250
    
251
    if [ "$SYNC" = "N" ]; then
252
	return 0
253
    fi
254
    
255
    if [ $# -lt 1 ]; then
256
	return 1
257
    fi
258
    
259
    COMPONENT="$1"
260
    shift
261
    NAME="$2"
262
    shift
263
264
    if [ "$COMPONENT" = "walrus" ]; then
265
	echo "syncing walrus"
266
    elif [ "$COMPONENT" = "cc" ]; then
267
	echo "syncing cc($NAME)"
268
    elif [ "$COMPONENT" = "sc" ]; then
269
	echo "syncing sc($NAME)"
270
    elif [ "$COMPONENT" = "nc" ]; then
271
	echo "syncing nc"
272
    fi
273
274
275
}
276
308 by graziano
better handling of the sync the keys problem.
277
# copy files over.
278
sync_keys() {
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
279
	local DESTDIR=""
280
	local REMOTE=""
308 by graziano
better handling of the sync the keys problem.
281
	local FILES=""
444.36.3 by root
fix bug in node-register
282
	local FILE=""
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
283
444.1.322 by root
fixed TOSYNC bug
284
	if [ "$SYNC" = "N" ]; then
285
	    return 0
286
	fi
287
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
288
	if [ $# -lt 4 ]; then
289
		return 1
290
	fi
291
444.36.2 by root
cleaned up euca_conf a bit for better error reporting, key syncing, and wgetting
292
	SOURCEDIRS="$1"
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
293
	shift
294
	DESTDIR="$1"
295
	shift
308 by graziano
better handling of the sync the keys problem.
296
	REMOTE="$1"
297
	shift
298
	while [ $# -ge 1 ]; do 
444.36.2 by root
cleaned up euca_conf a bit for better error reporting, key syncing, and wgetting
299
	    FILE=""
300
	    for sd in `echo $SOURCEDIRS | sed "s/,/ /g"`
301
	    do
302
		if [ -e "${sd}/${1}" ]; then
303
		    FILE="${sd}/${1}"
308 by graziano
better handling of the sync the keys problem.
304
		fi
444.36.2 by root
cleaned up euca_conf a bit for better error reporting, key syncing, and wgetting
305
	    done
306
	    if [ "$FILE" = "" ]; then
307
		echo "Warning: cannot file file ${1} in ${SOURCEDIRS}"
308
	    else
309
		FILES="$FILES $FILE"
310
	    fi
311
312
	    shift
308 by graziano
better handling of the sync the keys problem.
313
	done
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
314
315
	# is REMOTE actually localhost?
1054.1.3 by Dave Walker (Daviey)
Ubuntu patches applied
316
	if [ ${LOCALSYNC} = "Y" -o ${REMOTE} = "127.0.0.1" -o ${REMOTE} = localhost -o ${REMOTE} = "`hostname -s`" -o ${REMOTE} = "`hostname -f`" ]; then
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
317
	    # machine is localhost, not need for remote syncing
1029 by Dustin Kirkland
Back-commit of an upload to Lucid which didn't get pushed to the
318
	    for i in $FILES
319
	    do
320
		if [ ! -e $i ]; then
321
		    echo "ERROR: cannot find cluster credentials."
322
		    exit 1
323
		else
1054.1.3 by Dave Walker (Daviey)
Ubuntu patches applied
324
		    if ! $RSYNC -a $i $DESTDIR ; then
1029 by Dustin Kirkland
Back-commit of an upload to Lucid which didn't get pushed to the
325
			echo "ERROR: cannot copy file (${i}) to destination (${DESTDIR})"
326
			return 1
444.26.4 by graziano
We weren't checking the exit status after connecting (or trying) to the
327
		    fi
1029 by Dustin Kirkland
Back-commit of an upload to Lucid which didn't get pushed to the
328
		fi
1054.1.3 by Dave Walker (Daviey)
Ubuntu patches applied
329
	    done
444.26.4 by graziano
We weren't checking the exit status after connecting (or trying) to the
330
	    return 0
331
	fi
332
333
	# try rsync first 
334
	if [ -n "$RSYNC" ]; then
335
	    echo
336
	    echo  -n "Trying rsync to sync keys with \"${REMOTE}\"..."
1054.1.3 by Dave Walker (Daviey)
Ubuntu patches applied
337
	    [ -z "${RSYNC_RSH}" ] && RSYNC_RSH="ssh"
338
	    if sudo -u ${EUCA_USER} ${RSYNC} --rsh "${RSYNC_RSH}" -az ${FILES} ${EUCA_USER}@${REMOTE}:${DESTDIR}/ > /dev/null ; then
444.26.4 by graziano
We weren't checking the exit status after connecting (or trying) to the
339
		echo "done."
340
		return 0
341
	    else
342
		echo "failed."
343
	    fi
344
	fi
345
346
	# scp next
347
	if [ -n "$SCP" ]; then
348
	    echo
349
	    if [ "$EUCA_USER" = "" ]; then
350
		if getent passwd eucalyptus > /dev/null ; then
351
		    echo "Using 'eucalyptus' as EUCA_USER"
352
		    EUCA_USER="eucalyptus"
353
		else
354
		    echo "EUCA_USER is not defined!"
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
355
		    return 1
308 by graziano
better handling of the sync the keys problem.
356
		fi
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
357
	    fi
444.26.4 by graziano
We weren't checking the exit status after connecting (or trying) to the
358
	    echo
1054.1.3 by Dave Walker (Daviey)
Ubuntu patches applied
359
	    echo "Trying scp to sync keys to: ${EUCA_USER}@${REMOTE}:${DESTDIR}..."
360
	    if [ "$EUID" = `getent passwd $EUCA_USER | cut -f3 -d:` ]; then
361
                $SCP $SCP_OPT ${FILES} ${EUCA_USER}@${REMOTE}:${DESTDIR} > /dev/null
362
            else
363
	        sudo -u ${EUCA_USER} $SCP $SCP_OPT ${FILES} ${EUCA_USER}@${REMOTE}:${DESTDIR} > /dev/null
364
            fi
365
            if [ "$?" = "0" ]; then
444.26.4 by graziano
We weren't checking the exit status after connecting (or trying) to the
366
		echo "done."
367
		return 0
368
	    else
369
		echo "failed."
370
	    fi
371
	fi
372
	
444.26.3 by graziano
need to have /etc/eucalyptus owned by 'eucalytpus' to be able to use
373
	return 1
308 by graziano
better handling of the sync the keys problem.
374
}
375
1054.1.3 by Dave Walker (Daviey)
Ubuntu patches applied
376
xsearch() {
377
	local needle="$1" i="" haystack=" "
378
	shift
379
	for i in "$@"; do
380
		haystack="${haystack}$(printf "%s" "$i" | tr '\n' ' ') "
381
	done
382
	[ "${haystack#* ${needle} }" != "${haystack}" ]
383
}
384
1 by graziano obertelli
from CVS
385
if [ $# -eq 0 ]; then
444.26.4 by graziano
We weren't checking the exit status after connecting (or trying) to the
386
	usage
387
	exit 1
1 by graziano obertelli
from CVS
388
fi
389
390
# let's parse the command line
391
while [ $# -gt 0 ]; do
444.26.4 by graziano
We weren't checking the exit status after connecting (or trying) to the
392
	if [ "$1" = "-h" -o "$1" = "-help" -o "$1" = "?" -o "$1" = "--help" ]; then
393
		usage
394
		exit 1
395
	fi
396
397
	if [ "$1" = "-synckeys" -o "$1" = "-synckey" ]; then 
398
	    NODEMODE="SYNC"
399
	    shift
400
	    continue
401
	fi
402
	if [ "$1" = "-norsync" -o "$1" = "--no-rsync" ]; then 
403
	    RSYNC=""
404
	    shift
405
	    continue
406
	fi
1054.1.3 by Dave Walker (Daviey)
Ubuntu patches applied
407
	if [ "$1" = "--local-sync" ]; then
408
	    LOCALSYNC="Y"
409
	    shift
410
	    continue
411
	fi
444.26.4 by graziano
We weren't checking the exit status after connecting (or trying) to the
412
	if [ "$1" = "--list-scs" ]; then 
413
	    LIST="$LIST storages"
414
	    shift
415
	    continue
416
	fi
417
	if [ "$1" = "--list-walruses" ]; then 
418
	    LIST="$LIST walruses"
419
	    shift
420
	    continue
421
	fi
422
	if [ "$1" = "--list-clusters" ]; then 
423
	    LIST="$LIST clusters"
424
	    shift
425
	    continue
426
	fi
444.29.121 by decker
add the euca_conf bits for describe nodes, add trivial completion for euca_conf
427
	if [ "$1" = "--list-nodes" ]; then 
428
	    LIST="$LIST nodes"
429
	    shift
430
	    continue
431
	fi
444.26.4 by graziano
We weren't checking the exit status after connecting (or trying) to the
432
	if [ "$1" = "--verbose" ]; then 
433
	    VERBOSE="Y"
434
	    shift
435
	    continue
436
	fi
437
	if [ "$1" = "-noscp" -o "$1" = "--no-scp" ]; then 
438
	    SCP=""
439
	    shift
440
	    continue
441
	fi
444.38.11 by root
add option to skip scp interactive host key checking on register operations
442
	if [ "$1" = "--skip-scp-hostcheck" ]; then 
1054.1.3 by Dave Walker (Daviey)
Ubuntu patches applied
443
	    SCP_OPT="-oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null"
444.38.11 by root
add option to skip scp interactive host key checking on register operations
444
	    shift
445
	    continue
446
	fi
444.26.4 by graziano
We weren't checking the exit status after connecting (or trying) to the
447
	if [ "$1" = "-version" -o "$1" = "--version" ]; then 
448
	    VERSION="Y"
449
	    shift
450
	    continue
451
	fi
452
	if [ "$1" = "-setup" -o "$1" = "--setup" ]; then 
453
	    SETUP="Y"
454
	    shift
455
	    continue
456
	fi
457
	if [ "$1" = "--no-sync" ]; then 
458
	    SYNC="N"
459
	    shift
460
	    continue
461
	fi
462
	if [ "$1" = "--deregister-walrus" ]; then
463
	    WALRUS_MODE="DEL"
464
	    shift
465
	    continue
466
	fi
1054.1.3 by Dave Walker (Daviey)
Ubuntu patches applied
467
	if [ "$1" = "--discover-nodes" ]; then
468
	    NODEMODE="DISCOVER"
469
	    RSYNC_RSH="ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null"
470
	    shift
471
	    continue
472
	fi
444.26.4 by graziano
We weren't checking the exit status after connecting (or trying) to the
473
	if [ $# -eq 1 ]; then
474
		# we dont have options with no argument, so it has to be
475
		# the file
476
		FILE="$1"
477
		if [ "${FILE:0:1}" = '-' ]; then
478
			usage
479
			exit 1
480
		fi
481
		break
482
	fi
483
484
	# all other parameters requires at least 1 argument
485
	if [ $# -lt 2 ]; then
486
		usage
487
		exit 1
488
	fi
489
490
	# old command line options not used anylonger
491
	if [ "$1" = "-cc" -o "$1" = "-nc" -o "$1" = "-cloud" ]; then
492
		echo "-cc, -nc and -cloud are not used anymore"
493
		shift; shift;
494
		continue
495
	fi
496
497
	if [ "$1" = "-d" ]; then
498
		if [ ! -d "${2}" ]; then
499
			echo "Is $2 where Eucalyptus is installed?"
500
			exit 1
501
		fi
502
		EUCALYPTUS="${2}"
503
		shift; shift
504
		continue
505
	fi
506
	if [ "$1" = "-name" -o "$1" = "--name" ]; then
507
		NAME="$NAME $2"
508
		shift; shift
509
		continue
510
	fi		
511
	if [ "$1" = "-bridge" ]; then
512
		BRIDGE="$2"
513
		shift; shift
514
		continue
515
	fi		
516
	if [ "$1" = "-upgrade-conf" -o "$1" = "--upgrade-conf" ]; then
517
		# hidden options to upgrade from an older version
518
		UPGRADE_CONF="$2"
519
		if [ ! -e "$UPGRADE_CONF" ]; then
520
			echo "Cannot read $UPGRADE_CONF"
521
			exit 1
522
		fi
523
		shift; shift
524
		continue
525
	fi		
526
	if [ "$1" = "-import-conf" -o "$1" = "--import-conf" ]; then
527
	        IMPORTFILE="$2"
528
		if [ ! -e "$IMPORTFILE" ]; then
529
			echo "Cannot read $IMPORTFILE"
530
			exit 1
531
		fi
532
		shift; shift
533
		continue
534
	fi
535
	if [ "$1" = "-dhcpd" -o "$1" = "--dhcpd" ]; then
536
		DHCPD="$2"
537
		shift; shift
538
		continue
539
	fi		
540
	if [ "$1" = "-dhcp_user" -o "$1" = "--dhcp_user" ]; then
541
		DHCPC_USER="$2"
542
		shift; shift
543
		continue
544
	fi		
545
	if [ "$1" = "-nodes" ]; then
546
		NODES="${2}"
547
		shift; shift
548
		continue
549
	fi		
550
	if [ "$1" = "-ccp" -o "$1" = "--cc-port" ]; then
551
		CC_PORT="$2"
552
		shift; shift
553
		continue
554
	fi		
555
	if [ "$1" = "-ncp" -o "$1" = "--nc-port" ]; then
556
		NC_PORT="$2"
557
		shift; shift
558
		continue
559
	fi
560
	if [ "$1" = "-instances" -o "$1" = "--instances" ]; then
561
		INSTANCE="$2"
562
		shift; shift
563
		continue
564
	fi
565
	if [ "$1" = "-user" -o "$1" = "--user" ]; then
566
		EUCA_USER="$2"
567
		shift; shift
568
		continue
569
	fi
570
	if [ "$1" = "-hypervisor" -o "$1" = "--hypervisor" ]; then
571
		if [ "$2" != "xen" -a "$2" != "kvm" ]; then
572
			echo "Only kvm or xen are supported at the moment"
573
			exit 1
574
		fi
575
		HYPERVISOR="$2"
576
		shift; shift
577
		continue
578
	fi
579
	if [ "$1" = "-cloudp" ]; then
580
		if [ $# -lt 3 ]; then
581
			echo "We need 2 ports for cloud controller"
582
			exit 1
583
		fi
305 by graziano
Added stubs for new options.
584
# doesn't work right now
585
#		CLOUD_PORT="$2"
586
#		CLOUD_SSL_PORT="$3"
444.26.4 by graziano
We weren't checking the exit status after connecting (or trying) to the
587
		shift; shift; shift
588
		continue
589
	fi
590
	if [ "$1" = "--get-credentials" ]; then
591
	        CREDENTIALZIPFILE="${2}"
592
		shift; shift;
593
		continue
594
	fi
595
	if [ "$1" = "-addnode" -o "$1" = "--register-nodes" ]; then 
596
		NEWNODES="${2}"
597
		NODEMODE="ADD"
598
		shift; shift
599
		continue
600
	fi
601
	if [ "$1" = "-delnode" -o "$1" = "--deregister-nodes" ]; then 
602
		NEWNODES="${2}"
603
		NODEMODE="REM"
604
		shift; shift
605
		continue
606
	fi
607
	if [ "$1" = "--register-walrus" ]; then
608
		WALRUS_MODE="ADD"
609
		WALRUS="$2"
610
		shift; shift
611
		continue
612
	fi
613
	if [ "$1" = "--deregister-sc" ]; then
614
		SC_MODE="DEL"
615
		SCNAME="$2"
616
		shift; shift
617
		continue
618
	fi
619
	if [ "$1" = "--register-sc" ]; then
620
		if [ $# -lt 3 ]; then
621
			echo "--register-sc requires a CC and a hostname"
622
			exit 1
623
		fi
624
		SC_MODE="ADD"
625
		SCNAME="$2"
626
		SCHOST="$3"
627
		shift; shift; shift
628
		continue
629
	fi
630
	if [ "$1" = "-addcluster" -o "$1" = "--register-cluster" ]; then
631
		if [ $# -lt 3 ]; then
632
			echo "--register-cluster requires a user assigned name and CC hostname"
633
			exit 1
634
		fi
635
		CLUSNAME="$2"
636
		NEWCLUS="$3"
637
		CLUSMODE="ADD"
638
		shift; shift; shift
639
		continue
640
	fi
641
	if [ "$1" = "--deregister-cluster" ]; then
642
		CLUSNAME="$2"
643
		CLUSMODE="DEL"
644
		shift; shift
645
		continue
646
	fi
647
	if [ "$1" = "-check" -o "$1" = "--check" ]; then 
648
		if [ "$2" != "cc" -a "$2" != "cloud" -a "$2" != "nc" -a "$2" != "sc" -a "$2" != "walrus" ]; then
649
			echo "-check requires cc, nc, sc, walrus or cloud"
650
			exit 1
651
		fi
652
		CHECK="$2"
653
		shift; shift
654
		continue
655
	fi
656
	if [ "$1" = "--enable" ]; then 
657
		if [ "$2" != "cloud" -a "$2" != "sc" -a "$2" != "walrus" ]; then
658
			echo "--enable requires cloud, sc or walrus"
659
			exit 1
660
		fi
661
		ENABLED="$ENABLED $2"
662
		shift; shift
663
		continue
664
	fi
665
	if [ "$1" = "--disable" ]; then 
666
		if [ "$2" != "cloud" -a "$2" != "sc" -a "$2" != "walrus" ]; then
667
			echo "--disable requires cloud, sc or walrus"
668
			exit 1
669
		fi
670
		DISABLED="$DISABLED $2"
671
		shift; shift
672
		continue
673
	fi
674
	if [ "$1" = "-sync" -o "$1" = "--sync" ]; then 
675
		if [ "$2" != "cc" -a "$2" != "cloud" -a "$2" != "nc" -a "$2" != "sc" -a "$2" != "walrus" ]; then
676
			echo "-sync requires cc, nc, sc, walrus or cloud"
677
			exit 1
678
		fi
679
		TOSYNC="$2"
680
		shift; shift
681
		continue
682
	fi
683
	usage 
684
	exit 1
1 by graziano obertelli
from CVS
685
done
686
687
if [ -z "${FILE}" -o ! -f "${FILE}" ]; then
444.26.4 by graziano
We weren't checking the exit status after connecting (or trying) to the
688
	echo "$FILE is not a valid eucalyptus configuration file"
689
	exit  1
1 by graziano obertelli
from CVS
690
fi
691
198.10.12 by graziano obertelli
-check now requires a parameter (cc, nc or cloud).
692
# if asked to print the version that's all we do
693
if [ "$VERSION" = "Y" ]; then
1054.1.3 by Dave Walker (Daviey)
Ubuntu patches applied
694
	. $DEFAULTS_FILE
444.26.4 by graziano
We weren't checking the exit status after connecting (or trying) to the
695
	. $FILE
198.10.12 by graziano obertelli
-check now requires a parameter (cc, nc or cloud).
696
444.26.4 by graziano
We weren't checking the exit status after connecting (or trying) to the
697
	if [ -e $EUCALYPTUS/etc/eucalyptus/eucalyptus-version ]; then
698
		VERSION="$EUCALYPTUS/etc/eucalyptus/eucalyptus-version"
699
	elif [ -e @prefix@/etc/eucalyptus/eucalyptus-version ]; then
700
		VERSION="@prefix@/etc/eucalyptus/eucalyptus-version"
701
	fi
702
	if [ -n "$VERSION" ]; then
703
		echo -n "Eucalyptus version: "
704
		cat $VERSION 
705
	else
706
		echo "Cannot find eucalyptus installation!"
707
		exit 1
708
	fi
709
	exit 0
198.10.12 by graziano obertelli
-check now requires a parameter (cc, nc or cloud).
710
fi
198.10.1 by graziano obertelli
Few details/minor bugs:
711
1 by graziano obertelli
from CVS
712
# let's change the value
713
if [ -n "$EUCALYPTUS" ]; then
444.26.4 by graziano
We weren't checking the exit status after connecting (or trying) to the
714
	change_var_value $FILE EUCALYPTUS "${EUCALYPTUS}"
1 by graziano obertelli
from CVS
715
fi
716
if [ -n "$CC_PORT" ]; then
717
	change_var_value $FILE CC_PORT "${CC_PORT}"
718
fi
719
if [ -n "$NC_PORT" ]; then
720
	change_var_value $FILE NC_PORT "${NC_PORT}"
721
fi
722
if [ -n "$CLOUD_PORT" ]; then
723
	change_var_value $FILE CLOUD_PORT "${CLOUD_PORT}"
724
fi
725
if [ -n "$CLOUD_SSL_PORT" ]; then
726
	change_var_value $FILE CLOUD_SSL_PORT "${CLOUD_SSL_PORT}"
727
fi
728
if [ -n "$INSTANCE" ]; then
729
	change_var_value $FILE INSTANCE_PATH "${INSTANCE}"
730
fi
154 by graziano obertelli
added option to change dhcp user
731
if [ -n "$DHCPD" ]; then
732
	change_var_value $FILE VNET_DHCPDAEMON "${DHCPD}"
733
fi
734
if [ -n "$DHCPC_USER" ]; then
735
	change_var_value $FILE VNET_DHCPUSER "${DHCPC_USER}"
180 by graziano obertelli
Added uncomment: right now it's used only for not yet publicly known
736
	uncomment $FILE VNET_DHCPUSER
140 by graziano obertelli
added options to set dhcpcd binary
737
fi
1 by graziano obertelli
from CVS
738
if [ -n "$NODES" ]; then
739
	change_var_value $FILE NODES "${NODES}"
740
fi
25.1.111 by graziano obertelli
damn bzr revert: readded the code to handle HYPERVISOR and EUCA_USER
741
if [ -n "$HYPERVISOR" ]; then
742
	change_var_value $FILE HYPERVISOR "${HYPERVISOR}"
180 by graziano obertelli
Added uncomment: right now it's used only for not yet publicly known
743
	uncomment $FILE HYPERVISOR
25.1.111 by graziano obertelli
damn bzr revert: readded the code to handle HYPERVISOR and EUCA_USER
744
fi
198.1.169 by graziano obertelli
Small adjustement to spec files for 1.5.2.
745
if [ -n "$BRIDGE" ]; then
746
	change_var_value $FILE VNET_BRIDGE "${BRIDGE}"
747
	uncomment $FILE VNET_BRIDGE
748
fi
25.1.111 by graziano obertelli
damn bzr revert: readded the code to handle HYPERVISOR and EUCA_USER
749
if [ -n "$EUCA_USER" ]; then
198.10.8 by graziano obertelli
when changing EUCA_USER check if the user exists and warn the user if it
750
	ID="`which id 2> /dev/null`"
751
	if [ -n "$ID" ]; then
752
		if ! $ID $EUCA_USER > /dev/null 2> /dev/null ; then
753
			echo "WARNING: $EUCA_USER doesn't exists!"
754
		fi
755
	fi
25.1.111 by graziano obertelli
damn bzr revert: readded the code to handle HYPERVISOR and EUCA_USER
756
	change_var_value $FILE EUCA_USER "${EUCA_USER}"
757
fi
198.10.2 by graziano obertelli
Previous patch fixed also the init.d script trying to start services even
758
for x in $NAME ; do
759
	VALUE=`cat $FILE |grep $x|cut -f 2 -d =|tr  '"' ' '`
760
	echo "$x=$VALUE"
761
done
198.1.120 by graziano obertelli
We need to remove the semaphore on start/stop of the CC/NC. Added upgrade
762
444.1.398 by root
added 'import-conf' flag to euca_conf, to handle automated registration process parameter import in Ubuntu
763
# modify the current conf file based on an older configuration, or from import file
764
if [ -n "$UPGRADE_CONF" -o -n "$IMPORTFILE" ]; then
444.16.68 by graziano
More on the upgrade path from 1.5.
765
	VARS="EUCA_USER ENABLE_WS_SECURITY DISABLE_EBS HYPERVISOR LOGLEVEL SWAP_SIZE CC_PORT MANUAL_INSTANCES_CLEANUP NC_CACHE_SIZE SCHEDPOLICY NODES NC_SERVICE NC_PORT MAX_MEM MAX_CORES INSTANCE_PATH VNET_BRIDGE VNET_DHCPDAEMON VNET_DHCPUSER"
444.57.3 by root
Adds import of VNET_CLOUDIP and VNET_LOCALIP to euca_conf --import-conf
766
	VNET_VARS="VNET_MODE VNET_SUBNET VNET_NETMASK VNET_DNS VNET_ADDRSPERNET VNET_PUBLICIPS VNET_BROADCAST VNET_ROUTER VNET_MACMAP VNET_INTERFACE VNET_CLOUDIP VNET_LOCALIP"
309 by graziano
added --list-services, --enable-service and --disable-service to euca_conf
767
	
444.1.398 by root
added 'import-conf' flag to euca_conf, to handle automated registration process parameter import in Ubuntu
768
	if [ -n "$UPGRADE_CONF" ]; then
309 by graziano
added --list-services, --enable-service and --disable-service to euca_conf
769
	# source the old config
444.1.398 by root
added 'import-conf' flag to euca_conf, to handle automated registration process parameter import in Ubuntu
770
	    VARS_TO_DO=$VARS
771
	    VNET_VARS_TO_DO=$VNET_VARS
772
	    . $UPGRADE_CONF
773
	elif [ -n "$IMPORTFILE" ]; then
774
	    VARS_TO_DO=""
775
	    VNET_VARS_TO_DO=""
776
	    . $IMPORTFILE
777
	    for i in $VNET_VARS
778
	    do
779
		VAL="$(echo \$${i})"
780
		eval VAL=$VAL
781
		if [ -n "$VAL" ]; then
782
		    VNET_VARS_TO_DO="$VNET_VARS_TO_DO $i"
783
		fi
784
	    done
785
	fi
309 by graziano
added --list-services, --enable-service and --disable-service to euca_conf
786
787
	# let's start from no network
444.1.398 by root
added 'import-conf' flag to euca_conf, to handle automated registration process parameter import in Ubuntu
788
	for x in $VNET_VARS_TO_DO ; do
789
	    comment $FILE $x
309 by graziano
added --list-services, --enable-service and --disable-service to euca_conf
790
	done
444.1.398 by root
added 'import-conf' flag to euca_conf, to handle automated registration process parameter import in Ubuntu
791
	
309 by graziano
added --list-services, --enable-service and --disable-service to euca_conf
792
	# modified the defined variables
444.1.398 by root
added 'import-conf' flag to euca_conf, to handle automated registration process parameter import in Ubuntu
793
	for x in $VARS_TO_DO ; do
794
	    y="$(echo \$${x})"
795
	    eval y="$y"
796
	    if [ -z "$y" ]; then
309 by graziano
added --list-services, --enable-service and --disable-service to euca_conf
797
			# we just leave NODES uncommented even if it's empty
444.1.398 by root
added 'import-conf' flag to euca_conf, to handle automated registration process parameter import in Ubuntu
798
		    if [ "$x" != "NODES" ]; then
799
			comment $FILE $x
800
		    fi
801
	    else
802
		uncomment $FILE $x
803
		change_var_value $FILE $x "${y}"
804
	    fi
309 by graziano
added --list-services, --enable-service and --disable-service to euca_conf
805
	done
806
	# and add the network variables
807
	echo >> $FILE
444.1.398 by root
added 'import-conf' flag to euca_conf, to handle automated registration process parameter import in Ubuntu
808
	echo "# network configuration from the input configuration file" >> $FILE
809
	for x in $VNET_VARS_TO_DO ; do
810
	    y="$(echo \$${x})"
811
	    eval y="$y"
812
	    if [ -n "$y" ]; then
444.16.68 by graziano
More on the upgrade path from 1.5.
813
		if [ "$x" = "VNET_INTERFACE" ]; then
444.16.117 by graziano
Fix double VNET_PRIVINTERFACE VNET_PUBINTERFACE.
814
			change_var_value $FILE VNET_PRIVINTERFACE "${y}"
815
			change_var_value $FILE VNET_PUBINTERFACE "${y}"
444.16.68 by graziano
More on the upgrade path from 1.5.
816
		else
817
			echo "$x=\"${y}\"" >> $FILE
818
		fi
444.1.398 by root
added 'import-conf' flag to euca_conf, to handle automated registration process parameter import in Ubuntu
819
	    fi
309 by graziano
added --list-services, --enable-service and --disable-service to euca_conf
820
	done
821
fi
444.1.400 by graziano
same spacing in the help message.
822
308 by graziano
better handling of the sync the keys problem.
823
# we may need the location of the ssh key for eucalyptus
824
EUCA_HOME="`getent passwd eucalyptus|cut -f 6 -d ':'`"
825
if [ -f "${EUCA_HOME}/.ssh/id_rsa.pub" ]; then
826
	SSHKEY=`cat ${EUCA_HOME}/.ssh/id_rsa.pub`
827
else
828
	SSHKEY=""
829
fi
830
309 by graziano
added --list-services, --enable-service and --disable-service to euca_conf
831
# we need defaults in eucalyptus.conf
1054.1.3 by Dave Walker (Daviey)
Ubuntu patches applied
832
. $DEFAULTS_FILE
309 by graziano
added --list-services, --enable-service and --disable-service to euca_conf
833
. $FILE
1054.1.3 by Dave Walker (Daviey)
Ubuntu patches applied
834
# get node from nodes.list if it exists
835
if [ -e "$EUCALYPTUS/var/lib/eucalyptus/nodes.list" ]; then
836
    NODES=`cat $EUCALYPTUS/var/lib/eucalyptus/nodes.list`
837
fi
309 by graziano
added --list-services, --enable-service and --disable-service to euca_conf
838
198.1.143 by graziano obertelli
a more helpful message when eucalyptus is removed but not purged.
839
# first time setup
840
if [ -n "$SETUP" ]; then
198.10.17 by graziano obertelli
euca_*wrap does not belong to usr/share/eucalyptus but in usr/lib/eucalyptys.
841
	ROOTWRAP="$EUCALYPTUS/usr/lib/eucalyptus/euca_rootwrap"
198.1.143 by graziano obertelli
a more helpful message when eucalyptus is removed but not purged.
842
	
843
	# first of all setup euca_rootwrap
844
	if [ ! -x "$ROOTWRAP" ]; then
198.10.12 by graziano obertelli
-check now requires a parameter (cc, nc or cloud).
845
		echo "Cannot find $ROOTWRAP (or not readable)!"
198.1.143 by graziano obertelli
a more helpful message when eucalyptus is removed but not purged.
846
		exit 1
847
	fi
848
	# get EUCA group
849
	if [ -z "$EUCA_USER" ]; then
850
		echo "Is EUCA_USER defined?"
851
		exit 1
852
	fi
853
	# if running as root no need to do anything
854
	if [ "$EUCA_USER" != "root" ]; then
855
		ID="`which id 2> /dev/null`"
856
		if [ -z "$ID" ]; then
857
			echo "Cannot find command $ID"
858
			exit 1
859
		fi
860
		if ! $ID $EUCA_USER > /dev/null 2> /dev/null ; then
861
			echo "User $EUCA_USER doesn't exists!"
862
			exit 1
863
		fi
864
		EUCA_GROUP="`$ID -ng $EUCA_USER 2>/dev/null`"
865
		if [ -z "$EUCA_GROUP" ]; then
444.1.96 by graziano
Don't change permissions in the init script (only /var/run since it could
866
			echo "Cannot detect $EUCA_USER group"
867
			exit 1
868
		fi
869
		if ! chown root:$EUCA_GROUP $ROOTWRAP ; then
870
			exit 1
871
		fi
872
		if ! chmod 4750 $ROOTWRAP ; then
873
			exit 1
874
		fi
198.1.143 by graziano obertelli
a more helpful message when eucalyptus is removed but not purged.
875
	fi
876
	
877
	# let's create the instance path
878
	if [ -n "$INSTANCE_PATH" -a "$INSTANCE_PATH" != "not_configured" -a ! -d "$INSTANCE_PATH" ]; then
879
		if ! mkdir -p $INSTANCE_PATH ; then
880
			echo "Failed to create instance path!"
881
			exit 1
882
		fi
444.1.96 by graziano
Don't change permissions in the init script (only /var/run since it could
883
		if ! chown $EUCA_USER:$EUCA_GROUP $INSTANCE_PATH ; then
884
			exit 1
885
		fi
198.1.143 by graziano obertelli
a more helpful message when eucalyptus is removed but not purged.
886
	fi
198.10.22 by graziano obertelli
Small fixes during testing.
887
444.1.76 by root
change -setup to set ownership of files in $EUCALYPTUS/var/*/eucalyptus to EUCA_USER
888
	chown -R $EUCA_USER:$EUCA_GROUP $EUCALYPTUS/var/lib/eucalyptus
444.1.96 by graziano
Don't change permissions in the init script (only /var/run since it could
889
	ret=$?
444.1.76 by root
change -setup to set ownership of files in $EUCALYPTUS/var/*/eucalyptus to EUCA_USER
890
	chown -R $EUCA_USER:$EUCA_GROUP $EUCALYPTUS/var/log/eucalyptus
444.1.96 by graziano
Don't change permissions in the init script (only /var/run since it could
891
	let $((ret += $?))
444.1.76 by root
change -setup to set ownership of files in $EUCALYPTUS/var/*/eucalyptus to EUCA_USER
892
	chown -R $EUCA_USER:$EUCA_GROUP $EUCALYPTUS/var/run/eucalyptus
444.1.96 by graziano
Don't change permissions in the init script (only /var/run since it could
893
	let $((ret += $?))
444.26.4 by graziano
We weren't checking the exit status after connecting (or trying) to the
894
	chown $EUCA_USER:$EUCA_GROUP $EUCALYPTUS/etc/eucalyptus/eucalyptus.conf
444.16.24 by graziano
Fixes 462940. Be sure that eucalyptus.conf is owned by eycalyptus user.
895
	let $((ret += $?))
444.1.76 by root
change -setup to set ownership of files in $EUCALYPTUS/var/*/eucalyptus to EUCA_USER
896
198.10.22 by graziano obertelli
Small fixes during testing.
897
	# let's create more needed directory with the right permissions
898
	mkdir -p $EUCALYPTUS/var/lib/eucalyptus/db
444.1.96 by graziano
Don't change permissions in the init script (only /var/run since it could
899
	let $((ret += $?))
900
	chown $EUCA_USER:$EUCA_GROUP $EUCALYPTUS/var/lib/eucalyptus/db
901
	let $((ret += $?))
198.10.22 by graziano obertelli
Small fixes during testing.
902
	chmod 700 $EUCALYPTUS/var/lib/eucalyptus/db
444.1.96 by graziano
Don't change permissions in the init script (only /var/run since it could
903
	let $((ret += $?))
198.10.22 by graziano obertelli
Small fixes during testing.
904
	mkdir -p $EUCALYPTUS/var/lib/eucalyptus/keys
444.1.96 by graziano
Don't change permissions in the init script (only /var/run since it could
905
	let $((ret += $?))
906
	chown $EUCA_USER:$EUCA_GROUP $EUCALYPTUS/var/lib/eucalyptus/keys
907
	let $((ret += $?))
198.10.22 by graziano obertelli
Small fixes during testing.
908
	chmod 700 $EUCALYPTUS/var/lib/eucalyptus/keys
444.1.96 by graziano
Don't change permissions in the init script (only /var/run since it could
909
	let $((ret += $?))
286 by root
added ability for CC to stay up between reboots/restarts (eucalyptus-cc reload will reset, start/stop maintain on disk state)
910
	mkdir -p $EUCALYPTUS/var/lib/eucalyptus/CC
444.1.96 by graziano
Don't change permissions in the init script (only /var/run since it could
911
	let $((ret += $?))
912
	chown $EUCA_USER:$EUCA_GROUP $EUCALYPTUS/var/lib/eucalyptus/CC
913
	let $((ret += $?))
286 by root
added ability for CC to stay up between reboots/restarts (eucalyptus-cc reload will reset, start/stop maintain on disk state)
914
	chmod 700 $EUCALYPTUS/var/lib/eucalyptus/CC
444.1.96 by graziano
Don't change permissions in the init script (only /var/run since it could
915
	let $((ret += $?))
916
444.1.100 by root
euca_conf -setup 'return' was causing parse error, changed to 'exit'
917
	exit $ret
198.1.143 by graziano obertelli
a more helpful message when eucalyptus is removed but not purged.
918
fi
919
444.1.322 by root
fixed TOSYNC bug
920
if [ -n "$TOSYNC" ]; then
921
    echo "not implemented"
922
fi
923
198.10.3 by graziano obertelli
Added -check and -setup to euca_conf:
924
# pre-flight checks
925
if [ -n "$CHECK" ]; then
198.10.17 by graziano obertelli
euca_*wrap does not belong to usr/share/eucalyptus but in usr/lib/eucalyptys.
926
	ROOTWRAP="$EUCALYPTUS/usr/lib/eucalyptus/euca_rootwrap"
198.10.12 by graziano obertelli
-check now requires a parameter (cc, nc or cloud).
927
928
	# vblade and aoe may be needed
198.1.165 by graziano obertelli
vblade needs to be checked only for the cloud.
929
	if [ "$DISABLE_EBS" != "Y" -a "$DISABLE_EBS" != "y" ]; then
313 by graziano
Added new script to start/stop walrus and sc
930
		if [ "$CHECK" = "sc" ]; then
198.1.165 by graziano obertelli
vblade needs to be checked only for the cloud.
931
			VBLADE="`which vblade 2> /dev/null`"
932
			if [ -z "$VBLADE" ]; then
933
				echo
444.1.176 by graziano
If vblade is not found we should stop.
934
				echo "ERROR: EBS is enabled and vblade was not found"
935
				exit 1
198.1.165 by graziano obertelli
vblade needs to be checked only for the cloud.
936
			fi
198.10.12 by graziano obertelli
-check now requires a parameter (cc, nc or cloud).
937
		fi
938
	fi
198.10.4 by graziano obertelli
Suggest the user to run euca_conf -setup if the INSTANCE path is not
939
	
198.10.3 by graziano obertelli
Added -check and -setup to euca_conf:
940
	# first of all check euca_rootwrap
941
	if [ ! -x $ROOTWRAP ]; then
942
		echo "Cannot find euca_rootwrap!"
943
		exit 1
944
	fi
945
	# get EUCA group
946
	if [ -z "$EUCA_USER" ]; then
947
		echo "Running eucalyptus as root"
948
		EUCA_USER="root"
949
		EUCA_GROUP="root"
950
	fi
951
	# if running as root no need to do anything
952
	if [ "$EUCA_USER" != "root" ]; then
953
		ID="`which id 2> /dev/null`"
954
		if [ -z "$ID" ]; then
305 by graziano
Added stubs for new options.
955
			echo "Cannot find command id"
198.10.3 by graziano obertelli
Added -check and -setup to euca_conf:
956
			exit 1
957
		fi
958
		if ! $ID $EUCA_USER > /dev/null 2> /dev/null ; then
959
			echo "User $EUCA_USER doesn't exists!"
960
			exit 1
961
		fi
962
		EUCA_GROUP="`$ID -ng $EUCA_USER 2>/dev/null`"
963
		if [ -z "$EUCA_GROUP" ]; then
964
			echo "Cannot detect $EUCA_USER group: using $EUCA_USER"
965
			exit 1
966
		fi
967
		# need to check if euca_rootwrap can run as EUCA_USER
444.47.3 by root
update version in spec file to 1.6.2, choose more distro-generic way of checking euca_rootwrap functionality in euca_conf
968
                TEST_EUID="`sudo -u $EUCA_USER $ROOTWRAP $ID -u`"
198.10.3 by graziano obertelli
Added -check and -setup to euca_conf:
969
		if [ "$?" != "0" -o "$TEST_EUID" != "0" ]; then
198.10.4 by graziano obertelli
Suggest the user to run euca_conf -setup if the INSTANCE path is not
970
			echo "Problem running $ROOTWRAP! Did you run euca_conf -setup?"
198.10.3 by graziano obertelli
Added -check and -setup to euca_conf:
971
			exit 1
972
		fi
973
	fi
974
198.10.15 by graziano obertelli
move the INSTANCE_PATH check into -check
975
	# let's be sure we have the INSTANCE_PATH
976
	if [ "$CHECK" = "nc" ]; then
977
		if [ -z "$INSTANCE_PATH" ]; then
978
			echo "INSTANCE_PATH is not defined"
979
			exit 1
980
		fi
981
		if [ ! -d "$INSTANCE_PATH" ]; then
982
			echo "$INSTANCE_PATH doesn't exist: did you run euca_conf -setup?"
983
			exit 1
984
		fi
985
	fi
986
198.10.3 by graziano obertelli
Added -check and -setup to euca_conf:
987
	# let's set up directories which could disappears if /var/run is
988
	# in memory
444.1.96 by graziano
Don't change permissions in the init script (only /var/run since it could
989
	if [ ! -d $EUCALYPTUS/var/run/eucalyptus ]; then
990
		if ! mkdir -p $EUCALYPTUS/var/run/eucalyptus ; then
991
			# error should come from mkdir
992
			exit 1
993
		fi
444.1.328 by root
move the chown of /var/run/eucalyptus after directory exists check
994
	fi
995
	if ! chown $EUCA_USER:$EUCA_GROUP $EUCALYPTUS/var/run/eucalyptus ; then
996
	    # error should come from chown
997
	    exit 1
998
	fi
999
198.10.3 by graziano obertelli
Added -check and -setup to euca_conf:
1000
444.1.129 by root
register-walrus uses 'walrus' as the 'Name', added mkdir $EUCALYPTUS/var/run/eucalyptus/net in euca_conf when check cc is called, added modules/rampart to LD_LIBRARY_PATH in init scripts
1001
	if [ "$CHECK" = "cc" ]; then
1002
	    if [ ! -d $EUCALYPTUS/var/run/eucalyptus/net ]; then
1003
		if ! mkdir -p $EUCALYPTUS/var/run/eucalyptus/net ; then
1004
			# error should come from mkdir
1005
		    exit 1
1006
		fi
444.1.328 by root
move the chown of /var/run/eucalyptus after directory exists check
1007
	    fi
1008
	    if ! chown $EUCA_USER:$EUCA_GROUP $EUCALYPTUS/var/run/eucalyptus/net ; then
444.1.129 by root
register-walrus uses 'walrus' as the 'Name', added mkdir $EUCALYPTUS/var/run/eucalyptus/net in euca_conf when check cc is called, added modules/rampart to LD_LIBRARY_PATH in init scripts
1009
			# error should come from chown
444.1.328 by root
move the chown of /var/run/eucalyptus after directory exists check
1010
		exit 1
444.1.129 by root
register-walrus uses 'walrus' as the 'Name', added mkdir $EUCALYPTUS/var/run/eucalyptus/net in euca_conf when check cc is called, added modules/rampart to LD_LIBRARY_PATH in init scripts
1011
	    fi
1012
	fi
444.1.96 by graziano
Don't change permissions in the init script (only /var/run since it could
1013
	# good to go
1014
	exit 0
198.10.3 by graziano obertelli
Added -check and -setup to euca_conf:
1015
fi
1016
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
1017
createCloudURL () {
444.1.30 by root
added some registration code, made euca_ipt a bit more efficient
1018
    if ! getSecretKey; then
1019
	echo "ERROR: cannot get credentials"
1020
	return 1
1021
    fi
443 by root
changed up a bit
1022
    ARGS="AWSAccessKeyId=$AKEY"
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
1023
    KEY=$1
1024
    shift
1025
    VAL=$1
1026
    shift
1027
    while ( test -n "$KEY" -a -n "$VAL")
1028
    do
443 by root
changed up a bit
1029
	ARGS="${ARGS}&${KEY}=${VAL}"
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
1030
	KEY=$1
1031
	shift
1032
	VAL=$1
1033
	shift
1034
    done
1035
    if [ -z "$SKEY" ]; then
444.1.30 by root
added some registration code, made euca_ipt a bit more efficient
1036
	echo "ERROR: SKEY parameter is not set."
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
1037
	export URL=""
1038
	return 1
1039
    fi
444.10.12 by decker
fix the timestamp formatting in euca conf to use UTC
1040
    ARGS="${ARGS}&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=$(date -u '+%Y-%m-%dT%H%%3A%M%%3A%S.000Z')&Version=eucalyptus"
443 by root
changed up a bit
1041
    SIGNATURE=$(echo -en "GET\n127.0.0.1\n/services/Configuration\n${ARGS}" | openssl dgst -sha256 -hmac ${SKEY} -binary | openssl base64)
1042
    export URL="http://127.0.0.1:8773/services/Configuration?${ARGS}&Signature=${SIGNATURE}"
444.1.342 by graziano
better handling of --register-* in euca_conf
1043
	if [ "$VERBOSE" = "Y" ]; then
1044
		echo $URL
1045
	fi
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
1046
    return 0
1047
}
1048
1049
getSecretKey() {
415 by root
more stubbing out for fake registration mode
1050
    if [ -d "$EUCALYPTUS/var/lib/eucalyptus/db/" ]; then
1051
	DBDIR="$EUCALYPTUS/var/lib/eucalyptus/db/"
1052
    else
1053
	echo "ERROR: cannot locate eucalyptus database, try logging in through the admin web interface."
1054
	exit 1
1055
    fi
1056
444.66.163 by decker
fix issues with get credentials
1057
    FIELD=`grep -i "CREATE .*TABLE AUTH_USERS" ${DBDIR}/*auth* | sed 's/,/\n/g' | awk '/[Aa][Uu][Tt][Hh]_[Uu][Ss][Ee][Rr]_[Ss][Ee][Cc][Rr][Ee][Tt][Kk][Ee][Yy]/ {print NR}'`
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
1058
    if [ "$FIELD" = "" ]; then
1059
	echo "ERROR: cannot locate entry in eucalyptus database, try logging in through the admin web interface"
1060
	export SKEY=""
1061
	return 1
1062
    fi
444.66.151 by decker
fix the database that is used for groups
1063
    SKEY=$(eval echo $(awk -v field=${FIELD} -F, '/INSERT INTO AUTH_USERS.*admin/ {print $field}' ${DBDIR}/*auth* | head -n 1 | sed 's/[()]//g'))
443 by root
changed up a bit
1064
444.66.163 by decker
fix issues with get credentials
1065
   FIELD=`grep -i "CREATE .*TABLE AUTH_USERS" ${DBDIR}/*auth* | sed 's/,/\n/g' | awk '/[Aa][Uu][Tt][Hh]_[Uu][Ss][Ee][Rr]_[Qq][Uu][Ee][Rr][Yy]_[Ii][Dd]/ {print NR}'`
443 by root
changed up a bit
1066
   if [ "$FIELD" = "" ]; then
1067
     echo "ERROR: cannot locate entry in eucalyptus database, try logging in through the admin web interface"
1068
     export AKEY=""
1069
     return 1
1070
   fi
444.66.169 by decker
intermediate version; fixing tracking of old certificates
1071
   AKEY=$(eval echo $(awk -v field=${FIELD} -F, '/INSERT INTO AUTH_USERS.*admin/ {print $field}' ${DBDIR}/*auth* | head -n 1 | sed 's/[()]//g'))
443 by root
changed up a bit
1072
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
1073
    return 0
1074
}
1075
1076
checkLocalService() {
1077
    local SERVICE=""
414 by root
enabled 'fakeregisteration' mode in euca_conf, added 'eucalyptus-cloud' loader support into init scripts for cloud, walrus, sc
1078
    
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
1079
    if [ -z "$WGET" -o ! -x "$WGET" ]; then
1080
	echo "ERROR: wget is missing, cannot continue."
1081
	return 1
1082
    fi
1083
1084
    SERVICE="$1"
1085
    if [ -z "$SERVICE" ]; then
1086
	echo "ERROR: must pass in service name (CLC, CC)"
1087
	return 1
1088
    elif [ "$SERVICE" = "CLC" ]; then
415 by root
more stubbing out for fake registration mode
1089
	if [ -n "$FAKEREG" ]; then
1090
	    local SOURCEDIR="$EUCALYPTUS/var/lib/eucalyptus/keys/"
1091
	    for i in cloud
1092
	    do 
1093
		if [ ! -e "$SOURCEDIR/${i}-cert.pem" -o ! -e "$SOURCEDIR/${i}-pk.pem" ]; then
1094
		    openssl req -new -nodes -x509 -out $SOURCEDIR/${i}-cert.pem -keyout $SOURCEDIR/${i}-pk.pem -days 365 -subj "/C=US/ST=CA/L=City/CN=localhost/emailAddress=root@localhost"
1095
		fi
1096
	    done
1097
	fi
444.1.8 by root
better pidfile handling for vtund, new cluster register logic in euca_conf
1098
	
444.36.2 by root
cleaned up euca_conf a bit for better error reporting, key syncing, and wgetting
1099
	CMD="$WGET -T 10 -t 1 -O - -q --no-check-certificate https://127.0.0.1:8443/register | grep CloudVersion >/dev/null"
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
1100
    elif [ "$SERVICE" = "CC" ]; then
444.36.3 by root
fix bug in node-register
1101
	CMD="$WGET -T 10 -t 1 -O - -q http://127.0.0.1:8774/axis2/services/ | grep EucalyptusCC >/dev/null"
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
1102
    fi
1103
    
414 by root
enabled 'fakeregisteration' mode in euca_conf, added 'eucalyptus-cloud' loader support into init scripts for cloud, walrus, sc
1104
    if [ -n "${FAKEREG}" ]; then
1105
	CMD="echo"
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
1106
    fi
414 by root
enabled 'fakeregisteration' mode in euca_conf, added 'eucalyptus-cloud' loader support into init scripts for cloud, walrus, sc
1107
    if ! eval $CMD ; then
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
1108
	echo "ERROR: you need to be on the $SERVICE host and the $SERVICE needs to be running."
1109
	return 1
1110
    fi  
1111
    return 0
1112
}
1113
444.1.207 by root
added 'get-credentials' option to euca_conf for app store integration
1114
if [ -n "$CREDENTIALZIPFILE" ]; then
1115
    if [ -f "$CREDENTIALZIPFILE" ]; then
1116
	echo "file '$CREDENTIALZIPFILE' already exists, please remove and try again"
1117
	exit 1
1118
    fi
1119
    if ! checkLocalService "CLC" ; then
1120
	exit 1
1121
    fi
1122
1123
    if [ -d "$EUCALYPTUS/var/lib/eucalyptus/db/" ]; then
1124
	DBDIR="$EUCALYPTUS/var/lib/eucalyptus/db/"
1125
    else
1126
	echo "ERROR: cannot locate eucalyptus database, try logging in through the admin web interface."
1127
        exit 1
1128
    fi
444.66.163 by decker
fix issues with get credentials
1129
    FIELD=`grep -i "CREATE .*TABLE AUTH_USERS" ${DBDIR}/* | sed 's/,/\n/g' | awk '/[Aa][Uu][Tt][Hh]_[Uu][Ss][Ee][Rr]_[Tt][Oo][Kk][Ee][Nn]/ {print NR}'`
444.1.207 by root
added 'get-credentials' option to euca_conf for app store integration
1130
    if [ -z "$FIELD" ]; then
1131
	echo "cannot find code field in database, please go to the Eucalyptus web UI to obtain credentials."
1132
	exit 1
1133
    fi
444.75.41 by wenye
Fix euca_conf --get-credentials (frequently calling this function would fail).
1134
    VERCOL=`grep -i "CREATE .*TABLE AUTH_USERS" ${DBDIR}/* | sed 's/,/\n/g' | awk '/[Vv][Ee][Rr][Ss][Ii][Oo][Nn]/ {print NR}'`
1135
    if [ -z "$VERCOL" ]; then
1136
	echo "cannot find version field in database, please go to the Eucalyptus web UI to obtain credentials."
1137
	exit 1
1138
    fi
444.72.47 by wenye
Fix euca_conf --get-credentials.
1139
    KEY=$(eval echo $(awk -v field=${FIELD} -v vercol=${VERCOL} -F, 'BEGIN { token=""; max=-1; } /INSERT INTO AUTH_USERS.*admin/ { if ($vercol>max) { max=$vercol; token=$field; } } END { print token; }' ${DBDIR}/* | head -n 1 | sed 's/[()]//g'))
444.1.207 by root
added 'get-credentials' option to euca_conf for app store integration
1140
    if [ -z "$KEY" ]; then
1141
	echo "cannot find code in database, please go to the Eucalyptus web UI to obtain credentials."
1142
	exit 1
1143
    fi
1144
    CMD="$WGET --no-check-certificate \"https://localhost:8443/getX509?user=admin&code=$KEY\" -O $CREDENTIALZIPFILE"
1145
    if ! eval $CMD ; then
444.1.342 by graziano
better handling of --register-* in euca_conf
1146
	echo "failed to obtain credentals, please try again or go to the Eucalyptus web UI."
444.1.207 by root
added 'get-credentials' option to euca_conf for app store integration
1147
	exit 1
1148
    fi
1149
fi
1150
198.1.120 by graziano obertelli
We need to remove the semaphore on start/stop of the CC/NC. Added upgrade
1151
# adding a new cluster
444.1.33 by root
added 'deregister' to euca_conf, eucalyptus-dns handling from eucalyptus.conf
1152
if [ -n "$CLUSNAME" ]; then
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
1153
    if ! checkLocalService "CLC" ; then
1154
	exit 1
1155
    fi
444.1.33 by root
added 'deregister' to euca_conf, eucalyptus-dns handling from eucalyptus.conf
1156
1157
    if [ "$CLUSMODE" = "ADD" ]; then
1158
	if [ -d "${EUCALYPTUS}/var/lib/eucalyptus/keys/" ]; then
1159
	    SOURCEDIR=${EUCALYPTUS}/var/lib/eucalyptus/keys/${CLUSNAME}/
1160
	    DESTDIR=${EUCALYPTUS}/var/lib/eucalyptus/keys/
1161
	else
1162
	    echo "ERROR: cannot find key directory ($EUCALYPTUS/var/lib/eucalyptus/keys), check that your installation was successful!"
1163
	    exit 1
1164
	fi
1165
	
1166
	URL=""
1167
	if ! createCloudURL "Action" "RegisterCluster" "Host" "${NEWCLUS}" "Name" "${CLUSNAME}" "Port" "${CC_PORT}"; then
1168
	    exit 1
1169
	fi
1170
	
444.1.342 by graziano
better handling of --register-* in euca_conf
1171
	if ! check_ws "$URL" ; then
1172
		echo "ERROR: failed to register new cluster, please log in to the admin interface and check cloud status."
1173
		exit 1
444.1.33 by root
added 'deregister' to euca_conf, eucalyptus-dns handling from eucalyptus.conf
1174
	fi
1175
	
415 by root
more stubbing out for fake registration mode
1176
	if [ -n "${FAKEREG}" ]; then
1177
	    mkdir -p $SOURCEDIR
444.1.33 by root
added 'deregister' to euca_conf, eucalyptus-dns handling from eucalyptus.conf
1178
	    if [ -n "${FAKEREG}" ]; then
1179
		mkdir -p $SOURCEDIR
1180
		for i in cluster node
1181
		do 
1182
		    if [ ! -e "$SOURCEDIR/${i}-cert.pem" -o ! -e "$SOURCEDIR/${i}-pk.pem" ]; then
1183
			openssl req -new -nodes -x509 -out $SOURCEDIR/${i}-cert.pem -keyout $SOURCEDIR/${i}-pk.pem -days 365 -subj "/C=US/ST=CA/L=City/CN=localhost/emailAddress=root@localhost"
1184
		    fi
1185
		done
1186
	    fi
415 by root
more stubbing out for fake registration mode
1187
	fi
444.1.33 by root
added 'deregister' to euca_conf, eucalyptus-dns handling from eucalyptus.conf
1188
	
444.36.2 by root
cleaned up euca_conf a bit for better error reporting, key syncing, and wgetting
1189
        # sync the keys
444.38.16 by root
sync keys from DESTDIR first, then SOURCEDIR (SOURCEDIR gets priority)
1190
	if ! sync_keys "${DESTDIR},${SOURCEDIR}" ${DESTDIR} ${NEWCLUS} node-cert.pem cluster-cert.pem cluster-pk.pem node-pk.pem vtunpass cloud-cert.pem; then
444.36.2 by root
cleaned up euca_conf a bit for better error reporting, key syncing, and wgetting
1191
	    echo "ERROR: failed to sync keys with ${NEWCLUS}; registration will not be complete until keys can be synced, please try again."
1192
	    exit 1
444.1.33 by root
added 'deregister' to euca_conf, eucalyptus-dns handling from eucalyptus.conf
1193
	fi
1194
	echo
1195
	echo "SUCCESS: new cluster '${CLUSNAME}' on host '${NEWCLUS}' successfully registered."
1196
    elif [ "$CLUSMODE" = "DEL" ]; then
1197
	URL=""
444.1.349 by graziano obertelli
Deregistering a non-existent cluster (or sc) will now print an error
1198
	# let's see if we have such a cluster
1199
	LIST_RES=""
1200
	if ! createCloudURL "Action" "DescribeClusters" ; then
1201
		exit 1
1202
	fi
1203
	if ! check_ws "$URL" LIST_RES ; then
1204
		echo "ERROR: cannot talk with CLC"
1205
		exit 1
1206
	fi
1207
	FOUND="N"
1208
	for x in $LIST_RES ; do
1209
		if [ "$x" = "${CLUSNAME}" ]; then
1210
			FOUND="Y"
1211
			break
1212
		fi
1213
	done
1214
	if [ "$FOUND" = "N" ]; then
1215
		echo "No registered cluster $CLUSNAME was found"
1216
		exit 1
1217
	fi
1218
1219
	# now let's deregister
1220
	URL=""
444.1.33 by root
added 'deregister' to euca_conf, eucalyptus-dns handling from eucalyptus.conf
1221
	if ! createCloudURL "Action" "DeregisterCluster" "Name" "${CLUSNAME}"; then
1222
	    exit 1
1223
	fi
1224
	
444.1.342 by graziano
better handling of --register-* in euca_conf
1225
	if ! check_ws "$URL" ; then
1226
		echo "ERROR: failed to deregister new cluster, please log in to the admin interface and check cloud status."
1227
		exit 1
444.1.33 by root
added 'deregister' to euca_conf, eucalyptus-dns handling from eucalyptus.conf
1228
	fi	
1229
	echo
1230
	echo "SUCCESS: cluster '${CLUSNAME}' successfully deregistered."
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
1231
    fi
198.1.8 by root
update euca_conf to use new cluster/node registration procedure.
1232
fi
1233
305 by graziano
Added stubs for new options.
1234
# walrus
444.1.310 by root
fixed walrus deregister bug
1235
if [ -n "$WALRUS" -o -n "$WALRUS_MODE" ]; then
414 by root
enabled 'fakeregisteration' mode in euca_conf, added 'eucalyptus-cloud' loader support into init scripts for cloud, walrus, sc
1236
    if ! checkLocalService "CLC" ; then
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
1237
	exit 1
1238
    fi
443 by root
changed up a bit
1239
    
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
1240
    if [ "$WALRUS_MODE" = "ADD" ]; then
415 by root
more stubbing out for fake registration mode
1241
	echo "Adding WALRUS host $WALRUS"
1242
	if [ -d "${EUCALYPTUS}/var/lib/eucalyptus/keys/" ]; then
1243
	    SOURCEDIR=${EUCALYPTUS}/var/lib/eucalyptus/keys/
1244
	    DESTDIR=${EUCALYPTUS}/var/lib/eucalyptus/keys/
1245
	else
1246
	    echo "ERROR: cannot find key directory ($EUCALYPTUS/var/lib/eucalyptus/keys), check that your installation was successful!"
1247
	    exit 1
1248
	fi
1249
	
1250
	URL=""
444.1.129 by root
register-walrus uses 'walrus' as the 'Name', added mkdir $EUCALYPTUS/var/run/eucalyptus/net in euca_conf when check cc is called, added modules/rampart to LD_LIBRARY_PATH in init scripts
1251
	if ! createCloudURL "Action" "RegisterWalrus" "Host" "${WALRUS}" "Name" "walrus" "Port" "8773"; then
415 by root
more stubbing out for fake registration mode
1252
	    exit 1
1253
	fi
444.1.342 by graziano
better handling of --register-* in euca_conf
1254
1255
	if ! check_ws "$URL" ; then
444.1.33 by root
added 'deregister' to euca_conf, eucalyptus-dns handling from eucalyptus.conf
1256
	    echo "ERROR: failed to register Walrus, please log in to the admin interface and check cloud status."
415 by root
more stubbing out for fake registration mode
1257
	    exit 1
1258
	fi
444.1.33 by root
added 'deregister' to euca_conf, eucalyptus-dns handling from eucalyptus.conf
1259
	
444.1.422 by graziano
Check remote walrus upong registration. (lp:436274)
1260
	# check that walrus is at least running on the remote host
1261
	sleep 3
1262
	if ! check_heartbeat ${WALRUS} walrus ; then
444.36.2 by root
cleaned up euca_conf a bit for better error reporting, key syncing, and wgetting
1263
		echo "WARNING: Walrus is not up on host ${WALRUS};  registration will not be complete until walrus is running."
444.1.422 by graziano
Check remote walrus upong registration. (lp:436274)
1264
	fi
1265
	
1266
	# sync the keys
444.1.33 by root
added 'deregister' to euca_conf, eucalyptus-dns handling from eucalyptus.conf
1267
	if ! sync_keys ${SOURCEDIR} ${DESTDIR} ${WALRUS} euca.p12 ; then
444.36.2 by root
cleaned up euca_conf a bit for better error reporting, key syncing, and wgetting
1268
	    echo "ERROR: failed to sync keys with ${WALRUS}; registration will not be complete until keys can be synced, please try again."
444.1.139 by graziano
Avoid to print ERROR and afterwards SUCCESS: exit after ERROR.
1269
            exit 1
415 by root
more stubbing out for fake registration mode
1270
	fi
444.1.33 by root
added 'deregister' to euca_conf, eucalyptus-dns handling from eucalyptus.conf
1271
	echo
415 by root
more stubbing out for fake registration mode
1272
	echo "SUCCESS: new walrus on host '${WALRUS}' successfully registered."
1273
	
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
1274
    elif [ "$WALRUS_MODE" = "DEL" ]; then
444.1.33 by root
added 'deregister' to euca_conf, eucalyptus-dns handling from eucalyptus.conf
1275
	URL=""
444.1.310 by root
fixed walrus deregister bug
1276
	if ! createCloudURL "Action" "DeregisterWalrus" "Name" "walrus"; then
444.1.33 by root
added 'deregister' to euca_conf, eucalyptus-dns handling from eucalyptus.conf
1277
	    exit 1
1278
	fi
444.1.342 by graziano
better handling of --register-* in euca_conf
1279
	if ! check_ws "$URL" ; then
444.1.33 by root
added 'deregister' to euca_conf, eucalyptus-dns handling from eucalyptus.conf
1280
	    echo "ERROR: failed to deregister Walrus, please log in to the admin interface and check cloud status."
1281
	    exit 1
1282
	fi
444.1.56 by graziano
Moved a message in the right if branch.
1283
        echo
444.1.310 by root
fixed walrus deregister bug
1284
        echo "SUCCESS: Walrus successfully deregistered."
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
1285
    fi
305 by graziano
Added stubs for new options.
1286
fi
1287
1288
# sc
444.1.314 by root
fixed deregister-sc bug
1289
if [ -n "$SCNAME" ]; then
414 by root
enabled 'fakeregisteration' mode in euca_conf, added 'eucalyptus-cloud' loader support into init scripts for cloud, walrus, sc
1290
    if ! checkLocalService "CLC" ; then
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
1291
	exit 1
1292
    fi
1293
    
1294
    if [ "$SC_MODE" = "ADD" ]; then
415 by root
more stubbing out for fake registration mode
1295
	echo "Adding SC $SCHOST to cluster $SCNAME"
1296
	if [ -d "${EUCALYPTUS}/var/lib/eucalyptus/keys/" ]; then
444.1.76 by root
change -setup to set ownership of files in $EUCALYPTUS/var/*/eucalyptus to EUCA_USER
1297
	    SOURCEDIR=${EUCALYPTUS}/var/lib/eucalyptus/keys/
415 by root
more stubbing out for fake registration mode
1298
	    DESTDIR=${EUCALYPTUS}/var/lib/eucalyptus/keys/
1299
	else
1300
	    echo "ERROR: cannot find key directory ($EUCALYPTUS/var/lib/eucalyptus/keys), check that your installation was successful!"
1301
	    exit 1
1302
	fi
1303
	
1304
	URL=""
444.1.33 by root
added 'deregister' to euca_conf, eucalyptus-dns handling from eucalyptus.conf
1305
	if ! createCloudURL "Action" "RegisterStorageController" "Host" "${SCHOST}" "Name" "${SCNAME}" "Port" "8773"; then
415 by root
more stubbing out for fake registration mode
1306
	    exit 1
1307
	fi
444.1.342 by graziano
better handling of --register-* in euca_conf
1308
	if ! check_ws "$URL"; then
444.1.33 by root
added 'deregister' to euca_conf, eucalyptus-dns handling from eucalyptus.conf
1309
	    echo "ERROR: failed to register storage controller, please log in to the admin interface and check cloud status."
415 by root
more stubbing out for fake registration mode
1310
	    exit 1
1311
	fi
1312
	if [ -n "${FAKEREG}" ]; then
1313
	    mkdir -p $SOURCEDIR
1314
	    for i in sc
1315
	    do 
1316
		if [ ! -e "$SOURCEDIR/${i}-cert.pem" -o ! -e "$SOURCEDIR/${i}-pk.pem" ]; then
1317
		    openssl req -new -nodes -x509 -out $SOURCEDIR/${i}-cert.pem -keyout $SOURCEDIR/${i}-pk.pem -days 365 -subj "/C=US/ST=CA/L=City/CN=localhost/emailAddress=root@localhost"
1318
		fi
1319
	    done
1320
	fi
1321
    
1322
    # sync the keys
444.1.76 by root
change -setup to set ownership of files in $EUCALYPTUS/var/*/eucalyptus to EUCA_USER
1323
	if ! sync_keys ${SOURCEDIR} ${DESTDIR} ${SCHOST} euca.p12; then
444.36.2 by root
cleaned up euca_conf a bit for better error reporting, key syncing, and wgetting
1324
	    echo "ERROR: failed to sync keys with ${SCHOST}; registration will not be complete until keys can be synced, please try again."
444.1.139 by graziano
Avoid to print ERROR and afterwards SUCCESS: exit after ERROR.
1325
	    exit 1
415 by root
more stubbing out for fake registration mode
1326
	fi
444.1.33 by root
added 'deregister' to euca_conf, eucalyptus-dns handling from eucalyptus.conf
1327
	echo
415 by root
more stubbing out for fake registration mode
1328
	echo "SUCCESS: new SC for cluster '${SCNAME}' on host '${SCHOST}' successfully registered."
1329
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
1330
    elif [ "$SC_MODE" = "DEL" ]; then
444.1.349 by graziano obertelli
Deregistering a non-existent cluster (or sc) will now print an error
1331
	# let's see if we have such a storage controller
1332
	LIST_RES=""
1333
	if ! createCloudURL "Action" "DescribeStorageControllers" ; then
1334
		exit 1
1335
	fi
1336
	if ! check_ws "$URL" LIST_RES ; then
1337
		echo "ERROR: cannot talk with CLC"
1338
		exit 1
1339
	fi
1340
	FOUND="N"
1341
	for x in $LIST_RES ; do
1342
		if [ "$x" = "${SCNAME}" ]; then
1343
			FOUND="Y"
1344
			break
1345
		fi
1346
	done
1347
	if [ "$FOUND" = "N" ]; then
1348
		echo "No registered storage controller $SCNAME was found"
1349
		exit 1
1350
	fi
1351
1352
	# now let's deregister
444.1.33 by root
added 'deregister' to euca_conf, eucalyptus-dns handling from eucalyptus.conf
1353
	URL=""
1354
	if ! createCloudURL "Action" "DeregisterStorageController" "Name" "${SCNAME}"; then
1355
	    exit 1
1356
	fi
444.1.342 by graziano
better handling of --register-* in euca_conf
1357
	if ! check_ws "$URL" ; then
444.1.33 by root
added 'deregister' to euca_conf, eucalyptus-dns handling from eucalyptus.conf
1358
	    echo "ERROR: failed to deregister StorageController, please log in to the admin interface and check cloud status."
1359
	    exit 1
1360
	fi
1361
	echo
1362
	echo "SUCCESS: Storage controller for cluster '${SCNAME}' successfully deregistered."
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
1363
    fi
305 by graziano
Added stubs for new options.
1364
fi
1365
198.10.2 by graziano obertelli
Previous patch fixed also the init.d script trying to start services even
1366
# operations on the nodes
198.10.1 by graziano obertelli
Few details/minor bugs:
1367
if [ -n "$NODEMODE" ]; then
1368
	# for synckey we fake addnodes
1369
	if [ "$NODEMODE" = "SYNC" ]; then
1370
		if [ -z "$NODES" ]; then
1371
			echo "Warning: there are no NODES configured"
1372
		else
1373
			NEWNODES="${NODES}"
1374
			NODEMODE="ADD"
1375
		fi
1376
	fi
1054.1.3 by Dave Walker (Daviey)
Ubuntu patches applied
1377
	if [ "$NODEMODE" = "DISCOVER" ]; then
1378
		if ! which avahi-browse >/dev/null 2>&1; then
1379
			echo "ERROR: avahi-browse not installed, so cannot discover nodes"
1380
			exit 1
1381
		fi
1382
		NEWNODES=
1383
		for DISCOVERED in $(avahi-browse -prt _eucalyptus._tcp | grep '^=.*"type=node"' | cut -d\; -f8 | sort -u); do
1384
			if ! xsearch "$DISCOVERED" "$NODES"; then
1385
				read -p "New node found on $DISCOVERED; add it? [Yn] " CONFIRM
1386
				CONFIRM="$(printf %s "$CONFIRM" | tr A-Z a-z | cut -c1)"
1387
				if [ "x$CONFIRM" = x ] || [ "x$CONFIRM" = xy ]; then
1388
					NEWNODES="${NEWNODES:+$NEWNODES }$DISCOVERED"
1389
				fi
1390
			fi
1391
		done
1392
		NODEMODE="ADD"
1393
	fi
198.10.2 by graziano obertelli
Previous patch fixed also the init.d script trying to start services even
1394
198.10.19 by graziano obertelli
added -norsync option for distro with no root user
1395
	# check we have a valid command
1396
	if [ "$NODEMODE" != "ADD" -a "$NODEMODE" != "REM" ]; then
1397
		echo "ERROR: unknown mode '$NODEMODE', don't know what to do"
1398
		exit 1
1399
	fi
1400
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
1401
	if [ -d "${EUCALYPTUS}/var/lib/eucalyptus/keys/" ]; then
1402
	    SOURCEDIR=${EUCALYPTUS}/var/lib/eucalyptus/keys/
1403
	    DESTDIR=${EUCALYPTUS}/var/lib/eucalyptus/keys/
1404
	else
1405
	    echo "ERROR: cannot find key directory ($EUCALYPTUS/var/lib/eucalyptus/keys), check that your installation was successful and that this cluster is already registered!"
1406
	    exit 1
1407
	fi
1408
	
305 by graziano
Added stubs for new options.
1409
	# CC needs to be running 
413 by root
generalized service check, sync_keys and url creation/signing code in euca_conf, added stubs for 'dryrun' CC registration, added timeout to wget commands
1410
	if ! checkLocalService "CC" ; then
1411
	    exit 1
305 by graziano
Added stubs for new options.
1412
	fi
1413
198.10.19 by graziano obertelli
added -norsync option for distro with no root user
1414
	# warn the user on where we expect the keys to be
1415
	if [ "$NODEMODE" = "ADD" ]; then 
1416
		echo
1054.1.3 by Dave Walker (Daviey)
Ubuntu patches applied
1417
		echo "INFO: We expect all nodes to have eucalyptus installed in $EUCALYPTUS/var/lib/eucalyptus/keys for key synchronization."
198.10.19 by graziano obertelli
added -norsync option for distro with no root user
1418
	fi
1419
198.10.2 by graziano obertelli
Previous patch fixed also the init.d script trying to start services even
1420
	# adding (or removing) nodes
1421
	for NEWNODE in ${NEWNODES} ; do
444.67.12 by root
applied gdiff from 1.6.2-g
1422
	    # let's see if the node is already in the node list
1423
            its_here="0"
1424
            for x in $NODES ; do
1425
                if [ "$x" = "${NEWNODE}" ]; then
1426
                    its_here="1"
1427
                    break
1428
                fi
1429
	    done
1430
	    
1431
            # remove is simpler: just remove the node name
1432
            if [ "$NODEMODE" = "REM" ]; then
1433
                if [ "$its_here" = "0" ]; then
1434
                    echo "Node ${NEWNODE} is not known"
1435
                    continue
1436
                fi
1437
                NEW_NODES=""
1438
                for x in $NODES;  do
1439
                    if [ "$x" = "${NEWNODE}" ]; then
1440
                        continue
1441
                    fi
1442
                    NEW_NODES="$x $NEW_NODES"
1443
                done
1054.1.3 by Dave Walker (Daviey)
Ubuntu patches applied
1444
                echo "$NODES" | tr ' ' '\n' | uniq > $EUCALYPTUS/var/lib/eucalyptus/nodes.list
444.67.12 by root
applied gdiff from 1.6.2-g
1445
                echo "SUCCESS: removed node '${NEWNODE}' from '$FILE'"
1446
                continue
1447
            fi
1448
	    
1449
	    # let's sync keys with the nodes
1450
	    if ! sync_keys ${SOURCEDIR} ${DESTDIR} ${NEWNODE} node-cert.pem cluster-cert.pem node-pk.pem cloud-cert.pem; then
1054.1.3 by Dave Walker (Daviey)
Ubuntu patches applied
1451
		errors=1
444.67.12 by root
applied gdiff from 1.6.2-g
1452
		echo
1453
		echo "ERROR: could not synchronize keys with $NEWNODE!"
1454
		echo "The configuration will not have this node."
1455
		if [ "$SSHKEY" = "" ]; then
1456
		    echo "User $EUCA_USER may have to run ssh-keygen!"
1457
		else
1458
		    echo "Hint: to setup passwordless login to the nodes as user $EUCA_USER, you can"
1459
		    echo "run the following commands on node $NEWNODE:"
1460
		    echo "sudo -u $EUCA_USER mkdir -p ~${EUCA_USER}/.ssh"
1461
		    echo "sudo -u $EUCA_USER tee ~${EUCA_USER}/.ssh/authorized_keys > /dev/null <<EOT"
1462
		    echo "$SSHKEY"
1463
		    echo "EOT"
1464
		    echo ""
1465
		    echo "Be sure that authorized_keys is not group/world readable or writable"
1466
		fi
1467
		continue
1468
	    fi
1469
1470
            # if the node is already listed, we are done
1471
            if [ "$its_here" = "1" ]; then
1472
                continue
1473
            fi
1474
1475
            # add the node
1476
            NODES="${NODES} $NEWNODE"
1054.1.3 by Dave Walker (Daviey)
Ubuntu patches applied
1477
            echo "$NODES" | tr ' ' '\n' | uniq > $EUCALYPTUS/var/lib/eucalyptus/nodes.list
444.67.12 by root
applied gdiff from 1.6.2-g
1478
198.10.2 by graziano obertelli
Previous patch fixed also the init.d script trying to start services even
1479
	done
198.10.1 by graziano obertelli
Few details/minor bugs:
1480
fi
444.1.343 by graziano
added --list-{clusters|walruses|storages}
1481
444.29.121 by decker
add the euca_conf bits for describe nodes, add trivial completion for euca_conf
1482
444.1.343 by graziano
added --list-{clusters|walruses|storages}
1483
for x in $LIST ; do
444.1.349 by graziano obertelli
Deregistering a non-existent cluster (or sc) will now print an error
1484
	LIST_RES=""
1485
444.1.343 by graziano
added --list-{clusters|walruses|storages}
1486
	if [ "$x" = "walruses" ]; then
444.1.349 by graziano obertelli
Deregistering a non-existent cluster (or sc) will now print an error
1487
		if ! createCloudURL "Action" "DescribeWalruses" ; then
1488
			exit 1
1489
		fi
1490
		if ! check_ws "$URL" LIST_RES ; then
1491
			exit 1
1492
		fi
1493
		if [ -n "$LIST_RES" ]; then
1494
			echo "registered walruses:"
1495
		fi
444.29.121 by decker
add the euca_conf bits for describe nodes, add trivial completion for euca_conf
1496
		echo "$LIST_RES"
444.1.343 by graziano
added --list-{clusters|walruses|storages}
1497
	fi
1498
	if [ "$x" = "storages" ]; then
444.1.349 by graziano obertelli
Deregistering a non-existent cluster (or sc) will now print an error
1499
		if ! createCloudURL "Action" "DescribeStorageControllers" ; then
1500
			exit 1
1501
		fi
1502
		if ! check_ws "$URL" LIST_RES ; then
1503
			exit 1
1504
		fi
1505
		if [ -n "$LIST_RES" ]; then
1506
			echo "registered storage controllers:"
1507
		fi
444.29.121 by decker
add the euca_conf bits for describe nodes, add trivial completion for euca_conf
1508
		echo "$LIST_RES"
444.1.343 by graziano
added --list-{clusters|walruses|storages}
1509
	fi
1510
	if [ "$x" = "clusters" ]; then
444.1.349 by graziano obertelli
Deregistering a non-existent cluster (or sc) will now print an error
1511
		if ! createCloudURL "Action" "DescribeClusters" ; then
1512
			exit 1
1513
		fi
1514
		if ! check_ws "$URL" LIST_RES ; then
1515
			exit 1
1516
		fi
1517
		if [ -n "$LIST_RES" ]; then
1518
			echo "registered clusters:"
1519
		fi
444.29.121 by decker
add the euca_conf bits for describe nodes, add trivial completion for euca_conf
1520
		echo "$LIST_RES"
1521
	fi
1522
	if [ "$x" = "nodes" ]; then
1523
		if ! createCloudURL "Action" "DescribeNodes" ; then
1524
			exit 1
1525
		fi
1526
		if ! check_ws "$URL" LIST_RES ; then
1527
			exit 1
1528
		fi
1529
		if [ -n "$LIST_RES" ]; then
1530
			echo "registered nodes:"
1531
		fi
1532
		echo "$LIST_RES"
444.1.343 by graziano
added --list-{clusters|walruses|storages}
1533
	fi
1534
done
444.21.1 by graziano
use euca_conf to enable/disable ws starts/stop and use only one init
1535
444.29.121 by decker
add the euca_conf bits for describe nodes, add trivial completion for euca_conf
1536
444.21.1 by graziano
use euca_conf to enable/disable ws starts/stop and use only one init
1537
# enable/disable services
1538
if [ -r $EUCALYPTUS/var/lib/eucalyptus/services ]; then
1539
	for x in `cat $EUCALYPTUS/var/lib/eucalyptus/services` ; do
1540
		TO_START="$TO_START $x"
1541
	done
1542
fi
1543
if [ -n "$DISABLED" -o -n "$ENABLED" ]; then
1544
	for x in $TO_START $ENABLED ; do
1545
		to_start="Y"
1546
		for y in $DISABLED ; do
444.21.7 by graziano
I borrowed chris book on boolean algebra and found this bug.
1547
			if [ "$x" = "$y" ]; then
444.21.1 by graziano
use euca_conf to enable/disable ws starts/stop and use only one init
1548
				to_start="N"
1549
			fi
1550
		done
1551
		[ $to_start = "Y" ] && echo $x
1552
	done | sort | uniq > $EUCALYPTUS/var/lib/eucalyptus/services
1553
fi
1054.1.3 by Dave Walker (Daviey)
Ubuntu patches applied
1554
1555
[ "$errors" = "1" ] && exit 1 || exit 0