scripts: Add autocluster-test-ctdb script
[tridge/autocluster.git] / autocluster
diff --git a/autocluster b/autocluster
deleted file mode 100755 (executable)
index 9225852..0000000
+++ /dev/null
@@ -1,370 +0,0 @@
-#!/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 <http://www.gnu.org/licenses/>.
-
-if [ -f "$0" ]; then
-    installdir="`dirname \"$0\"`"
-else
-    autocluster=`which $0`
-    installdir="`dirname \"$autocluster\"`"
-fi
-
-config="config"
-set -e
-
-####################
-# show program usage
-usage ()
-{
-    cat >&2 <<EOF
-Usage: autocluster [OPTION] ... <COMMAND>
-  options:
-    -c <file>  specify config file (default is "config")
-    -x         enable script debugging
-
-  commands:
-     create base
-           create a base image
-
-     create cluster CLUSTERNAME
-           create a full cluster
-
-     create node CLUSTERNAME NODENUMBER
-           create one cluster node
-
-     create tsm CLUSTERNAME
-           create a TSM server node
-
-     mount DISK
-           mount a qemu disk on mnt/
-
-     unmount
-           unmount a qemu disk from mnt/
-
-     bootbase
-           boot the base image
-
-     testproxy
-           test your proxy setup
-EOF
-    exit 1
-}
-
-
-###############################
-# create a single node
-create_node() {
-    CLUSTER="$1"
-    NODENUMBER="$2"
-    NAME="$CLUSTER""n$NODENUMBER"
-    BASE="$VIRTBASE/$BASENAME.img"
-    DISK="$VIRTBASE/$CLUSTER/$NAME.qcow2"
-    NUMSHARED=3
-
-    # first node might need more memory for SoFS GUI
-    if [ $NODENUMBER = 1 -a $GUIMEM -gt $MEM ]; then
-       MEM=$GUIMEM
-    fi
-
-    echo "Creating cluster node $NAME"
-
-    mkdir -p $VIRTBASE/$CLUSTER
-
-    echo "Creating the disk"
-    rm -f "$DISK"
-    qemu-img create -b "$BASE" -f qcow2 "$DISK"
-
-    IPNUM=`expr $FIRSTIP + $NODENUMBER`
-
-    mount_disk $DISK
-    setup_base
-    setup_network
-    unmount_disk
-
-    mkdir -p tmp
-
-    MAC1=`get_macaddr $CLUSTER $NODENUMBER 1`
-    MAC2=`get_macaddr $CLUSTER $NODENUMBER 2`
-    MAC3=`get_macaddr $CLUSTER $NODENUMBER 3`
-    UUID=`uuidgen`
-    
-    echo "Creating $NAME.xml"
-    substitute_vars $NODE_TEMPLATE tmp/$NAME.xml
-    
-    # install the XML file
-    virsh undefine $NAME > /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
-    
-    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
-    # setup a nice ID at the start of the disk
-    echo "SOFS-`uuidgen`" > tmp/diskid
-    dd if=tmp/diskid of=$TSMDISK conv=notrunc bs=1 > /dev/null 2>&1
-    
-    # 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
-    mkdir -p $KVMLOG
-
-    echo "Creating 3 shared disks"
-    for i in `seq 1 3`; do
-       qemu-img create -f raw $VIRTBASE/$CLUSTER/shared$i $SHAREDDISKSIZE
-       # setup a nice ID at the start of the disk
-       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
-
-    echo "Creating TSM server node"
-    create_tsm "$CLUSTER"
-}
-
-###################
-# create base image
-create_base() {
-
-    NAME="$BASENAME"
-    DISK="$VIRTBASE/$NAME.img"
-
-    echo "Creating the disk"
-    qemu-img create -f raw "$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"
-
-    echo "Creating kickstart floppy"
-    dd if=/dev/zero of=tmp/floppy.img bs=1024 count=1440
-    mkdosfs tmp/floppy.img
-    mount -o loop -t msdos tmp/floppy.img mnt
-    cp tmp/ks.cfg mnt
-    mount -o loop,ro $ISO tmp/ISO
-    
-    echo "Setting up bootloader"
-    cp tmp/ISO/isolinux/isolinux.bin tmp
-    cp tmp/ISO/isolinux/vmlinuz tmp
-    cp tmp/ISO/isolinux/initrd.img tmp
-    umount tmp/ISO
-    umount mnt
-
-    UUID=`uuidgen`
-
-    substitute_vars $INSTALL_TEMPLATE tmp/$NAME.xml
-
-    rm -f $KVMLOG/serial.$NAME
-
-    # boot the install CD
-    virsh create tmp/$NAME.xml
-
-    echo "Waiting for install to start"
-    sleep 2
-    
-    # wait for the install to finish
-    cat <<EOF > tmp/wait.exp
-spawn tail -f $KVMLOG/serial.$NAME
-expect -timeout 3600 "you may safely reboot your system"
-EOF
-
-    expect tmp/wait.exp
-    virsh destroy $NAME
-    
-    if ! grep "you may safely reboot your system" $KVMLOG/serial.$NAME > /dev/null; then
-       echo "Failed to create base image $DISK"
-       exit 1
-    fi
-    
-    ls -l $DISK
-    cat <<EOF
-
-Install finished, base image $DISK created
-
-You may wish to run
-   chattr +i $DISK
-To ensure that this image does not change
-
-EOF
-}
-
-
-
-###############################
-# boot the base disk
-boot_base() {
-    CLUSTER="$1"
-
-    NAME="$BASENAME"
-    DISK="$VIRTBASE/$NAME.img"
-
-    rm -rf tmp
-    mkdir -p tmp
-
-    IPNUM=$FIRSTIP
-    CLUSTER="base"
-
-    mount_disk $DISK
-    setup_base
-    unmount_disk
-
-    UUID=`uuidgen`
-    
-    echo "Creating $NAME.xml"
-    substitute_vars $BOOT_TEMPLATE tmp/$NAME.xml
-    
-    # boot the base system
-    virsh create tmp/$NAME.xml
-}
-
-###############################
-# test the proxy setup
-test_proxy() {
-    export http_proxy=$WEBPROXY
-    wget -O /dev/null $INSTALL_SERVER
-    echo "Proxy OK"
-}
-
-######################################################################
-
-
-############################
-# parse command line options
-temp=$(getopt -n "$prog" -o "c:xh" -l help -- "$@")
-
-[ $? != 0 ] && usage
-
-eval set -- "$temp"
-
-while true ; do
-    case "$1" in
-       -c) config="$2" ; shift; shift ;;
-       -x) set -x; shift ;;
-       --) shift ; break ;;
-       -h|--help|*) usage ;; # Shouldn't happen, so this is reasonable.
-    esac
-done
-
-. "$config"
-. "$installdir/functions"
-
-# check for needed programs 
-check_command nbd-client
-check_command expect
-check_command qemu-nbd
-
-[ $# -lt 1 ] && usage
-
-command="$1"
-shift
-
-case $command in
-    create)
-       type=$1
-       shift
-       case $type in
-           base)
-               [ $# != 0 ] && usage
-               create_base;
-               ;;
-           cluster)
-               [ $# != 1 ] && usage
-               create_cluster "$1";
-               ;;
-           node)
-               [ $# != 2 ] && usage
-               create_node "$1" "$2";
-               ;;
-           tsm)
-               [ $# != 1 ] && usage
-               create_tsm "$1";
-               ;;
-           *)
-               usage;
-               ;;
-       esac
-       ;;
-    mount)
-       [ $# != 1 ] && usage
-       mount_disk "$1"
-       ;;
-    unmount)
-       [ $# != 0 ] && usage
-       unmount_disk
-       ;;
-    bootbase)
-       boot_base;
-       ;;
-    testproxy)
-       test_proxy;
-       ;;
-    *)
-       usage;
-       ;;
-esac
-
-