diff options
author | Martin Schwenke <martin@meltin.net> | 2013-02-19 12:55:47 +1100 |
---|---|---|
committer | Martin Schwenke <martin@meltin.net> | 2013-02-19 12:55:47 +1100 |
commit | 0e2c4f51f4478e5b0e69649339864776a8b5144f (patch) | |
tree | 8059e24902c077f3ab1075d06ed50d1c935cc392 | |
parent | 37b2555b68320cd6c900d6879d08db82a481215f (diff) | |
download | autocluster-0e2c4f51f4478e5b0e69649339864776a8b5144f.tar.gz autocluster-0e2c4f51f4478e5b0e69649339864776a8b5144f.tar.xz autocluster-0e2c4f51f4478e5b0e69649339864776a8b5144f.zip |
New hook hack_disk_hooks to customise the value of $DISKautocluster-0.7
Works for base, system and shared disks.
Signed-off-by: Martin Schwenke <martin@meltin.net>
-rwxr-xr-x | autocluster | 40 | ||||
-rw-r--r-- | config.d/10shareddisk.defconf | 41 |
2 files changed, 55 insertions, 26 deletions
diff --git a/autocluster b/autocluster index 8d7ae2f..8f9fa30 100755 --- a/autocluster +++ b/autocluster @@ -167,6 +167,14 @@ clear_hooks () ############################## +# These hooks are intended to customise the value of $DISK. They have +# access to 1 argument ("base", "system", "shared") and the variables +# $VIRTBASE, $CLUSTER, $BASENAME (for "base"), $NAME (for "system"), +# $SHARED_DISK_NUM (for "shared"). A hook must be deterministic and +# should not be stateful, since they can be called multiple times for +# the same disk. +hack_disk_hooks="" + # common node creation stuff create_node_COMMON () { @@ -179,21 +187,29 @@ create_node_COMMON () die "Error: if BASE_FORMAT is \"qcow2\" then SYSTEM_DISK_FORMAT must also be \"qcow2\"." fi - IPNUM=$(($FIRSTIP + $ip_offset)) - DISK="${VIRTBASE}/${CLUSTER}/${NAME}.${SYSTEM_DISK_FORMAT}" - local base_disk="${VIRTBASE}/${BASENAME}.${BASE_FORMAT}" + local IPNUM=$(($FIRSTIP + $ip_offset)) + # Determine base image name. We use $DISK temporarily to allow + # the path to be hacked. + local DISK="${VIRTBASE}/${BASENAME}.${BASE_FORMAT}" if [ "$BASE_PER_NODE_TYPE" = "yes" ] ; then - base_disk="${VIRTBASE}/${BASENAME}-${type}.${BASE_FORMAT}" + DISK="${VIRTBASE}/${BASENAME}-${type}.${BASE_FORMAT}" fi + run_hooks hack_disk_hooks "base" + local base_disk="$DISK" - mkdir -p $VIRTBASE/$CLUSTER tmp + # Determine the system disk image name. + DISK="${VIRTBASE}/${CLUSTER}/${NAME}.${SYSTEM_DISK_FORMAT}" + run_hooks hack_disk_hooks "system" local di="$DISK" if [ "$DISK_FOLLOW_SYMLINKS" = "yes" -a -L "$DISK" ] ; then di=$(readlink "$DISK") fi rm -f "$di" + local di_dirname="${di%/*}" + mkdir -p "$di_dirname" + case "$SYSTEM_DISK_FORMAT" in qcow2) echo "Creating the disk..." @@ -229,6 +245,8 @@ create_node_COMMON () # Pull the UUID for this node out of the map. UUID=$(awk "\$1 == $ip_offset {print \$2}" $uuid_map) + mkdir -p tmp + echo "Creating $NAME.xml" substitute_vars $template_file tmp/$NAME.xml @@ -474,10 +492,11 @@ test_proxy() { kickstart_floppy_create_hooks= # create base image -create_base() { - - NAME="$BASENAME" - DISK="${VIRTBASE}/${NAME}.${BASE_FORMAT}" +create_base() +{ + local NAME="$BASENAME" + local DISK="${VIRTBASE}/${NAME}.${BASE_FORMAT}" + run_hooks hack_disk_hooks "base" mkdir -p $KVMLOG @@ -488,6 +507,9 @@ create_base() { if [ "$DISK_FOLLOW_SYMLINKS" = "yes" -a -L "$DISK" ] ; then di=$(readlink "$DISK") fi + rm -f "$di" + local di_dirname="${di%/*}" + mkdir -p "$di_dirname" echo "Creating the disk" qemu-img create -f $BASE_FORMAT "$di" $DISKSIZE diff --git a/config.d/10shareddisk.defconf b/config.d/10shareddisk.defconf index d53765d..7a62004 100644 --- a/config.d/10shareddisk.defconf +++ b/config.d/10shareddisk.defconf @@ -73,16 +73,18 @@ shared_disk_template () local -a devices=($(eval echo {${first}..z} {a..z}{a..z})) - local p c + local p SHARED_DISK_NUM local n=0 - for p in $(seq 1 $paths) ; do - for c in $(seq 1 $SHAREDDISK_COUNT) ; do + for SHARED_DISK_NUM in $(seq 1 $SHAREDDISK_COUNT) ; do + local DISK="${VIRTBASE}/${CLUSTER}/shared${SHARED_DISK_NUM}" + run_hooks hack_disk_hooks "shared" + for p in $(seq 1 $paths) ; do local dev="${devices[$n]}" [ -n "$dev" ] || die "Too many shared disks! The function shared_disk_template needs to be hacked to allow more shared disks..." cat <<EOF <disk type='file' device='disk'> <driver name='qemu' cache='@@SHARED_DISK_CACHE@@'/> - <source file='@@VIRTBASE@@/@@CLUSTER@@/shared${c}'/> + <source file='${DISK}'/> <target dev='@@SHARED_DISK_PREFIX@@${dev}' bus='@@SHARED_DISK_TYPE@@'/> </disk> EOF @@ -125,37 +127,42 @@ EOF fi echo "Creating ${SHAREDDISK_COUNT} shared disks" - local i - for i in $(seq 1 $SHAREDDISK_COUNT); do - local f="$VIRTBASE/$CLUSTER/shared$i" - if [ "$DISK_FOLLOW_SYMLINKS" = "yes" -a -L "$f" ] ; then - f=$(readlink "$f") + local SHARED_DISK_NUM + for SHARED_DISK_NUM in $(seq 1 $SHAREDDISK_COUNT); do + local DISK="$VIRTBASE/$CLUSTER/shared${SHARED_DISK_NUM}" + run_hooks hack_disk_hooks "shared" + local di="$DISK" + if [ "$DISK_FOLLOW_SYMLINKS" = "yes" -a -L "$DISK" ] ; then + di=$(readlink "$DISK") fi - rm -f "$f" + rm -f "$di" + local di_dirname="${di%/*}" + mkdir -p "$di_dirname" + if [ "$SHARED_DISK_TYPE" = "iscsi" ] ; then - dd if=/dev/zero seek=$SHAREDDISKSIZE bs=1 count=1 of="$f" + dd if=/dev/zero seek=$SHAREDDISKSIZE bs=1 count=1 of="$di" local paths=$SHARED_DISK_MULTIPATH_NUMPATHS # readability - local zc=$(printf "%03d" $i) + local zc=$(printf "%03d" $SHARED_DISK_NUM) local p for p in $(seq 1 $paths) ; do - local lun=$(($paths * ($i - 1) + $p)) + local lun=$(($paths * ($SHARED_DISK_NUM - 1) + $p)) # vendor_id AUTCLSTR used by /etc/init.d/iscsimultipath cat <<EOF >>"$iscsi_out" tgtadm --lld iscsi --mode logicalunit --op new \ --tid ${ISCSI_TID} --lun ${lun} \ - -b ${f} + -b ${DISK} tgtadm --lld iscsi --mode logicalunit --op update \ --tid ${ISCSI_TID} --lun ${lun} \ --params vendor_id=AUTCLSTR,product_id=${uc},product_rev=0001,scsi_sn=SHARE${zc} EOF done else - qemu-img create -f raw "$f" $SHAREDDISKSIZE + qemu-img create -f raw "$di" $SHAREDDISKSIZE fi # setup a nice ID at the start of the disk - "$SHARED_DISK_ID_GEN" "$i" > tmp/diskid - dd if=tmp/diskid of=$VIRTBASE/$CLUSTER/shared$i conv=notrunc bs=1 > /dev/null 2>&1 + "$SHARED_DISK_ID_GEN" "$SHARED_DISK_NUM" > tmp/diskid + dd if=tmp/diskid of="$di" conv=notrunc bs=1 > /dev/null 2>&1 head -n 1 tmp/diskid >>"$shared_disk_ids" done echo |