2 # main autocluster script
4 # Copyright (C) Andrew Tridgell 2008
5 # Copyright (C) Martin Schwenke 2008
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, see <http://www.gnu.org/licenses/>.
21 installdir="`dirname \"$0\"`"
23 autocluster=`which $0`
24 installdir="`dirname \"$autocluster\"`"
35 Usage: autocluster [OPTION] ... <COMMAND>
37 -c <file> specify config file (default is "config")
38 -x enable script debugging
44 create cluster CLUSTERNAME
47 create node CLUSTERNAME NODENUMBER
48 create one cluster node
50 create tsm CLUSTERNAME
51 create a TSM server node
54 mount a qemu disk on mnt/
57 unmount a qemu disk from mnt/
69 ###############################
70 # create a single node
74 NAME="$CLUSTER""n$NODENUMBER"
75 BASE="$VIRTBASE/$BASENAME.img"
76 DISK="$VIRTBASE/$CLUSTER/$NAME.qcow2"
79 # first node might need more memory for SoFS GUI
80 if [ $NODENUMBER = 1 -a $GUIMEM -gt $MEM ]; then
85 echo "Creating cluster node $NAME"
87 mkdir -p $VIRTBASE/$CLUSTER
89 echo "Creating the disk"
91 qemu-img create -b "$BASE" -f qcow2 "$DISK"
93 IPNUM=`expr $FIRSTIP + $NODENUMBER`
102 MAC1=`get_macaddr $CLUSTER $NODENUMBER 1`
103 MAC2=`get_macaddr $CLUSTER $NODENUMBER 2`
104 MAC3=`get_macaddr $CLUSTER $NODENUMBER 3`
107 echo "Creating $NAME.xml"
108 substitute_vars $NODE_TEMPLATE tmp/$NAME.xml
110 # install the XML file
111 $VIRSH undefine $NAME > /dev/null 2>&1 || true
112 $VIRSH define tmp/$NAME.xml
116 ###############################
121 BASE="$VIRTBASE/$BASENAME.img"
122 DISK="$VIRTBASE/$CLUSTER/$NAME.qcow2"
123 TSMDISK="$VIRTBASE/$CLUSTER/tsmstorage.qcow2"
125 echo "Creating TSM cluster node $NAME"
127 mkdir -p $VIRTBASE/$CLUSTER tmp
129 echo "Creating the disk"
131 qemu-img create -b "$BASE" -f qcow2 "$DISK"
133 echo "Creating tsm disk"
134 qemu-img create -f qcow2 "$TSMDISK" $TSMDISKSIZE
136 # TSM server is first IP in the cluster
145 MAC1=`get_macaddr $CLUSTER 0 0`
147 echo "Creating $NAME.xml"
148 substitute_vars $TSM_TEMPLATE tmp/$NAME.xml
150 # install the XML file
151 $VIRSH undefine $NAME > /dev/null 2>&1 || true
152 $VIRSH define tmp/$NAME.xml
156 ###############################
157 # create a whole cluster
161 mkdir -p $VIRTBASE/$CLUSTER tmp
164 echo "Creating 3 shared disks"
165 for i in `seq 1 3`; do
166 qemu-img create -f raw $VIRTBASE/$CLUSTER/shared$i $SHAREDDISKSIZE
167 # setup a nice ID at the start of the disk
168 echo "SOFS-`uuidgen`" > tmp/diskid
169 dd if=tmp/diskid of=$VIRTBASE/$CLUSTER/shared$i conv=notrunc bs=1 > /dev/null 2>&1
172 echo "Creating $NUMNODES base nodes"
173 for i in `seq 1 $NUMNODES`; do
174 create_node "$CLUSTER" $i
177 echo "Creating TSM server node"
178 create_tsm "$CLUSTER"
180 echo "# autocluster $CLUSTER" > hosts.$CLUSTER
181 echo "$IPBASE.0.$FIRSTIP ${CLUSTER}tsm.$LOWDOMAIN ${CLUSTER}tsm" >> hosts.$CLUSTER
182 for i in `seq 1 $NUMNODES`; do
183 echo "$IPBASE.0.`expr $FIRSTIP + $i` ${CLUSTER}n$i.$LOWDOMAIN ${CLUSTER}n$i" >> hosts.$CLUSTER
185 echo >> hosts.$CLUSTER
187 echo "Cluster $CLUSTER created"
188 echo "You may want to add this to your /etc/hosts file:"
199 DISK="$VIRTBASE/$NAME.img"
203 echo "Creating the disk"
204 qemu-img create -f raw "$DISK" $DISKSIZE
207 mkdir -p mnt tmp tmp/ISO
213 echo "Creating kickstart file from template"
214 substitute_vars "$KICKSTART" "tmp/ks.cfg"
216 echo "Creating kickstart floppy"
217 dd if=/dev/zero of=tmp/floppy.img bs=1024 count=1440
218 mkdosfs tmp/floppy.img
219 mount -o loop -t msdos tmp/floppy.img mnt
221 mount -o loop,ro $ISO tmp/ISO
223 echo "Setting up bootloader"
224 cp tmp/ISO/isolinux/isolinux.bin tmp
225 cp tmp/ISO/isolinux/vmlinuz tmp
226 cp tmp/ISO/isolinux/initrd.img tmp
232 substitute_vars $INSTALL_TEMPLATE tmp/$NAME.xml
234 rm -f $KVMLOG/serial.$NAME
236 # boot the install CD
237 $VIRSH create tmp/$NAME.xml
239 echo "Waiting for install to start"
242 # wait for the install to finish
243 cat <<EOF > tmp/wait.exp
244 spawn tail -f $KVMLOG/serial.$NAME
245 expect -timeout 3600 "you may safely reboot your system"
251 if ! grep "you may safely reboot your system" $KVMLOG/serial.$NAME > /dev/null; then
252 echo "Failed to create base image $DISK"
259 Install finished, base image $DISK created
263 To ensure that this image does not change
270 ###############################
276 DISK="$VIRTBASE/$NAME.img"
290 echo "Creating $NAME.xml"
291 substitute_vars $BOOT_TEMPLATE tmp/$NAME.xml
293 # boot the base system
294 $VIRSH create tmp/$NAME.xml
297 ###############################
298 # test the proxy setup
300 export http_proxy=$WEBPROXY
301 wget -O /dev/null $INSTALL_SERVER
305 ######################################################################
308 ############################
309 # parse command line options
310 temp=$(getopt -n "$prog" -o "c:xh" -l help -- "$@")
318 -c) config="$2" ; shift; shift ;;
321 -h|--help|*) usage ;; # Shouldn't happen, so this is reasonable.
325 . "`dirname $config`/$config"
326 . "$installdir/functions"
328 LOWDOMAIN=`echo $DOMAIN | tr A-Z a-z`
330 # check for needed programs
331 check_command nbd-client
333 check_command qemu-nbd
335 [ $# -lt 1 ] && usage
355 create_node "$1" "$2";