diff --git a/src/tm_mad/vmfs/delete b/src/tm_mad/vmfs/delete index cb6e6b59f5..4df1989480 100755 --- a/src/tm_mad/vmfs/delete +++ b/src/tm_mad/vmfs/delete @@ -16,6 +16,26 @@ # 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/$file in $DST_HOST" + done + + exec_and_log "vifs $VI_PARAMS --force --rm [$DSID]$VMID/$dir" \ + "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 @@ -40,6 +60,8 @@ fi . $TMCOMMON + + DST_PATH=`arg_path $DST` DST_HOST=`arg_host $DST` @@ -66,24 +88,12 @@ if [ "$USE_SSH" == "yes" ]; then ssh_exec_and_log $DST_HOST "rm -rf $DST_PATH" "Error deleting $DST_PATH" else if [ `is_disk $DST_PATH` -eq 1 ]; then - dir=$(basename $DST_PATH) - FILES_TO_ERASE=`vifs $VI_PARAMS --dir [$DSID]$VMID/$dir|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/$file" \ - "Cannot delete [$DSID]$VMID/$dir/$file in $DST_HOST" - done - exec_and_log "vifs $VI_PARAMS --force --rm [$DSID]$VMID/$dir" \ - "Cannot delete [$DSID]$VMID in $DST_HOST" + vifs_rmdir $(basename $DST_PATH) 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 - FILES_TO_ERASE=`vifs $VI_PARAMS --dir [$DSID]$VMID/$dir|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/$file" \ - "Cannot delete [$DSID]$VMID/$dir/$file in $DST_HOST" - done - exec_and_log "vifs $VI_PARAMS --force --rm [$DSID]$VMID/$dir" \ - "Cannot delete [$DSID]$VMID in $DST_HOST" + vifs_rmdir $dir done fi fi