1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-22 13:33:52 +03:00

Common file paths in tm_common.sh (#255)

This commit is contained in:
Jaime Melis 2010-08-13 13:51:06 +02:00
parent 92c31a5052
commit 5707604e97
20 changed files with 83 additions and 64 deletions

View File

@ -49,7 +49,7 @@ log "DST: $DST_PATH"
DST_DIR=`dirname $DST_PATH`
log "Creating directory $DST_DIR"
exec_and_log "ssh $DST_HOST mkdir -p $DST_DIR"
exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR"
case $SRC in
#------------------------------------------------------------------------------
@ -57,11 +57,11 @@ case $SRC in
#------------------------------------------------------------------------------
http://*)
log "Creating LV $LV_NAME"
exec_and_log "ssh $DST_HOST sudo lvcreate -L$SIZE -n $LV_NAME $VG_NAME"
exec_and_log "ssh $DST_HOST ln -s /dev/$VG_NAME/$LV_NAME $DST_PATH"
exec_and_log "$SSH $DST_HOST $SUDO $LVCREATE -L$SIZE -n $LV_NAME $VG_NAME"
exec_and_log "$SSH $DST_HOST ln -s /dev/$VG_NAME/$LV_NAME $DST_PATH"
log "Dumping Image into /dev/$VG_NAME/$LV_NAME"
exec_and_log "eval ssh $DST_HOST 'wget $SRC -q -O- | sudo dd of=/dev/$VG_NAME/$LV_NAME bs=64k'"
exec_and_log "eval $SSH $DST_HOST '$WGET $SRC -q -O- | $SUDO $DD of=/dev/$VG_NAME/$LV_NAME bs=64k'"
;;
#------------------------------------------------------------------------------
@ -69,8 +69,8 @@ http://*)
#------------------------------------------------------------------------------
*:/dev/*)
log "Cloning LV $LV_NAME"
exec_and_log "ssh $DST_HOST sudo lvcreate -s -L$SIZE -n $LV_NAME $SRC_PATH"
exec_and_log "ssh $DST_HOST ln -s /dev/$VG_NAME/$LV_NAME $DST_PATH"
exec_and_log "$SSH $DST_HOST $SUDO $LVCREATE -s -L$SIZE -n $LV_NAME $SRC_PATH"
exec_and_log "$SSH $DST_HOST ln -s /dev/$VG_NAME/$LV_NAME $DST_PATH"
;;
#------------------------------------------------------------------------------
@ -78,10 +78,10 @@ http://*)
#------------------------------------------------------------------------------
*)
log "Creating LV $LV_NAME"
exec_and_log "ssh $DST_HOST sudo lvcreate -L$SIZE -n $LV_NAME $VG_NAME"
exec_and_log "ssh $DST_HOST ln -s /dev/$VG_NAME/$LV_NAME $DST_PATH"
exec_and_log "$SSH $DST_HOST $SUDO $LVCREATE -L$SIZE -n $LV_NAME $VG_NAME"
exec_and_log "$SSH $DST_HOST ln -s /dev/$VG_NAME/$LV_NAME $DST_PATH"
log "Dumping Image"
exec_and_log "eval cat $SRC_PATH | ssh $DST_HOST sudo dd of=/dev/$VG_NAME/$LV_NAME bs=64k"
exec_and_log "eval cat $SRC_PATH | $SSH $DST_HOST $SUDO $DD of=/dev/$VG_NAME/$LV_NAME bs=64k"
;;
esac

View File

@ -41,7 +41,7 @@ fi
DST_PATH=`arg_path $DST`
DST_DIR=`dirname $DST_PATH`
DST_FILE=`basename $DST_PATH`
DST_HASH=`echo -n $DST | md5sum | awk '{print $1}'`
DST_HASH=`echo -n $DST | $MD5SUM | $AWK '{print $1}'`
TMP_DIR="$ONE_LOCATION/var/$DST_HASH"
ISO_DIR="$TMP_DIR/isofiles"
@ -51,7 +51,7 @@ exec_and_log "mkdir -p $ISO_DIR"
for f in $SRC; do
case $f in
http://*)
exec_and_log "wget -O $ISO_DIR $f"
exec_and_log "$WGET -O $ISO_DIR $f"
;;
*)
@ -60,7 +60,7 @@ for f in $SRC; do
esac
done
exec_and_log "mkisofs -o $TMP_DIR/$DST_FILE -J -R $ISO_DIR"
exec_and_log "scp $TMP_DIR/$DST_FILE $DST"
exec_and_log "$MKISOFS -o $TMP_DIR/$DST_FILE -J -R $ISO_DIR"
exec_and_log "$SCP $TMP_DIR/$DST_FILE $DST"
exec_and_log "rm -rf $TMP_DIR"

View File

@ -36,7 +36,7 @@ SRC_HOST=`arg_host $SRC`
VID=`get_vid $SRC_PATH`
log "Deleting remote LVs"
exec_and_log "ssh $SRC_HOST sudo lvremove -f \$(echo $VG_NAME/\$(sudo lvs --noheadings $VG_NAME|awk '{print \$1}'|grep lv-one-$VID))"
exec_and_log "$SSH $SRC_HOST $SUDO $LVREMOVE -f \$(echo $VG_NAME/\$($SUDO $LVS --noheadings $VG_NAME|$AWK '{print \$1}'|grep lv-one-$VID))"
log "Deleting $SRC_PATH"
exec_and_log "ssh $SRC_HOST rm -rf $SRC_PATH"
exec_and_log "$SSH $SRC_HOST rm -rf $SRC_PATH"

View File

@ -28,12 +28,12 @@ DEFAULT_LV_SIZE="1G"
# -------------------------------------------------------------------------- #
function get_vid {
echo $1 |sed -e 's%^.*/\([^/]*\)/images.*$%\1%'
echo $1 |$SED -e 's%^.*/\([^/]*\)/images.*$%\1%'
}
function get_lv_name {
VID=`get_vid $1`
DISK=`echo $1|awk -F. '{printf $NF}'`
DISK=`echo $1|$AWK -F. '{printf $NF}'`
echo "lv-one-$VID-$DISK"
}

View File

@ -32,7 +32,7 @@ DST_PATH=`arg_path $DST`
DST_HOST=`arg_host $DST`
DST_DIR=`dirname $DST_PATH`
exec_and_log "ssh $DST_HOST mkdir -p $DST_DIR"
exec_and_log "ssh $DST_HOST dd if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M"
exec_and_log "ssh $DST_HOST mkfs -t $FSTYPE -F $DST_PATH"
exec_and_log "ssh $DST_HOST chmod a+rw $DST_PATH"
exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR"
exec_and_log "$SSH $DST_HOST $DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M"
exec_and_log "$SSH $DST_HOST $MKFS -t $FSTYPE -F $DST_PATH"
exec_and_log "$SSH $DST_HOST chmod a+rw $DST_PATH"

View File

@ -33,11 +33,11 @@ DST_HOST=`arg_host $DST`
DST_DIR=`dirname $DST_PATH`
log "Creating ${SIZE}Mb image in $DST_PATH"
exec_and_log "ssh $DST_HOST mkdir -p $DST_DIR"
exec_and_log "ssh $DST_HOST dd if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M"
exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR"
exec_and_log "$SSH $DST_HOST $DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M"
log "Initializing swap space"
exec_and_log "ssh $DST_HOST /sbin/mkswap $DST_PATH"
exec_and_log "$SSH $DST_HOST $MKSWAP $DST_PATH"
exec_and_log "ssh $DST_HOST chmod a+w $DST_PATH"
exec_and_log "$SSH $DST_HOST chmod a+w $DST_PATH"

View File

@ -57,21 +57,21 @@ if [ "$SRC_HOST" != "$HOSTNAME" ]; then
lv=\$(readlink $SRC_PATH)
rm $SRC_PATH
touch $SRC_PATH
sudo dd if=\$lv of=$SRC_PATH bs=64k
$SUDO $DD if=\$lv of=$SRC_PATH bs=64k
else
exit 1
fi" | ssh $SRC_HOST "bash -s"
fi" | $SSH $SRC_HOST "$BASH -s"
[ "$?" != "0" ] && log_error "Error dumping LV to disk image"
log "Deleting remote LVs"
exec_and_log "ssh $SRC_HOST sudo lvremove -f \$(echo $VG_NAME/\$(sudo lvs --noheadings $VG_NAME|awk '{print \$1}'|grep lv-one-$VID))"
exec_and_log "$SSH $SRC_HOST $SUDO $LVREMOVE -f \$(echo $VG_NAME/\$($SUDO $LVS --noheadings $VG_NAME|$AWK '{print \$1}'|grep lv-one-$VID))"
fi
log "Moving $SRC_PATH"
exec_and_log "ssh $DST_HOST mkdir -p $DST_DIR"
exec_and_log "scp -r $SRC $DST"
exec_and_log "ssh $SRC_HOST rm -rf $SRC_PATH"
exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR"
exec_and_log "$SCP -r $SRC $DST"
exec_and_log "$SSH $SRC_HOST rm -rf $SRC_PATH"
if [ "$DST_HOST" != "$HOSTNAME" ]; then
log_error "This TM does not support resuming."

View File

@ -46,7 +46,7 @@ exec_and_log "chmod a+w $DST_DIR"
case $SRC in
http://*)
log "Downloading $SRC"
exec_and_log "wget -O $DST_PATH $SRC"
exec_and_log "$WGET -O $DST_PATH $SRC"
;;
*)

View File

@ -51,7 +51,7 @@ exec_and_log "mkdir -p $ISO_DIR"
for f in $SRC; do
case $f in
http://*)
exec_and_log "wget -O $ISO_DIR $f"
exec_and_log "$WGET -O $ISO_DIR $f"
;;
*)
@ -60,7 +60,7 @@ for f in $SRC; do
esac
done
exec_and_log "mkisofs -o $DST_PATH -J -R $ISO_DIR"
exec_and_log "$MKISOFS -o $DST_PATH -J -R $ISO_DIR"
exec_and_log "rm -rf $ISO_DIR"

View File

@ -37,7 +37,7 @@ fix_dst_path
DST_DIR=`dirname $DST_PATH`
exec_and_log "mkdir -p $DST_DIR"
exec_and_log "dd if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M"
exec_and_log "mkfs -t $FSTYPE -F $DST_PATH"
exec_and_log "$DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M"
exec_and_log "$MKFS -t $FSTYPE -F $DST_PATH"
exec_and_log "chmod a+rw $DST_PATH"

View File

@ -40,10 +40,10 @@ exec_and_log "mkdir -p $DST_DIR"
exec_and_log "chmod a+w $DST_DIR"
log "Creating ${SIZE}Mb image in $DST_PATH"
exec_and_log "dd if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M"
exec_and_log "$DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M"
log "Initializing swap space"
exec_and_log "/sbin/mkswap $DST_PATH"
exec_and_log "$MKSWAP $DST_PATH"
exec_and_log "chmod a+w $DST_PATH"

View File

@ -40,19 +40,19 @@ log "DST: $DST_PATH"
DST_DIR=`dirname $DST_PATH`
log "Creating directory $DST_DIR"
exec_and_log "ssh $DST_HOST mkdir -p $DST_DIR"
exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR"
case $SRC in
http://*)
log "Downloading $SRC"
exec_and_log "ssh $DST_HOST wget -O $DST_PATH $SRC"
exec_and_log "$SSH $DST_HOST $WGET -O $DST_PATH $SRC"
;;
*)
log "Cloning $SRC"
exec_and_log "scp $SRC $DST"
exec_and_log "$SCP $SRC $DST"
;;
esac
exec_and_log "ssh $DST_HOST chmod a+rw $DST_PATH"
exec_and_log "$SSH $DST_HOST chmod a+rw $DST_PATH"

View File

@ -41,7 +41,7 @@ fi
DST_PATH=`arg_path $DST`
DST_DIR=`dirname $DST_PATH`
DST_FILE=`basename $DST_PATH`
DST_HASH=`echo -n $DST | md5sum | awk '{print $1}'`
DST_HASH=`echo -n $DST | $MD5SUM | $AWK '{print $1}'`
TMP_DIR="$ONE_LOCATION/var/$DST_HASH"
ISO_DIR="$TMP_DIR/isofiles"
@ -51,7 +51,7 @@ exec_and_log "mkdir -p $ISO_DIR"
for f in $SRC; do
case $f in
http://*)
exec_and_log "wget -O $ISO_DIR $f"
exec_and_log "$WGET -O $ISO_DIR $f"
;;
*)
@ -60,7 +60,7 @@ for f in $SRC; do
esac
done
exec_and_log "mkisofs -o $TMP_DIR/$DST_FILE -J -R $ISO_DIR"
exec_and_log "scp $TMP_DIR/$DST_FILE $DST"
exec_and_log "$MKISOFS -o $TMP_DIR/$DST_FILE -J -R $ISO_DIR"
exec_and_log "$SCP $TMP_DIR/$DST_FILE $DST"
exec_and_log "rm -rf $TMP_DIR"

View File

@ -31,4 +31,4 @@ SRC_PATH=`arg_path $SRC`
SRC_HOST=`arg_host $SRC`
log "Deleting $SRC_PATH"
exec_and_log "ssh $SRC_HOST rm -rf $SRC_PATH"
exec_and_log "$SSH $SRC_HOST rm -rf $SRC_PATH"

View File

@ -32,7 +32,7 @@ DST_PATH=`arg_path $DST`
DST_HOST=`arg_host $DST`
DST_DIR=`dirname $DST_PATH`
exec_and_log "ssh $DST_HOST mkdir -p $DST_DIR"
exec_and_log "ssh $DST_HOST dd if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M"
exec_and_log "ssh $DST_HOST mkfs -t $FSTYPE -F $DST_PATH"
exec_and_log "ssh $DST_HOST chmod a+rw $DST_PATH"
exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR"
exec_and_log "$SSH $DST_HOST $DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M"
exec_and_log "$SSH $DST_HOST $MKFS -t $FSTYPE -F $DST_PATH"
exec_and_log "$SSH $DST_HOST chmod a+rw $DST_PATH"

View File

@ -33,11 +33,11 @@ DST_HOST=`arg_host $DST`
DST_DIR=`dirname $DST_PATH`
log "Creating ${SIZE}Mb image in $DST_PATH"
exec_and_log "ssh $DST_HOST mkdir -p $DST_DIR"
exec_and_log "ssh $DST_HOST dd if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M"
exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR"
exec_and_log "$SSH $DST_HOST $DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M"
log "Initializing swap space"
exec_and_log "ssh $DST_HOST /sbin/mkswap $DST_PATH"
exec_and_log "$SSH $DST_HOST $MKSWAP $DST_PATH"
exec_and_log "ssh $DST_HOST chmod a+w $DST_PATH"
exec_and_log "$SSH $DST_HOST chmod a+w $DST_PATH"

View File

@ -36,6 +36,6 @@ DST_HOST=`arg_host $DST`
DST_DIR=`dirname $DST_PATH`
log "Moving $SRC_PATH"
exec_and_log "ssh $DST_HOST mkdir -p $DST_DIR"
exec_and_log "scp -r $SRC $DST"
exec_and_log "ssh $SRC_HOST rm -rf $SRC_PATH"
exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR"
exec_and_log "$SCP -r $SRC $DST"
exec_and_log "$SSH $SRC_HOST rm -rf $SRC_PATH"

View File

@ -22,6 +22,24 @@ else
ONE_LOCAL_VAR=$ONE_LOCATION/var
fi
# Paths for utilities
AWK=/usr/bin/awk
BASH=/bin/bash
DATE=/bin/date
DD=/bin/dd
LVCREATE=/sbin/lvcreate
LVREMOVE=/sbin/lvremove
LVS=/sbin/lvs
MD5SUM=/usr/bin/md5sum
MKFS=/sbin/mkfs
MKISOFS=/usr/bin/mkisofs
MKSWAP=/sbin/mkswap
SCP=/usr/bin/scp
SED=/bin/sed
SSH=/usr/bin/ssh
SUDO=/usr/bin/sudo
WGET=/usr/bin/wget
function get_vmdir
{
VMDIR=`cat $ONE_CONF | grep ^VM_DIR= | cut -d= -f2`
@ -55,7 +73,7 @@ SCRIPT_NAME=`basename $0`
# Formats date for logs
function log_date
{
date +"%a %b %d %T %Y"
$DATE +"%a %b %d %T %Y"
}
# Logs a message
@ -83,13 +101,13 @@ function error_message
# Gets the host from an argument
function arg_host
{
echo $1 | sed -e 's/^\([^:]*\):.*$/\1/'
echo $1 | $SED -e 's/^\([^:]*\):.*$/\1/'
}
# Gets the path from an argument
function arg_path
{
echo $1 | sed -e 's/^[^:]*:\(.*\)$/\1/'
echo $1 | $SED -e 's/^[^:]*:\(.*\)$/\1/'
}
# Executes a command, if it fails return error message and exits
@ -145,3 +163,4 @@ function timeout_exec_and_log
exit $CMD_CODE
fi
}

View File

@ -34,12 +34,12 @@ log "$1 $2"
case $SRC in
http://*)
log "Downloading $SRC"
exec_and_log "ssh $DST_HOST wget -O $DST_PATH $SRC_PATH"
exec_and_log "$SSH $DST_HOST $WGET -O $DST_PATH $SRC_PATH"
;;
*)
log "Cloning $SRC"
VM_ID=`echo $DST | sed -e 's/.*\/\([0-9]\+\)\/images\/.*/\1/'`
VM_ID=`echo $DST | $SED -e 's/.*\/\([0-9]\+\)\/images\/.*/\1/'`
cp -r $SRC_PATH $DATASTORE_PATH/one-$VM_ID &>/dev/null
mv $DATASTORE_PATH/one-$VM_ID/*.vmx $DATASTORE_PATH/one-$VM_ID/one-$VM_ID.vmx
;;

View File

@ -25,7 +25,7 @@ fi
. $TMCOMMON
# We just need the <vid> bit
VM_ID=`echo $1 | sed -e 's/.*\/\([0-9]\+\)\/images\/.*/\1/'`
VM_ID=`echo $1 | $SED -e 's/.*\/\([0-9]\+\)\/images\/.*/\1/'`
log "Deleting $SRC_PATH"
exec_and_log "rm -rf $DATASTORE_PATH/one-$VM_ID"