bug #1635: Move dir removal to a function in vmfs/delete action

(cherry picked from commit ba5aa8058a)
This commit is contained in:
Ruben S. Montero authored and Javi Fontan committed 2012-12-20 17:30:06 +01:00
1 parent 89dd74d78b
commit 494efbc7d2
1 file changed
+25 -15
+25 -15
View File
@@ -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 <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
@@ -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