From b22ce33616ce0f866dc3381856a3c79f02e512de Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Tue, 11 Sep 2012 15:44:09 +0200 Subject: [PATCH] feature #1437: Finishing VMDS Datastore --- src/datastore_mad/remotes/vmfs/mkfs | 41 ++++++++++++++++++----------- src/datastore_mad/remotes/vmfs/rm | 35 +++++++++++++++++------- src/tm_mad/vmware/mkimage | 2 +- 3 files changed, 51 insertions(+), 27 deletions(-) diff --git a/src/datastore_mad/remotes/vmfs/mkfs b/src/datastore_mad/remotes/vmfs/mkfs index 5c0e0a0bd5..3f03dc58aa 100755 --- a/src/datastore_mad/remotes/vmfs/mkfs +++ b/src/datastore_mad/remotes/vmfs/mkfs @@ -52,6 +52,7 @@ done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/BASE_PATH \ /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/RESTRICTED_DIRS \ /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/SAFE_DIRS \ /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/UMASK \ + /DS_DRIVER_ACTION_DATA/DATASTORE/ID \ /DS_DRIVER_ACTION_DATA/IMAGE/FSTYPE \ /DS_DRIVER_ACTION_DATA/IMAGE/SIZE) @@ -59,14 +60,24 @@ BASE_PATH="${XPATH_ELEMENTS[0]}" RESTRICTED_DIRS="${XPATH_ELEMENTS[1]}" SAFE_DIRS="${XPATH_ELEMENTS[2]}" UMASK="${XPATH_ELEMENTS[3]}" -FSTYPE="${XPATH_ELEMENTS[4]}" -SIZE="${XPATH_ELEMENTS[5]}" +IMAGE_DS_ID="${XPATH_ELEMENTS[4]}" +FSTYPE="${XPATH_ELEMENTS[5]}" +SIZE="${XPATH_ELEMENTS[6]}" set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK" DST=`generate_image_path` +DST_DIR=`dirname $DST` +DST_FOLDER_NAME=`basename $DST` DST_HOST=`get_destination_host` +if [ "$SSH" != "yes" ]; then + USERNAME=`echo $(cat $VMWARERC |grep ":username:"|cut -d":" -f 3)` + PASSWORD=`echo $(cat $VMWARERC |grep ":password:"|cut -d":" -f 3)` + REMOTE_DS_ROUTE="$IMAGE_DS_ID]$DST_FOLDER_NAME" + VI_PARAMS="--server $DST_HOST --username $USERNAME --password $PASSWORD" +fi + # ------------ Image to save_as disk, no need to create a FS ------------ if [ "$FSTYPE" = "save_as" ]; then @@ -74,24 +85,22 @@ if [ "$FSTYPE" = "save_as" ]; then exit 0 fi -# ------------ Create the image to the repository ------------ +# ------------ Create the image within the image datastore ------------ -DISK=$DST/disk.vmdk -DISK_TMP=$DISK.tmp +log "Making filesystem of ${SIZE}M (with no format) at $DST" IMAGE_FORMAT=vmdk +VMWARE_DISK_TYPE=`echo $FSTYPE|cut -d'_' -f 2` -MKFS_CMD=`mkfs_command $DISK_TMP $FSTYPE` +if [ "$SSH" == "yes" ]; then + ssh_exec_and_log $DST_HOST "mkdir -p $DST" "Could not create disk directory $DST" + ssh_exec_and_log $DST_HOST "$VMKFSTOOLS -U $DST/disk.vmdk" + ssh_exec_and_log $DST_HOST "$VMKFSTOOLS -c ${SIZE}M -d ${VMWARE_DISK_TYPE} $DST/disk.vmdk" "Cannot create $DST/disk.vmdk on $DST_HOST" +else + exec_and_log 'vifs $VI_PARAMS --mkdir "[$IMAGE_DS_ID] $DST_FOLDER_NAME"' "Cannot create [$IMAGE_DS_ID] $DST_FOLDER_NAME on $DST_HOST" -exec_and_log "mkdir -p $DST" \ - "Could not create disk directory $DST" -exec_and_log "$DD if=/dev/zero of=$DISK_TMP bs=1 count=1 seek=${SIZE}M" \ - "Could not create temporary image $DISK_TMP" -exec_and_log "$MKFS_CMD" \ - "Unable to create filesystem $FSTYPE in $DISK_TMP" -exec_and_log "$QEMU_IMG convert -O $IMAGE_FORMAT $DISK_TMP $DISK" \ - "Unable to convert to $IMAGE_FORMAT in $DISK_TMP" -exec_and_log "rm -f $DISK_TMP" \ - "Unable to remove temporary disk $DISK_TMP" + exec_and_log "$VMKFSTOOLS $VI_PARAMS -U $DST_PATH/disk.vmdk" + exec_and_log "$VMKFSTOOLS $VI_PARAMS -c ${SIZE}M -d ${VMWARE_DISK_TYPE} $DST/disk.vmdk" "Cannot create $DST/disk.vmdk on $DST_HOST" +fi echo "$DST" diff --git a/src/datastore_mad/remotes/vmfs/rm b/src/datastore_mad/remotes/vmfs/rm index bb3ac1601f..01bd6f2528 100755 --- a/src/datastore_mad/remotes/vmfs/rm +++ b/src/datastore_mad/remotes/vmfs/rm @@ -24,14 +24,17 @@ if [ -z "${ONE_LOCATION}" ]; then LIB_LOCATION=/usr/lib/one + VMWARERC=/etc/one/vmwarerc else LIB_LOCATION=$ONE_LOCATION/lib + VMWARERC=$ONE_LOCATION/etc/vmwarerc fi . $LIB_LOCATION/sh/scripts_common.sh DRIVER_PATH=$(dirname $0) source ${DRIVER_PATH}/../libfs.sh +source $(dirname $0)/vmfsrc # -------- Get rm and datastore arguments from OpenNebula core ------------ @@ -45,22 +48,34 @@ unset i XPATH_ELEMENTS while IFS= read -r -d '' element; do XPATH_ELEMENTS[i++]="$element" done < <($XPATH /DS_DRIVER_ACTION_DATA/IMAGE/SOURCE \ - /DS_DRIVER_ACTION_DATA/DATASTORE/BASE_PATH) + /DS_DRIVER_ACTION_DATA/DATASTORE/ID \ + ) SRC="${XPATH_ELEMENTS[0]}" -BASE_PATH="${XPATH_ELEMENTS[1]}" +DS_NAME="${XPATH_ELEMENTS[1]}" -BASENAME_SRC=`basename "${SRC##$BASE_PATH}"` +DST_HOST=`get_destination_host` +FOLDER_TO_ERASE=`dirname SRC` + +if [ "$SSH" != "yes" ]; then + USERNAME=`echo $(cat $VMWARERC |grep ":username:"|cut -d":" -f 3)` + PASSWORD=`echo $(cat $VMWARERC |grep ":password:"|cut -d":" -f 3)` + VI_PARAMS="--server $DST_HOST --username $USERNAME --password $PASSWORD" +fi # ------------ Remove the image from the repository ------------ -if [ -d "$SRC" -a `dirname "$SRC"` = "$BASE_PATH" -a -n "$BASENAME_SRC" ] -then - log "Removing $SRC from the image repository" +log "Removing $SRC from the image repository" - exec_and_log "rm -r $SRC" \ - "Error deleting $SRC" +if [ "$SSH" == "yes" ]; then + ssh_exec_and_log $DST_HOST "rm -r /vmfs/volumes/$DS_NAME/$FOLDER_TO_ERASE" "Error deleting $SRC" else - log_error "Bad formed or unavailable Image source: ${SRC}" - exit 1 + # We have to erase the contents of the folder one by one + FILES_TO_ERASE=`vifs $VI_PARAMS --dir "[$DS_NAME] $FOLDER_TO_ERASE"|grep -v "Content Listing"|grep -v "\-\-\-\-\-\-\-\-"|egrep -v "^[[:space:]]*$"` + for file in $FILES_TO_ERASE; do + exec_and_log 'vifs $VI_PARAMS --rm "[$DS_NAME] $FOLDER_TO_ERASE/$file"' "Cannot delete $FOLDER_TO_ERASE/$file in $DST_HOST" + done + exec_and_log 'vifs $VI_PARAMS --rm "[$DS_NAME] $FOLDER_TO_ERASE"' "Cannot delete $FOLDER_TO_ERASE in $DST_HOST" fi + +exit 0 diff --git a/src/tm_mad/vmware/mkimage b/src/tm_mad/vmware/mkimage index 013705c205..8bf8e36582 100755 --- a/src/tm_mad/vmware/mkimage +++ b/src/tm_mad/vmware/mkimage @@ -82,7 +82,7 @@ else exec_and_log "VMWARE_DISK_TYPE=`echo $FSTYPE|cut -d'_' -f 2`" exec_and_log "$VMKFSTOOLS $VI_PARAMS -U $DST_PATH/disk.vmdk" - exec_and_log "$VMKFSTOOLS -c ${SIZE}M -d ${VMWARE_DISK_TYPE} $DST/disk.vmdk" + exec_and_log "$VMKFSTOOLS $VI_PARAMS -c ${SIZE}M -d ${VMWARE_DISK_TYPE} $DST/disk.vmdk" "Cannot create $DST/disk.vmdk on $DST_HOST" fi exit 0