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 # setup a nice ID at the start of the disk
167 qemu-img create -f raw $VIRTBASE/$CLUSTER/shared$i $SHAREDDISKSIZE
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 $BASE_FORMAT "$DISK" $DISKSIZE
207 mkdir -p mnt tmp tmp/ISO
212 echo "Creating kickstart file from template"
213 substitute_vars "$KICKSTART" "tmp/ks.cfg"
215 if [ $INSTALLKEY = "--skip" ]; then
217 --------------------------------------------------------------------------------------
218 WARNING: You have not entered an install key. Some RHEL packages will not be installed.
220 Please enter a valid RHEL install key in your config file like this:
222 INSTALLKEY="1234-5678-0123-4567"
224 The install will continue without an install key in 5 seconds
225 --------------------------------------------------------------------------------------
230 echo "Creating kickstart floppy"
231 dd if=/dev/zero of=tmp/floppy.img bs=1024 count=1440
232 mkdosfs tmp/floppy.img
233 mount -o loop -t msdos tmp/floppy.img mnt
235 mount -o loop,ro $ISO tmp/ISO
237 echo "Setting up bootloader"
238 cp tmp/ISO/isolinux/isolinux.bin tmp
239 cp tmp/ISO/isolinux/vmlinuz tmp
240 cp tmp/ISO/isolinux/initrd.img tmp
246 substitute_vars $INSTALL_TEMPLATE tmp/$NAME.xml
248 rm -f $KVMLOG/serial.$NAME
250 # boot the install CD
251 $VIRSH create tmp/$NAME.xml
253 echo "Waiting for install to start"
256 # wait for the install to finish
257 cat <<EOF > tmp/wait.exp
258 spawn tail -f $KVMLOG/serial.$NAME
259 expect -timeout 3600 "you may safely reboot your system"
265 if ! grep "you may safely reboot your system" $KVMLOG/serial.$NAME > /dev/null; then
266 echo "Failed to create base image $DISK"
273 Install finished, base image $DISK created
277 To ensure that this image does not change
284 ###############################
290 DISK="$VIRTBASE/$NAME.img"
304 echo "Creating $NAME.xml"
305 substitute_vars $BOOT_TEMPLATE tmp/$NAME.xml
307 # boot the base system
308 $VIRSH create tmp/$NAME.xml
311 ###############################
312 # test the proxy setup
314 export http_proxy=$WEBPROXY
315 wget -O /dev/null $INSTALL_SERVER
319 ######################################################################
322 ############################
323 # parse command line options
324 temp=$(getopt -n "$prog" -o "c:xh" -l help -- "$@")
332 -c) config="$2" ; shift; shift ;;
335 -h|--help|*) usage ;; # Shouldn't happen, so this is reasonable.
339 . "$installdir/config.default"
340 . "`dirname $config`/$config"
341 . "$installdir/functions"
343 LOWDOMAIN=`echo $DOMAIN | tr A-Z a-z`
345 # check for needed programs
346 check_command nbd-client
348 check_command qemu-nbd
350 [ $# -lt 1 ] && usage
370 create_node "$1" "$2";