#!/bin/bash # main autocluster script # # Copyright (C) Andrew Tridgell 2008 # Copyright (C) Martin Schwenke 2008 # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, see . if [ -f "$0" ]; then installdir="`dirname \"$0\"`" else autocluster=`which $0` installdir="`dirname \"$autocluster\"`" fi #################### # show program usage usage () { cat < options: -c specify config file (default is "config") -x enable script debugging --dump dump config settings and exit configuration options: EOF usage_config_options cat < /dev/null 2>&1 || true $VIRSH define tmp/$NAME.xml } ############################### # create a TSM node create_tsm() { CLUSTER="$1" NAME="$CLUSTER""tsm" BASE="$VIRTBASE/$BASENAME.img" DISK="$VIRTBASE/$CLUSTER/$NAME.qcow2" TSMDISK="$VIRTBASE/$CLUSTER/tsmstorage.qcow2" echo "Creating TSM cluster node $NAME" mkdir -p $VIRTBASE/$CLUSTER tmp echo "Creating the disk" rm -f "$DISK" qemu-img create -b "$BASE" -f qcow2 "$DISK" echo "Creating tsm disk" qemu-img create -f qcow2 "$TSMDISK" $TSMDISKSIZE # TSM server is first IP in the cluster IPNUM=$FIRSTIP mount_disk $DISK setup_base setup_network unmount_disk UUID=`uuidgen` MAC1=`get_macaddr $CLUSTER 0 0` echo "Creating $NAME.xml" substitute_vars $TSM_TEMPLATE tmp/$NAME.xml # install the XML file $VIRSH undefine $NAME > /dev/null 2>&1 || true $VIRSH define tmp/$NAME.xml } ############################### # create a whole cluster create_cluster() { CLUSTER="$1" mkdir -p $VIRTBASE/$CLUSTER tmp mkdir -p $KVMLOG echo "Creating 3 shared disks" for i in `seq 1 3`; do # setup a nice ID at the start of the disk qemu-img create -f raw $VIRTBASE/$CLUSTER/shared$i $SHAREDDISKSIZE echo "SOFS-`uuidgen`" > tmp/diskid dd if=tmp/diskid of=$VIRTBASE/$CLUSTER/shared$i conv=notrunc bs=1 > /dev/null 2>&1 done echo "Creating $NUMNODES base nodes" for i in `seq 1 $NUMNODES`; do create_node "$CLUSTER" $i done if [ $WITH_TSM_NODE -eq 1 ]; then echo "Creating TSM server node" create_tsm "$CLUSTER" fi echo "# autocluster $CLUSTER" > hosts.$CLUSTER [ $WITH_TSM_NODE -eq 1 ] && { echo "$IPBASE.0.$FIRSTIP ${CLUSTER}tsm.$LOWDOMAIN ${CLUSTER}tsm" >> hosts.$CLUSTER } for i in `seq 1 $NUMNODES`; do echo "$IPBASE.0.`expr $FIRSTIP + $i` ${CLUSTER}n$i.$LOWDOMAIN ${CLUSTER}n$i" >> hosts.$CLUSTER done echo >> hosts.$CLUSTER echo "Cluster $CLUSTER created" echo "You may want to add this to your /etc/hosts file:" cat hosts.$CLUSTER echo } ############################### # test the proxy setup test_proxy() { export http_proxy=$WEBPROXY wget -O /dev/null $INSTALL_SERVER || { echo "Your WEBPROXY setting \"$WEBPROXY\" is not working" exit 1 } echo "Proxy OK" } ################### # create base image create_base() { NAME="$BASENAME" DISK="$VIRTBASE/$NAME.img" mkdir -p $KVMLOG echo "Testing WEBPROXY $WEBPROXY" test_proxy echo "Creating the disk" qemu-img create -f $BASE_FORMAT "$DISK" $DISKSIZE rm -rf tmp mkdir -p mnt tmp tmp/ISO setup_timezone setup_repos echo "Creating kickstart file from template" substitute_vars "$KICKSTART" "tmp/ks.cfg" if [ $INSTALLKEY = "--skip" ]; then cat <