mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-12 08:58:17 +03:00
feature #2097: VMFS TM driver now uses SSH protocol to handle disk images.
This commit is contained in:
parent
0c9034066f
commit
9ac61d085e
@ -282,7 +282,16 @@ function mkfs_command {
|
||||
;;
|
||||
"vmdk_"*)
|
||||
VMWARE_DISK_TYPE=`echo $FSTYPE|cut -d'_' -f 2`
|
||||
|
||||
echo "$VMWARE_DISK_TYPE" | \
|
||||
grep '\<thin\>\|\<zeroedthic\>\|\<eagerzeroedthick\>' 2>&1 /dev/null
|
||||
|
||||
if [ $? -eq 1 ] ; then
|
||||
VMWARE_DISK_TYPE="thin"
|
||||
fi
|
||||
|
||||
echo "$VMKFSTOOLS -U $DST/disk.vmdk; \
|
||||
rm -f $DST/*; \
|
||||
$VMKFSTOOLS -c ${SIZE}M -d ${VMWARE_DISK_TYPE} $DST/disk.vmdk"
|
||||
return 0
|
||||
;;
|
||||
@ -462,43 +471,3 @@ function iqn_get_host {
|
||||
VG_NAME=$(iqn_get_vg_name "$IQN")
|
||||
echo ${TARGET%%.$VG_NAME.$LV_NAME}
|
||||
}
|
||||
|
||||
function vmfs_create_remote_path {
|
||||
DS_ID=$1
|
||||
# Create DST in DST_HOST
|
||||
if [ "${USE_SSH,,}" == "yes" ]; then
|
||||
exec_and_log "ssh_make_path $DST_HOST /vmfs/volumes/$DS_ID/$DST_FOLDER" \
|
||||
"Cannot create /vmfs/volumes/$DS_ID/$DST_FOLDER in $DST_HOST"
|
||||
else
|
||||
exec_and_log "vifs $VI_PARAMS --mkdir [$DS_ID]$DST_FOLDER" \
|
||||
"Cannot create [$DS_ID]$DST_FOLDER in $DST_HOST"
|
||||
fi
|
||||
}
|
||||
|
||||
function vmfs_set_up {
|
||||
if [ "${USE_SSH,,}" != "yes" ]; then
|
||||
USERNAME=`echo $(cat $VMWARERC |grep ":username:"|cut -d":" -f 3|tr -d '"')`
|
||||
PASSWORD=`echo $(cat $VMWARERC |grep ":password:"|cut -d":" -f 3|tr -d '"')`
|
||||
if [ -z $PASSWORD ]; then
|
||||
VI_PARAMS="--server $DST_HOST --username $USERNAME --password \"\""
|
||||
else
|
||||
VI_PARAMS="--server $DST_HOST --username $USERNAME --password $PASSWORD"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function vmfs_create_double_path {
|
||||
DS_ID=$1
|
||||
FIRST_FOLDER=$2
|
||||
SECOND_FOLDER=$3
|
||||
# Two calls needed since vifs cannot do a mkdir -p
|
||||
vifs $VI_PARAMS --force --mkdir [$DS_ID]$FIRST_FOLDER &> /dev/null
|
||||
vifs $VI_PARAMS --force --mkdir [$DS_ID]$FIRST_FOLDER/$SECOND_FOLDER &> /dev/null
|
||||
|
||||
}
|
||||
|
||||
function vmfs_create_simple_path {
|
||||
DS_ID=$1
|
||||
FIRST_FOLDER=$2
|
||||
vifs $VI_PARAMS --force --mkdir [$DS_ID]$FIRST_FOLDER &> /dev/null
|
||||
}
|
||||
|
@ -77,28 +77,6 @@ function make_relative {
|
||||
echo $dots${src#$common/}
|
||||
}
|
||||
|
||||
# Gets whether the vmfs drivers should use ssh or not
|
||||
function get_tm_use_ssh {
|
||||
DATASTORE_ID=$1
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Get datastore information
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
XPATH="${ONE_LOCAL_VAR}/remotes/datastore/xpath.rb --stdin"
|
||||
|
||||
unset i XPATH_ELEMENTS
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <(onedatastore show -x $DATASTORE_ID| $XPATH \
|
||||
/DATASTORE/TEMPLATE/TM_USE_SSH)
|
||||
|
||||
TM_USE_SSH="${XPATH_ELEMENTS[0]:-$TM_USE_SSH}"
|
||||
|
||||
echo ${TM_USE_SSH,,}
|
||||
}
|
||||
|
||||
#Return DISK_TYPE
|
||||
function disk_type
|
||||
{
|
||||
|
@ -41,52 +41,29 @@ fi
|
||||
. $TMCOMMON
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Retrieve needed information, set dst path and dir
|
||||
# Retrieve needed information, Example (same for SRC)
|
||||
# DST : esx1:/vmfs/volumes/105/90/disk.0
|
||||
# SRC : one:/vmfs/volumes/104/84045f4a
|
||||
# DST_PATH : /vmfs/volumes/105/90/disk.0
|
||||
# DST_DIR : /vmfs/volumes/105/90/
|
||||
# DST_HOST : esx1
|
||||
#
|
||||
# DISK_TYPE: CDROM if it is a cd (not a directory)
|
||||
#-------------------------------------------------------------------------------
|
||||
SRC_PATH=`arg_path $SRC`
|
||||
SRC_FOLDER=`basename $SRC_PATH`
|
||||
|
||||
SRC_PATH=`arg_path $SRC`
|
||||
DST_PATH=`arg_path $DST`
|
||||
|
||||
DST_HOST=`arg_host $DST`
|
||||
DST_DIR=`dirname $DST_PATH`
|
||||
DST_FOLDER=`basename $DST_PATH`
|
||||
IMAGE_DS_NAME=`basename $(dirname $SRC_PATH)`
|
||||
SYSTEM_DS_NAME=`basename $(dirname $(dirname $DST_PATH))`
|
||||
USE_SSH=$(get_tm_use_ssh $IMAGE_DS_NAME)
|
||||
|
||||
# Let's check if it is a CDROM
|
||||
DISK_TYPE=$(disk_type)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set up datastore
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
vmfs_set_up
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Create remote folder
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
if [ "$DISK_TYPE" != "CDROM" ]; then
|
||||
if [ "$USE_SSH" == "yes" ]; then
|
||||
ssh_make_path $DST_HOST $DST_PATH
|
||||
else
|
||||
vmfs_create_double_path $SYSTEM_DS_NAME $VMID $DST_FOLDER
|
||||
fi
|
||||
else
|
||||
if [ "$USE_SSH" == "yes" ]; then
|
||||
ssh_make_path $DST_HOST $(dirname $DST_PATH)
|
||||
else
|
||||
vmfs_create_simple_path $SYSTEM_DS_NAME $VMID
|
||||
fi
|
||||
fi
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Clone (cp) SRC into DST
|
||||
#-------------------------------------------------------------------------------
|
||||
log "Cloning $SRC_PATH in $DST"
|
||||
|
||||
if [ "$USE_SSH" == "yes" ]; then
|
||||
log "Cloning $SRC in $DST"
|
||||
|
||||
CLONESCRIPT=$(cat <<EOF
|
||||
cd $DST_DIR
|
||||
@ -94,42 +71,27 @@ cd $DST_DIR
|
||||
export PATH=/usr/sbin:/sbin:\$PATH
|
||||
|
||||
if [ "$DISK_TYPE" != "CDROM" ]; then
|
||||
if [ ! -d $DST_PATH ]; then
|
||||
mkdir -p $DST_PATH
|
||||
fi
|
||||
|
||||
$VMKFSTOOLS -U $DST_PATH/disk.vmdk
|
||||
rm $DST_PATH/*
|
||||
rm -f $DST_PATH/*
|
||||
|
||||
$VMKFSTOOLS -i $SRC_PATH/disk.vmdk -d thin $DST_PATH/disk.vmdk
|
||||
else
|
||||
rm $DST_PATH
|
||||
if [ ! -d $DST_DIR ]; then
|
||||
mkdir -p $DST_DIR
|
||||
fi
|
||||
|
||||
rm -f $DST_PATH
|
||||
|
||||
cp $SRC_PATH $DST_PATH
|
||||
ln -s $DST_PATH $DST_PATH.iso
|
||||
fi
|
||||
|
||||
EOF
|
||||
)
|
||||
ssh_exec_and_log $DST_HOST "$CLONESCRIPT" "Error cloning $SRC to $DST"
|
||||
else
|
||||
if [ "$DISK_TYPE" != "CDROM" ]; then
|
||||
$VMKFSTOOLS $VI_PARAMS -U \
|
||||
[$SYSTEM_DS_NAME]$VMID/$DST_FOLDER/disk.vmdk &> /dev/null
|
||||
|
||||
# Erase in case that vmkfstool didn't recognize the disk
|
||||
FILES_TO_ERASE=`vifs $VI_PARAMS --dir [$SYSTEM_DS_NAME]$VMID/$DST_FOLDER|\
|
||||
grep -v "Content Listing"|grep -v "\-\-\-\-\-\-\-\-"|egrep -v "^[[:space:]]*$"`
|
||||
for file in $FILES_TO_ERASE; do
|
||||
vifs $VI_PARAMS --force --rm [$SYSTEM_DS_NAME]$VMID/$DST_FOLDER/$file
|
||||
done
|
||||
|
||||
exec_and_log \
|
||||
"$VMKFSTOOLS $VI_PARAMS -i [$IMAGE_DS_NAME]$SRC_FOLDER/disk.vmdk \
|
||||
-d thin [$SYSTEM_DS_NAME]$VMID/$DST_FOLDER/disk.vmdk" \
|
||||
"Error cloning $SRC to $DST"
|
||||
else
|
||||
vifs $VI_PARAMS --force --rm [$SYSTEM_DS_NAME]$VMID/$DST_PATH &> /dev/null
|
||||
exec_and_log \
|
||||
"vifs $VI_PARAMS -c [$IMAGE_DS_NAME]$(basename $SRC_PATH) \
|
||||
[$SYSTEM_DS_NAME]$VMID/$DST_FOLDER.iso" \
|
||||
"Cannot upload [$IMAGE_DS_NAME]$(basename $SRC_PATH) to \
|
||||
[$SYSTEM_DS_NAME]$VMID/$DST_FOLDER.iso on $DST_HOST"
|
||||
fi
|
||||
fi
|
||||
ssh_exec_and_log $DST_HOST "$CLONESCRIPT" "Error cloning $SRC to $DST"
|
||||
|
||||
exit 0
|
||||
|
@ -1,127 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
# context context.sh file1 file2 ... fileN host:remote_system_ds/disk.i vmid 0
|
||||
# - context.sh file are the contents of the context ISO
|
||||
# - host is the target host to deploy the VM
|
||||
# - remote_system_ds is the path for the system datastore in the host
|
||||
# - vmid is the id of the VM
|
||||
# - 0 is the target datastore (system)
|
||||
|
||||
ARGV=("$@")
|
||||
|
||||
DS_ID="${ARGV[$(($#-1))]}"
|
||||
VM_ID="${ARGV[$(($#-2))]}"
|
||||
DST="${ARGV[$(($#-3))]}"
|
||||
SRC=("${ARGV[@]:0:$(($#-3))}")
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
|
||||
VMWARERC=/etc/one/vmwarerc
|
||||
else
|
||||
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
|
||||
VMWARERC=$ONE_LOCATION/etc/vmwarerc
|
||||
fi
|
||||
|
||||
. $TMCOMMON
|
||||
|
||||
function exit_error
|
||||
{
|
||||
error_message "$ERROR"
|
||||
rm -rf $ISO_DIR > /dev/null 2>&1
|
||||
exit -1
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Retrieve needed information, set dst path and dir
|
||||
#-------------------------------------------------------------------------------
|
||||
DST_PATH=`arg_path $DST`
|
||||
DST_HOST=`arg_host $DST`
|
||||
DST_DIR=`dirname $DST_PATH`
|
||||
DST_FOLDER=`basename $DST_PATH`
|
||||
USE_SSH=$(get_tm_use_ssh $DS_ID)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set up datastore
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
vmfs_set_up
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Create remote folder
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
if [ "$USE_SSH" == "yes" ]; then
|
||||
ssh_make_path $DST_HOST $DST_DIR
|
||||
else
|
||||
vmfs_create_double_path $DS_ID $VM_ID $DST_FOLDER
|
||||
fi
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Build the Context Block device (locally) and copy it remotely
|
||||
#-------------------------------------------------------------------------------
|
||||
log "Generating context block device at $DST"
|
||||
|
||||
ISO_DIR="$DS_DIR/.isofiles/$VM_ID"
|
||||
ISO_FILE="$ISO_DIR/$VM_ID.iso"
|
||||
|
||||
exec_and_set_error "mkdir -p $ISO_DIR" \
|
||||
"Could not create tmp dir to make context dev"
|
||||
[ -n "$ERROR" ] && exit_error
|
||||
|
||||
for f in "${SRC[@]}"; do
|
||||
case "$f" in
|
||||
http://*)
|
||||
exec_and_set_error "$WGET -P $ISO_DIR $f" "Error downloading $f"
|
||||
;;
|
||||
*)
|
||||
if echo "$f" | grep -q ':'; then
|
||||
target=$(echo "$f"|cut -d':' -f2-)
|
||||
target="'$target'"
|
||||
f=$(echo "$f"|cut -d':' -f1)
|
||||
else
|
||||
target=""
|
||||
fi
|
||||
|
||||
exec_and_set_error "cp -R $f $ISO_DIR/$target" \
|
||||
"Error copying $f to $ISO_DIR"
|
||||
;;
|
||||
esac
|
||||
|
||||
[ -n "$ERROR" ] && exit_error
|
||||
done
|
||||
|
||||
exec_and_set_error "$MKISOFS -o $ISO_FILE -J -R $ISO_DIR" \
|
||||
"Error creating iso fs"
|
||||
[ -n "$ERROR" ] && exit_error
|
||||
|
||||
if [ "$USE_SSH" == "yes" ]; then
|
||||
exec_and_set_error "$SCP $ISO_FILE $DST_HOST:$DST_PATH.iso" \
|
||||
"Error copying context ISO to $DST"
|
||||
else
|
||||
# Copies the iso file with .iso suffix, needed for VMware CDROMs
|
||||
vifs $VI_PARAMS -f -rm [$DS_ID]$VM_ID/$DST_FOLDER.iso
|
||||
exec_and_set_error \
|
||||
"vifs $VI_PARAMS -p $ISO_FILE [$DS_ID]$VM_ID/$DST_FOLDER.iso" \
|
||||
"Error copying context ISO to [$DS_ID]$VM_ID/$DST_FOLDER.iso in $DST_HOST"
|
||||
fi
|
||||
|
||||
[ -n "$ERROR" ] && exit_error
|
||||
rm -rf $ISO_DIR > /dev/null 2>&1
|
||||
|
||||
exit 0
|
1
src/tm_mad/vmfs/context
Symbolic link
1
src/tm_mad/vmfs/context
Symbolic link
@ -0,0 +1 @@
|
||||
../common/context
|
@ -16,27 +16,6 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
function vifs_rmdir {
|
||||
DIR_TO_RM="$1"
|
||||
FILES_TO_ERASE=`vifs $VI_PARAMS --dir [$DSID]$VMID/$DIR_TO_RM | \
|
||||
grep -v "Content Listing"|grep -Fv -- "--------"|egrep -v "^[[:space:]]*$"`
|
||||
|
||||
for file in $FILES_TO_ERASE; do
|
||||
exec_and_log \
|
||||
"vifs $VI_PARAMS --force --rm [$DSID]$VMID/$DIR_TO_RM/$file" \
|
||||
"Cannot delete [$DSID]$VMID/$DIR_TO_RM/$file in $DST_HOST"
|
||||
done
|
||||
|
||||
exec_and_log "vifs $VI_PARAMS --force --rm [$DSID]$VMID/$DIR_TO_RM" \
|
||||
"Cannot delete [$DSID]$VMID in $DST_HOST"
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
# DELETE <host:remote_system_ds/disk.i|host:remote_system_ds/> vmid dsid
|
||||
# - host is the target host to deploy the VM
|
||||
# - remote_system_ds is the path for the system datastore in the host
|
||||
@ -56,57 +35,26 @@ fi
|
||||
|
||||
. $TMCOMMON
|
||||
|
||||
DST_PATH=`arg_path $DST`
|
||||
DST_HOST=`arg_host $DST`
|
||||
|
||||
#Get the System DS ID based in PATH. dsid argument is for the image DS
|
||||
if [ `is_disk $DST_PATH` -eq 1 ]; then
|
||||
DSID=$(basename $(dirname $(dirname $DST)))
|
||||
else
|
||||
DSID=$(basename $(dirname $DST))
|
||||
fi
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Retrieve needed information
|
||||
# DST : esx1:/vmfs/volumes/105/90/disk.0
|
||||
# DST_PATH : /vmfs/volumes/105/90/disk.0
|
||||
# DST_HOST : esx1
|
||||
# DSID : 105
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
USE_SSH=$(get_tm_use_ssh $DSID)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set up datastore
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
vmfs_set_up
|
||||
DST_PATH=`arg_path $DST`
|
||||
DST_HOST=`arg_host $DST`
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Return if deleting a disk, we will delete them when removing the
|
||||
# remote_system_ds directory for the VM (remotely)
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
log "Deleting $DST_PATH"
|
||||
|
||||
if [ "$USE_SSH" == "yes" ]; then
|
||||
ssh_exec_and_log $DST_HOST "rm -rf $DST_PATH" "Error deleting $DST_PATH"
|
||||
if [ `is_disk $DST_PATH` -eq 1 ]; then
|
||||
exit 0
|
||||
else
|
||||
if [ `is_disk $DST_PATH` -eq 1 ]; then
|
||||
DISK_TYPE=$(disk_type)
|
||||
DISK_NAME=$(basename $DST_PATH)
|
||||
|
||||
if [ "$DISK_TYPE" != "CDROM" ]; then
|
||||
vifs_rmdir $DISK_NAME
|
||||
else
|
||||
exec_and_log \
|
||||
"vifs $VI_PARAMS --force --rm [$DSID]$VMID/$DISK_NAME.iso" \
|
||||
"Cannot delete [$DSID]$VMID/$DISK_NAME.iso in $DST_HOST"
|
||||
fi
|
||||
else
|
||||
DIRS_TO_ERASE=`vifs $VI_PARAMS --dir [$DSID]$VMID|\
|
||||
grep -v "Content Listing"|grep -Fv -- "--------"|egrep -v "^[[:space:]]*$"`
|
||||
|
||||
for dir in $DIRS_TO_ERASE; do
|
||||
vifs_rmdir $dir
|
||||
done
|
||||
fi
|
||||
ssh_exec_and_log $DST_HOST "rm -rf $DST_PATH" "Error deleting $DST_PATH"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
@ -38,60 +38,57 @@ fi
|
||||
|
||||
. $TMCOMMON
|
||||
|
||||
#-v ------------------------------------------------------------------------------
|
||||
# Retrieve needed information, Example (same for SRC)
|
||||
# DST : esx1:/vmfs/volumes/105/90/disk.0
|
||||
# SRC : one:/vmfs/volumes/104/84045f4a
|
||||
# DST_PATH : /vmfs/volumes/105/90/disk.0
|
||||
# DST_DIR : /vmfs/volumes/105/90/
|
||||
# DST_HOST : esx1
|
||||
#
|
||||
# DISK_TYPE: CDROM if it is a cd (not a directory)
|
||||
#-------------------------------------------------------------------------------
|
||||
# Retrieve needed information, set dst path and dir
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
SRC_PATH=`arg_path $SRC`
|
||||
DST_PATH=`arg_path $DST`
|
||||
|
||||
DST_HOST=`arg_host $DST`
|
||||
DST_DIR=`dirname $DST_PATH`
|
||||
|
||||
SRC_ARG_PATH=`arg_path $SRC`
|
||||
|
||||
DST_DS_PATH="$(dirname $(dirname $(dirname $DST_PATH)))"
|
||||
SRC_DS_PATH="$(dirname $(dirname $SRC_ARG_PATH))"
|
||||
|
||||
SRC_PATH="${DST_DS_PATH}${SRC_ARG_PATH##$SRC_DS_PATH}"
|
||||
|
||||
USE_SSH=$(get_tm_use_ssh $DSID)
|
||||
DISK_TYPE=$(disk_type)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Link (ln) SRC into DST
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
if [ "$USE_SSH" == "yes" ]; then
|
||||
if [ "$DISK_TYPE" != "CDROM" ]; then
|
||||
log "Link all files in $SRC_PATH to $DST_PATH"
|
||||
|
||||
# Let's check if it is a CDROM
|
||||
DISK_TYPE=$(disk_type)
|
||||
LINK_SCRIPT=$(cat <<EOF
|
||||
if [ ! -d $DST_PATH ]; then
|
||||
mkdir -p $DST_PATH
|
||||
fi
|
||||
|
||||
if [ "$DISK_TYPE" != "CDROM" ]; then
|
||||
ssh_make_path $DST_HOST $DST_PATH
|
||||
|
||||
log "Link all files in $SRC_PATH to $DST_PATH"
|
||||
|
||||
LINK_SCRIPT=$(cat <<EOF
|
||||
for file in \$(find $SRC_PATH -type f); do
|
||||
(cd $DST_PATH ; ln -sf \$file)
|
||||
done
|
||||
EOF
|
||||
)
|
||||
ssh_exec_and_log $DST_HOST "$LINK_SCRIPT" \
|
||||
"Could not link dir files from $SRC_PATH to $DST_PATH"
|
||||
else
|
||||
# Just need to create the /<vid> folder, not the disk.<n> as well
|
||||
ssh_make_path $DST_HOST $(dirname $DST_PATH)
|
||||
ssh_exec_and_log $DST_HOST "$LINK_SCRIPT" \
|
||||
"Error linking files from $SRC_PATH to $DST_PATH"
|
||||
else
|
||||
log "Link CD-ROM from $SRC_PATH to $DST_PATH"
|
||||
|
||||
log "Link CD-ROM from $SRC_PATH to $DST_PATH"
|
||||
LINK_SCRIPT=$(cat <<EOF
|
||||
if [ ! -d $DST_DIR ]; then
|
||||
mkdir -p $DST_DIR
|
||||
fi
|
||||
|
||||
LINK_SCRIPT=$(cat <<EOF
|
||||
ln -s $SRC_PATH $DST_PATH.iso
|
||||
EOF
|
||||
)
|
||||
ssh_exec_and_log $DST_HOST "$LINK_SCRIPT" \
|
||||
"Could not link CDROM ISO file from $SRC_PATH to system $DST_PATH"
|
||||
fi
|
||||
else
|
||||
log "Cannot link files without SSH enabled on the ESX hosts, calling clone"
|
||||
exec $(dirname $0)/clone $*
|
||||
ssh_exec_and_log $DST_HOST "$LINK_SCRIPT" \
|
||||
"Error linking CDROM ISO file from $SRC_PATH to $DST_PATH"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
@ -42,21 +42,14 @@ fi
|
||||
. $TMCOMMON
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Retrieve needed information, set dst path and dir
|
||||
# Retrieve needed information
|
||||
# DST : esx1:/vmfs/volumes/105/90/disk.0
|
||||
# DST_PATH : /vmfs/volumes/105/90/disk.0
|
||||
# DST_HOST : esx1
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
DST_PATH=`arg_path $DST`
|
||||
DST_HOST=`arg_host $DST`
|
||||
DST_DIR=`dirname $DST_PATH`
|
||||
DST_FOLDER=`basename $DST_PATH`
|
||||
|
||||
USE_SSH=$(get_tm_use_ssh $DSID)
|
||||
SYSTEM_DS_NAME=`basename $(dirname $(dirname $DST_PATH))`
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set up datastore
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
vmfs_set_up
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Make the new image (file-based)
|
||||
@ -64,34 +57,19 @@ vmfs_set_up
|
||||
|
||||
log "Making filesystem of ${SIZE}M and type $FSTYPE at $DST"
|
||||
|
||||
if [ "$USE_SSH" == "yes" ]; then
|
||||
ssh_make_path $DST_HOST $DST_PATH
|
||||
MKFS_CMD=`mkfs_command $DST_PATH $FSTYPE $SIZE`
|
||||
MKFS_CMD=`mkfs_command $DST_PATH $FSTYPE $SIZE`
|
||||
|
||||
MKSCRIPT=$(cat <<EOF
|
||||
rm $DST_PATH/*
|
||||
export PATH=/usr/sbin:/sbin:\$PATH
|
||||
|
||||
if [ ! -d $DST_PATH ]; then
|
||||
mkdir -p $DST_PATH
|
||||
fi
|
||||
|
||||
$MKFS_CMD
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log $DST_HOST "$MKSCRIPT" "Could not create image $DST_PATH"
|
||||
else
|
||||
vmfs_create_double_path $SYSTEM_DS_NAME $VMID $DST_FOLDER
|
||||
|
||||
VMWARE_DISK_TYPE=`echo $FSTYPE|cut -d'_' -f 2`
|
||||
$VMKFSTOOLS $VI_PARAMS -U [$SYSTEM_DS_NAME]$VMID/$DST_FOLDER/disk.vmdk &> /dev/null
|
||||
|
||||
# Erase in case that vmkfstool didn't recognize the disk
|
||||
FILES_TO_ERASE=`vifs $VI_PARAMS --dir [$SYSTEM_DS_NAME]$VMID/$DST_FOLDER|\
|
||||
grep -v "Content Listing"|grep -v "\-\-\-\-\-\-\-\-"|egrep -v "^[[:space:]]*$"`
|
||||
for file in $FILES_TO_ERASE; do
|
||||
vifs $VI_PARAMS --force --rm [$SYSTEM_DS_NAME]$VMID/$DST_FOLDER/$file
|
||||
done
|
||||
|
||||
exec_and_log "$VMKFSTOOLS $VI_PARAMS -c ${SIZE}M -d ${VMWARE_DISK_TYPE}\
|
||||
[$SYSTEM_DS_NAME]$VMID/$DST_FOLDER/disk.vmdk" \
|
||||
"Cannot create [$SYSTEM_DS_NAME]$VMID/$DST_FOLDER/disk.vmdk on $DST_HOST"
|
||||
fi
|
||||
ssh_exec_and_log $DST_HOST "$MKSCRIPT" "Could not create image $DST_PATH"
|
||||
|
||||
exit 0
|
||||
|
@ -41,15 +41,34 @@ fi
|
||||
. $TMCOMMON
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Retrieve needed information, Example (same for SRC)
|
||||
# SRC : esx1:/vmfs/volumes/105/90/disk.0
|
||||
# DST : one:/vmfs/volumes/104/84045f4a
|
||||
# SRC_PATH : /vmfs/volumes/105/90/disk.0
|
||||
# SRC_DISK : /vmfs/volumes/105/90/disk.0/disk.vmdk
|
||||
# SRC_HOST : esx1
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
function mvds_ssh {
|
||||
SRC_PATH=`arg_path $SRC`
|
||||
DST_PATH=`arg_path $DST`
|
||||
|
||||
SRC_DISK="$SRC_PATH/disk.vmdk"
|
||||
DST_DISK="$DST_PATH/disk.vmdk"
|
||||
|
||||
SRC_HOST=`arg_host $SRC`
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Move the image back to the datastore
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
log "Moving $SRC to $DST"
|
||||
|
||||
MVSCRIPT=$(cat <<EOF
|
||||
SRC_READLN=\$($READLINK -f $SRC_PATH)
|
||||
DST_READLN=\$($READLINK -f $DST_PATH)
|
||||
|
||||
if [ \( -L $SRC_PATH \) -a \( "$SRC_READLN" = "$DST_READLN" \) ] ; then
|
||||
SRC_DISK_LN=\$($READLINK -f $SRC_DISK)
|
||||
DST_DISK_LN=\$($READLINK -f $DST_DISK)
|
||||
|
||||
if [ \( -L $SRC_DISK \) -a \( "$SRC_DISK_LN" = "$DST_DISK_LN" \) ] ; then
|
||||
echo "Not moving files to image repo, they are the same"
|
||||
else
|
||||
$VMKFSTOOLS -U $DST_DISK
|
||||
@ -64,62 +83,6 @@ fi
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log $SRC_HOST "$MVSCRIPT" \
|
||||
"Could not move image $SRC_DISK_VMW to $DST_DISK_VMW"
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
function mvds_local {
|
||||
|
||||
$VMKFSTOOLS $VI_PARAMS -U $DST_DISK_VMW &> /dev/null
|
||||
|
||||
exec_and_log "$VMKFSTOOLS $VI_PARAMS -i $SRC_DISK_VMW -d thin $DST_DISK_VMW" \
|
||||
"Could not move image $SRC_DISK_VMW to $DST_DISK_VMW"
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Retrieve needed information, set dst path and dir
|
||||
#-------------------------------------------------------------------------------
|
||||
SRC_PATH=`arg_path $SRC`
|
||||
SRC_HOST=`arg_host $SRC`
|
||||
SRC_FOLDER=`basename $SRC_PATH`
|
||||
|
||||
DST_PATH=`arg_path $DST`
|
||||
DST_HOST=$SRC_HOST
|
||||
DST_FOLDER=`basename $DST_PATH`
|
||||
|
||||
USE_SSH=$(get_tm_use_ssh $DSID)
|
||||
|
||||
IMAGE_DS_NAME=`basename $(dirname $DST_PATH)`
|
||||
SYSTEM_DS_NAME=`basename $(dirname $(dirname $SRC_PATH))`
|
||||
|
||||
# Paths for disks
|
||||
SRC_DISK="$SRC_PATH/disk.vmdk"
|
||||
SRC_DISK_VMW="[$SYSTEM_DS_NAME]$VMID/$SRC_FOLDER/disk.vmdk"
|
||||
|
||||
DST_DISK="$DST_PATH/disk.vmdk"
|
||||
DST_DISK_VMW="[$IMAGE_DS_NAME]$DST_FOLDER/disk.vmdk"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set up datastore
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
vmfs_set_up
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Move the image back to the datastore
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
log "Moving $SRC_DISK_VMW to $DST_DISK_VMW"
|
||||
|
||||
if [ "$USE_SSH" == "yes" ]; then
|
||||
mvds_ssh
|
||||
else
|
||||
mvds_local
|
||||
fi
|
||||
ssh_exec_and_log $SRC_HOST "$MVSCRIPT" "Could not move image $SRC to $DST"
|
||||
|
||||
exit 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user