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