1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

feature #1020: Add common lib for tm functions. Fix deploy bug. Fix save bug in tm_mv. Add better linking of image files.

This commit is contained in:
Ruben S. Montero 2011-12-24 03:48:51 +01:00
parent d9aab98414
commit 0b449e3401
7 changed files with 87 additions and 54 deletions

View File

@ -728,6 +728,7 @@ LVM_TM_COMMANDS_LIB_FILES="src/tm_mad/lvm/tm_clone.sh \
VMWARE_TM_COMMANDS_LIB_FILES="src/tm_mad/vmware/tm_clone.sh \
src/tm_mad/vmware/tm_ln.sh \
src/tm_mad/vmware/tm_mv.sh \
src/tm_mad/vmware/functions.sh \
src/tm_mad/vmware/tm_context.sh"
#-------------------------------------------------------------------------------

View File

@ -0,0 +1,61 @@
# ---------------------------------------------------------------------------- #
# Copyright 2010-2011, C12G Labs S.L #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
# ---------------------------------------------------------------------------- #
#Symlinks the dst_path to dst_path.iso if it is an ISO file
function fix_iso {
dst_path=$1
if [ -f $dst_path ]; then
file -b $dst_path | grep "ISO 9660" > /dev/null 2>&1
if [ $? -eq 0 ]; then
bname=`basename $dst_path`
exec_and_log "ln -s $bname $dst_path/$bname.iso" \
"Can not link ISO file."
fi
fi
}
#Creates the VM dir
function create_vmdir {
dst_path=$1
log "Creating directory `basename $dst_path`"
exec_and_log "mkdir -p $dst_path"
exec_and_log "chmod a+rw $dst_path"
}
#Makes path src ($1) relative to dst ($2)
function make_relative {
src=$1
dst=$2
common=$dst
while [ -z "`echo $src | grep -E "^$common"`" ]; do
common=`dirname $common`
dots="../$dots"
done
echo $dots${src#$common/}
}
#Test if the source file is a disk (and not the image dir for the VM)
function is_disk {
echo $1 | grep -q 'disk\.[0-9]\+$' > /dev/null 2>&1
echo $?
}

View File

@ -26,6 +26,7 @@ else
fi
. $TMCOMMON
. "`dirname $0`/functions.sh"
get_vmdir
@ -37,34 +38,11 @@ fix_paths
log_debug "$1 $2"
log_debug "DST: $DST_PATH"
DST_DIR=`dirname $DST_PATH`
create_vmdir $DST_PATH
log "Creating directory $DST_DIR"
exec_and_log "rm -rf $DST_DIR"
exec_and_log "mkdir -p $DST_PATH"
exec_and_log "chmod a+w $DST_PATH"
log "Cloning $SRC_PATH"
case $SRC in
http://*)
log "Downloading $SRC"
exec_and_log "$WGET -O $DST_PATH $SRC" \
"Error downloading $SRC"
;;
*)
log "Cloning $SRC_PATH"
exec_and_log "cp -r $SRC_PATH/* $DST_PATH" \
"Error copying $SRC to $DST"
;;
esac
SRC_FILE_SUFFIX=`echo ${SRC_PATH##*.}`
if [ "x$SRC_FILE_SUFFIX" == "xiso" ]; then
cd $DST_DIR
DISK_NAME = `basename $DST_PATH`
ln -s $DISK_NAME $DISK_NAME.iso
fi
exec_and_log "chmod a+rw $DST_PATH"
exec_and_log "cp -r $SRC_PATH/* $DST_PATH" \
"Error copying $SRC to $DST"
fix_iso_file $DST_PATH

View File

@ -33,6 +33,7 @@ else
fi
. $TMCOMMON
. "`dirname $0`/functions.sh"
get_vmdir

View File

@ -26,6 +26,7 @@ else
fi
. $TMCOMMON
. "`dirname $0`/functions.sh"
get_vmdir
@ -34,30 +35,20 @@ DST_PATH=`arg_path $DST`
fix_dst_path
DST_DIR=`dirname $DST_PATH`
create_vmdir $DST_PATH
# SRC_PATH needs to be made relative to $ONE_LOCATION/var
VM_FOLDER_NAME=`basename $SRC_PATH`
REPO_NAME="images"
RELATIVE_SRC_PATH="../../$REPO_NAME/$VM_FOLDER_NAME"
log "Creating directory $DST_PATH"
exec_and_log "rm -rf $DST"
exec_and_log "mkdir -p $DST_PATH"
exec_and_log "chmod a+w $DST_PATH"
# ---------------------------------------------------------------------------- #
# Link all files of the disk directory. Note that link paths needs to be #
# relative in order to be accessible from the vSphere Data Store #
# ---------------------------------------------------------------------------- #
REL_SRC_PATH=`make_relative $SRC_PATH $DST_PATH`
log "Link all files in $SRC_PATH to $DST_PATH"
IMAGE_DIR=`dirname $DST_PATH`
cd $IMAGE_DIR
for file in `find $RELATIVE_SRC_PATH/* -type f`; do
file_name=`basename $file`
exec_and_log "ln -sf ../$file $DST_PATH/$file_name"
for file in `find $SRC_PATH -type f`; do
FNAME=`basename $file`
exec_and_log "ln -sf $REL_SRC_PATH/$FNAME $DST_PATH/$FNAME"
done
# Put the symlink mark for tm_mv
exec_and_log "ln -sf $RELATIVE_SRC_PATH $DST_PATH/.disk"
#Mark this disk persistent with a symlink for tm_mv and repo mv
exec_and_log "ln -sf $REL_SRC_PATH $DST_PATH/.disk"

View File

@ -28,6 +28,7 @@ else
fi
. $TMCOMMON
. "`dirname $0`/functions.sh"
get_vmdir
@ -41,13 +42,13 @@ SRC_PATH=`fix_dir_slashes "$SRC_PATH"`
if [ "$SRC_PATH" = "$DST_PATH" ]; then
log "Will not move, source and destination are equal"
elif [ -f "$SRC_PATH/.disk" ]; then # This link was set in tm_ln.sh
elif [ -L "$SRC_PATH/.disk" ]; then
 exec_and_log "mv $SRC_PATH/.disk $DST_PATH"
elif echo $SRC_PATH | grep -q 'disk\.[0-9]\+$'; then
   log "Moving $SRC_PATH"
elif [ "`is_disk $SRC_PATH`" = "0" ] ; then
log "Moving $SRC_PATH"
   exec_and_log "mv $SRC_PATH $DST_PATH"
elif [ -d $SRC_PATH ]; then
log "Will not move, is not saving image"
log "Will not move, is not saving a VM disk image"
else
log "Moving $SRC_PATH"
exec_and_log "mv $SRC_PATH $DST_PATH"

View File

@ -31,7 +31,7 @@ require 'vmwarelib'
dfile = ARGV[0]
host = ARGV[1]
id = ARGV[3]
id = ARGV[2]
vmware_drv = VMwareDriver.new(host, id)