~ubuntu-branches/ubuntu/natty/eucalyptus/natty-201103250208

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash

# Storage controller registration script
# Registers SC at IP $2 with cluster $1 (on CLC)

# Source common functions
. /usr/share/eucalyptus/registration/common

# Parameter sanitizing
CLUSTERNAME=${1% storage}
IP=$2
testip "${IP}"

# Check if SC isn't already registered
for sc in `euca_conf --list-scs | tail -n +2 | awk '{ print $1 }'`; do
  if [ "$sc" == "$CLUSTERNAME" ]; then
    reglog "SC for $CLUSTERNAME is already registered."
    exit 1
  fi
done

# Register SC if CC exists
function tryregistersc {
  for cc in `euca_conf --list-clusters | tail -n +2 | awk '{ print $1 }'`; do
    if [ "$cc" == "$1" ]; then
      SHORT_COMMAND="euca_conf --register-sc"
      REAL_COMMAND="/usr/sbin/euca_conf --no-rsync --skip-scp-hostcheck --register-sc "${CLUSTERNAME}" "${IP}""
      COMMAND_OUTPUT=$(eval $REAL_COMMAND)
      STATUS=$?
      if [ $STATUS -eq 0 ];then
        reglog "$SHORT_COMMAND returned SUCCESS"
      else
        reglog "$SHORT_COMMAND returned FAILURE (error $STATUS): Command attempted was \"$REAL_COMMAND\", and had the following output: \"$COMMAND_OUTPUT\""
      fi
      exit 0
    fi
  done
}

tryregistersc "${CLUSTERNAME}"

retries=2
while [ $retries -gt 0 ]; do
  reglog "Cluster $CLUSTERNAME doesn't exist, retrying in 10 seconds."
  sleep 10
  tryregistersc "${CLUSTERNAME}"
  tries=$(($tries-1))
done

reglog "Cluster $CLUSTERNAME doesn't exist"
exit 1