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