diff --git a/src/mad/sh/scripts_common.sh b/src/mad/sh/scripts_common.sh index c0dd9ccf2d..5644d45d2b 100644 --- a/src/mad/sh/scripts_common.sh +++ b/src/mad/sh/scripts_common.sh @@ -282,7 +282,16 @@ function mkfs_command { ;; "vmdk_"*) VMWARE_DISK_TYPE=`echo $FSTYPE|cut -d'_' -f 2` + + echo "$VMWARE_DISK_TYPE" | \ + grep '\\|\\|\' 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 -} diff --git a/src/tm_mad/tm_common.sh b/src/tm_mad/tm_common.sh index 30395b0b56..e4f8abdfb8 100644 --- a/src/tm_mad/tm_common.sh +++ b/src/tm_mad/tm_common.sh @@ -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 { diff --git a/src/tm_mad/vmfs/clone b/src/tm_mad/vmfs/clone index eaf8619503..f234de39d9 100755 --- a/src/tm_mad/vmfs/clone +++ b/src/tm_mad/vmfs/clone @@ -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 < /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 diff --git a/src/tm_mad/vmfs/context b/src/tm_mad/vmfs/context deleted file mode 100755 index 94a99599b6..0000000000 --- a/src/tm_mad/vmfs/context +++ /dev/null @@ -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 diff --git a/src/tm_mad/vmfs/context b/src/tm_mad/vmfs/context new file mode 120000 index 0000000000..921312e950 --- /dev/null +++ b/src/tm_mad/vmfs/context @@ -0,0 +1 @@ +../common/context \ No newline at end of file diff --git a/src/tm_mad/vmfs/delete b/src/tm_mad/vmfs/delete index e95367088e..f4fd08c53a 100755 --- a/src/tm_mad/vmfs/delete +++ b/src/tm_mad/vmfs/delete @@ -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 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 diff --git a/src/tm_mad/vmfs/ln b/src/tm_mad/vmfs/ln index 82971ccce3..26644f0a6b 100755 --- a/src/tm_mad/vmfs/ln +++ b/src/tm_mad/vmfs/ln @@ -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 < folder, not the disk. 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 < /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 diff --git a/src/tm_mad/vmfs/mvds b/src/tm_mad/vmfs/mvds index 4ee2185419..b6167bdf5b 100755 --- a/src/tm_mad/vmfs/mvds +++ b/src/tm_mad/vmfs/mvds @@ -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 < /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