Statistiques
| Révision :

root / trunk / shell / configuration-delete-compute-nodes @ 52

Historique | Voir | Annoter | Télécharger (3,27 ko)

1 51 storres
#! /bin/bash -x
2 51 storres
#
3 51 storres
# ST - 2012-07-04
4 51 storres
#
5 51 storres
# Delete the compute nodes for a configuration.
6 51 storres
#
7 51 storres
# Get the directory of the script.
8 51 storres
SCRIPT_PATH=`dirname $0`
9 51 storres
# Get the script name.
10 51 storres
SCRIPT_NAME=`basename $0`
11 51 storres
# Source the common configuration variables.
12 51 storres
. $SCRIPT_PATH/c-i-a-b.common
13 51 storres
#
14 51 storres
# Get the configurations
15 51 storres
#
16 51 storres
CONFIGURATIONS=`ls $SCRIPT_PATH/$CONST_CONFIGURATIONS_DIR`
17 51 storres
CONFIGURATIONS_STRING="{"
18 51 storres
echo $CONFIGURATIONS
19 51 storres
for i in $CONFIGURATIONS ; do
20 51 storres
  CONFIGURATIONS_STRING="$CONFIGURATIONS_STRING$i|"
21 51 storres
done
22 51 storres
#
23 51 storres
# Check command line arguments.
24 51 storres
#
25 51 storres
if [ "x$1" == "x" ]
26 51 storres
  then
27 51 storres
     echo
28 51 storres
     echo "Missing parameter. Aborting!"
29 51 storres
     echo
30 51 storres
     echo "Usage: $SCRIPT_NAME configuration"
31 51 storres
     echo
32 51 storres
     echo -e "	configuration: one of $CONFIGURATIONS_STRING\b}"
33 51 storres
     exit 1
34 51 storres
fi
35 51 storres
#
36 51 storres
# Does the configuration exist?
37 51 storres
#
38 51 storres
CONFIGURATION_FOUND=""
39 51 storres
CONFIGURATION=`echo $1 | tr [:upper:] [:lower:]`
40 51 storres
for i in $CONFIGURATIONS ; do
41 51 storres
    CURRENT_CONFIGURATION=`echo $i | tr [:upper:] [:lower:]`
42 51 storres
    if [ $CONFIGURATION == $CURRENT_CONFIGURATION ] ; then
43 51 storres
      CONFIGURATION_FOUND=$i
44 51 storres
    fi
45 51 storres
done
46 51 storres
if [ -z $CONFIGURATION_FOUND ] ; then
47 51 storres
  echo
48 51 storres
  echo
49 51 storres
  echo "The configuration \"$1\" does not exist".
50 51 storres
  echo -e "The configuration must be one of $CONFIGURATIONS_STRING\b}."
51 51 storres
  echo "Aborting!"
52 51 storres
  echo
53 51 storres
  echo
54 51 storres
  exit 1
55 51 storres
else
56 51 storres
  CONFIGURATION=$CONFIGURATION_FOUND
57 51 storres
fi
58 51 storres
#
59 51 storres
# Source the specific variables for the configuration.
60 51 storres
#
61 51 storres
. $SCRIPT_PATH/$CONST_CONFIGURATIONS_DIR/$CONFIGURATION/c-i-a-b.config.common
62 51 storres
#
63 51 storres
# Delete the compute nodes.
64 51 storres
#
65 51 storres
COMPUTE_NODE_INDEX=1
66 51 storres
while [ $COMPUTE_NODE_INDEX -le $COMPUTE_NODE_MAX_INDEX ] ; do
67 51 storres
#
68 51 storres
# Compute the host name.
69 51 storres
#
70 51 storres
  #
71 51 storres
  # Convert the number into a three caracters strings.
72 51 storres
  #
73 51 storres
  COMPUTE_NODE_INDEX_STRING=$COMPUTE_NODE_INDEX
74 51 storres
  while [ ${#COMPUTE_NODE_INDEX_STRING} -lt 3 ] ; do
75 51 storres
    COMPUTE_NODE_INDEX_STRING="0$COMPUTE_NODE_INDEX_STRING"
76 51 storres
  done
77 51 storres
  #
78 51 storres
  # Compute the host name.
79 51 storres
  #
80 51 storres
  CURRENT_HOST_NAME=${COMPUTE_NODE_NAME_PREFIX}${COMPUTE_NODE_INDEX_STRING}
81 51 storres
  #
82 51 storres
  # If the compute node is running, stop it.
83 51 storres
  #
84 51 storres
  IS_RUNNING=`xm list | grep $CURRENT_HOST_NAME`
85 51 storres
  if [ ! -z "$IS_RUNNING" ] ; then
86 51 storres
    xm shutdown $CURRENT_HOST_NAME
87 51 storres
    #
88 51 storres
    # And wait until it has sopped.
89 51 storres
    #
90 51 storres
    IS_RUNNING=""
91 51 storres
    while [ -z "$IS_RUNNING" ] ; do
92 51 storres
      IS_RUNNING=`xm list | grep $CURRENT_HOST_NAME`
93 51 storres
      sleep 1
94 51 storres
    done # End while
95 51 storres
  fi # End compute node is running.
96 51 storres
  #
97 51 storres
  # If necessary, delete the VM system disk.
98 51 storres
  #
99 51 storres
  COMPUTE_NODE_SYSTEM_DISK_DEVICE="${COMPUTE_NODE_MODEL_SYSTEM_VOLUME_GROUP_DEVICE}/${CURRENT_HOST_NAME}-${CONST_SYSTEM_DISK_POSTFIX}-clone"
100 51 storres
  if [ -e $COMPUTE_NODE_SYSTEM_DISK_DEVICE ] ; then
101 51 storres
    lvremove -f $COMPUTE_NODE_SYSTEM_DISK_DEVICE
102 51 storres
    if [ $? -ne 0 ] ; then
103 51 storres
      ciab_abort_message "Could not remove system disk for $CURRENT_HOST_NAME" 1
104 51 storres
    fi
105 51 storres
  fi
106 51 storres
  #
107 51 storres
  # If necessary, remove the swap volume for the compute node.
108 51 storres
  #
109 51 storres
  COMPUTE_NODE_SWAP_DISK_DEVICE="COMPUTE_NODE_SWAP_DISK_VOLUME_GROUP_DEVICE/${CURRENT_HOST_NAME}-${CONST_SWAP_DISK_POSTFIX}"
110 51 storres
  if [ -e $COMPUTE_NODE_SWAP_DISK_DEVICE ] ; then
111 51 storres
    lvremove -f $COMPUTE_NODE_SWAP_DISK_DEVICE
112 51 storres
    if [ $? -ne 0 ] ; then
113 51 storres
      ciab_abort_message "Could not remove swap disk for $CURRENT_HOST_NAME" 1
114 51 storres
    fi
115 51 storres
  fi
116 51 storres
  #
117 51 storres
  # Remove the Xen configuration file.
118 51 storres
  #
119 51 storres
  CURRENT_PATH=/etc/xen
120 51 storres
  rm -f $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg
121 51 storres
  #
122 51 storres
  COMPUTE_NODE_INDEX=$((COMPUTE_NODE_INDEX + 1))
123 51 storres
done
124 51 storres
exit 0