From 0b427dde457999f3783e47b43230cf504846bfd9 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Fri, 28 Sep 2012 14:45:10 +0200 Subject: [PATCH] feature #1437: Homogenoeus naming and function encapsulation for VMFS ds drivers --- src/datastore_mad/remotes/vmfs/clone | 17 ++++------- src/datastore_mad/remotes/vmfs/cp | 31 +++++++------------- src/datastore_mad/remotes/vmfs/mkfs | 43 ++++++++++++---------------- src/datastore_mad/remotes/vmfs/rm | 24 ++++++---------- src/mad/sh/scripts_common.sh | 22 ++++++++++++++ 5 files changed, 64 insertions(+), 73 deletions(-) diff --git a/src/datastore_mad/remotes/vmfs/clone b/src/datastore_mad/remotes/vmfs/clone index 6036573148..bed2c43de7 100755 --- a/src/datastore_mad/remotes/vmfs/clone +++ b/src/datastore_mad/remotes/vmfs/clone @@ -65,22 +65,15 @@ SRC="${XPATH_ELEMENTS[5]}" IMAGE_ID="${XPATH_ELEMENTS[6]}" SRC_FOLDER=`basename $SRC` - -set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK" - DST=`generate_image_path` DST_FOLDER=`basename $DST` DST_HOST=`get_destination_host $IMAGE_ID` -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 +# ------------ Set up datastore ------------- + +set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK" + +vmfs_set_up # ------------ Copy the image to the repository ------------- diff --git a/src/datastore_mad/remotes/vmfs/cp b/src/datastore_mad/remotes/vmfs/cp index 2984bc4cac..43d211e004 100755 --- a/src/datastore_mad/remotes/vmfs/cp +++ b/src/datastore_mad/remotes/vmfs/cp @@ -76,34 +76,23 @@ MD5="${XPATH_ELEMENTS[9]}" SHA1="${XPATH_ELEMENTS[10]}" IMAGE_ID="${XPATH_ELEMENTS[11]}" -# Set up the datastore -set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK" - FE_DST=`generate_image_path` DST_FOLDER=`basename $FE_DST` DST="/vmfs/volumes/$DS_ID/$DST_FOLDER" DST_HOST=`get_destination_host $IMAGE_ID` -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 -# Create DST in DST_HOST -if [ "$USE_SSH" == "yes" ]; then - ssh_make_path $DST_HOST $DST -else - exec_and_log "vifs $VI_PARAMS --mkdir [$DS_ID]$DST_FOLDER" \ - "Cannot create $DST in $DST_HOST" -fi +# ------------ Set up datastore ------------- -# Prepare for a possible download in the front-end -if [ ! -d $TMP_DIR ]; then +set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK" + +vmfs_set_up + +vmfs_create_remote_path + +# ------------ Prepare for a possible download in the front-end ------------- + +if [ ! -d $TMP_DIR ]; then mkdir -p $TMP_DIR fi diff --git a/src/datastore_mad/remotes/vmfs/mkfs b/src/datastore_mad/remotes/vmfs/mkfs index 31ec0a922e..d4a633d367 100755 --- a/src/datastore_mad/remotes/vmfs/mkfs +++ b/src/datastore_mad/remotes/vmfs/mkfs @@ -63,27 +63,20 @@ RESTRICTED_DIRS="${XPATH_ELEMENTS[1]}" SAFE_DIRS="${XPATH_ELEMENTS[2]}" UMASK="${XPATH_ELEMENTS[3]}" USE_SSH="${XPATH_ELEMENTS[4]:-$DS_USE_SSH}" -IMAGE_DS_ID="${XPATH_ELEMENTS[5]}" +DS_ID="${XPATH_ELEMENTS[5]}" FSTYPE="${XPATH_ELEMENTS[6]}" SIZE="${XPATH_ELEMENTS[7]}" IMAGE_ID="${XPATH_ELEMENTS[8]}" - -set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK" - DST=`generate_image_path` DST_DIR=`dirname $DST` DST_FOLDER=`basename $DST` DST_HOST=`get_destination_host $IMAGE_ID` -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 +# ------------ Set up datastore ------------- + +set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK" + +vmfs_set_up # ------------ Image to save_as disk, no need to create a FS ------------ @@ -94,23 +87,23 @@ fi # ------------ Create the image within the image datastore ------------ -log "Making filesystem of ${SIZE}M (with no format) at [$IMAGE_DS_ID]$DST_FOLDER on $DST_HOST" +log "Making filesystem of ${SIZE}M (with no format) at [$DS_ID]$DST_FOLDER on $DST_HOST" IMAGE_FORMAT=vmdk VMWARE_DISK_TYPE=`echo $FSTYPE|cut -d'_' -f 2` if [ "$USE_SSH" == "yes" ]; then - ssh_exec_and_log $DST_HOST "mkdir -p /vmfs/volumes/$IMAGE_DS_ID/$DST_FOLDER" \ - "Could not create disk directory /vmfs/volumes/$IMAGE_DS_ID/$DST_FOLDER on $DST_HOST" - $SSH $DST_HOST $VMKFSTOOLS -U [$IMAGE_DS_ID]$DST_FOLDER/disk.vmdk - ssh_exec_and_log $DST_HOST "$VMKFSTOOLS -c ${SIZE}M -d ${VMWARE_DISK_TYPE} /vmfs/volumes/$IMAGE_DS_ID/$DST_FOLDER/disk.vmdk" \ - "Cannot create [$IMAGE_DS_ID] $DST_FOLDER/disk.vmdk on $DST_HOST" + ssh_exec_and_log $DST_HOST "mkdir -p /vmfs/volumes/$DS_ID/$DST_FOLDER" \ + "Could not create disk directory /vmfs/volumes/$DS_ID/$DST_FOLDER on $DST_HOST" + $SSH $DST_HOST $VMKFSTOOLS -U [$DS_ID]$DST_FOLDER/disk.vmdk + ssh_exec_and_log $DST_HOST "$VMKFSTOOLS -c ${SIZE}M -d ${VMWARE_DISK_TYPE} /vmfs/volumes/$DS_ID/$DST_FOLDER/disk.vmdk" \ + "Cannot create [$DS_ID] $DST_FOLDER/disk.vmdk on $DST_HOST" else - $VMKFSTOOLS $VI_PARAMS -U [$IMAGE_DS_ID]$DST_FOLDER/disk.vmdk &> /dev/null - exec_and_log "vifs $VI_PARAMS --mkdir [$IMAGE_DS_ID]$DST_FOLDER" \ - "Cannot create [$IMAGE_DS_ID] $DST_FOLDER on $DST_HOST" - exec_and_log "$VMKFSTOOLS $VI_PARAMS -c ${SIZE}M -d ${VMWARE_DISK_TYPE} [$IMAGE_DS_ID]$DST_FOLDER/disk.vmdk" \ - "Cannot create $IMAGE_DS_ID]$DST_FOLDER/disk.vmdk on $DST_HOST" + $VMKFSTOOLS $VI_PARAMS -U [$DS_ID]$DST_FOLDER/disk.vmdk &> /dev/null + exec_and_log "vifs $VI_PARAMS --mkdir [$IDS_ID]$DST_FOLDER" \ + "Cannot create [$DS_ID] $DST_FOLDER on $DST_HOST" + exec_and_log "$VMKFSTOOLS $VI_PARAMS -c ${SIZE}M -d ${VMWARE_DISK_TYPE} [$DS_ID]$DST_FOLDER/disk.vmdk" \ + "Cannot create $DS_ID]$DST_FOLDER/disk.vmdk on $DST_HOST" fi -echo "/vmfs/volumes/$IMAGE_DS_ID/$DST_FOLDER" +echo "/vmfs/volumes/$DS_ID/$DST_FOLDER" diff --git a/src/datastore_mad/remotes/vmfs/rm b/src/datastore_mad/remotes/vmfs/rm index 9f38fc8286..a5a6b1eed2 100755 --- a/src/datastore_mad/remotes/vmfs/rm +++ b/src/datastore_mad/remotes/vmfs/rm @@ -53,40 +53,34 @@ done < <($XPATH /DS_DRIVER_ACTION_DATA/IMAGE/SOURCE \ /DS_DRIVER_ACTION_DATA/IMAGE/ID) SRC="${XPATH_ELEMENTS[0]}" -DS_NAME="${XPATH_ELEMENTS[1]}" +DS_ID="${XPATH_ELEMENTS[1]}" USE_SSH="${XPATH_ELEMENTS[4]:-$DS_USE_SSH}" IMAGE_ID="${XPATH_ELEMENTS[2]}" DST_HOST=`get_destination_host $IMAGE_ID` DST_FOLDER=`basename $SRC` -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 +# ------------ Set up datastore ------------ + +vmfs_set_up # ------------ Remove the image from the repository ------------ log "Removing $SRC from the image repository" if [ "$USE_SSH" == "yes" ]; then - if [ -n $DS_NAME -a -n $DST_FOLDER ]; then - ssh_exec_and_log $DST_HOST "rm -rf /vmfs/volumes/$DS_NAME/$DST_FOLDER" \ + if [ -n $DS_ID -a -n $DST_FOLDER ]; then + ssh_exec_and_log $DST_HOST "rm -rf /vmfs/volumes/$DS_ID/$DST_FOLDER" \ "Error deleting $SRC" fi else # We have to erase the contents of the folder one by one - FILES_TO_ERASE=`vifs $VI_PARAMS --dir [$DS_NAME]$DST_FOLDER|grep -v "Content Listing"|grep -v "\-\-\-\-\-\-\-\-"|egrep -v "^[[:space:]]*$"` + FILES_TO_ERASE=`vifs $VI_PARAMS --dir [$DS_ID]$DST_FOLDER|grep -v "Content Listing"|grep -v "\-\-\-\-\-\-\-\-"|egrep -v "^[[:space:]]*$"` for file in $FILES_TO_ERASE; do - exec_and_log "vifs $VI_PARAMS --force --rm [$DS_NAME]$DST_FOLDER/$file" \ + exec_and_log "vifs $VI_PARAMS --force --rm [$DS_ID]$DST_FOLDER/$file" \ "Cannot delete $DST_FOLDER/$file in $DST_HOST" done - exec_and_log "vifs $VI_PARAMS --force --rm [$DS_NAME]$DST_FOLDER" \ + exec_and_log "vifs $VI_PARAMS --force --rm [$DS_ID]$DST_FOLDER" \ "Cannot delete $DST_FOLDER in $DST_HOST" fi diff --git a/src/mad/sh/scripts_common.sh b/src/mad/sh/scripts_common.sh index f0f346a82b..d7a6e5aeb5 100644 --- a/src/mad/sh/scripts_common.sh +++ b/src/mad/sh/scripts_common.sh @@ -409,3 +409,25 @@ function iqn_get_host { VG_NAME=$(iqn_get_vg_name "$IQN") echo ${TARGET%%.$VG_NAME.$LV_NAME} } + +function vmfs_crate_remote_path { + # Create DST in DST_HOST + if [ "$USE_SSH" == "yes" ]; then + ssh_make_path $DST_HOST $DST + else + exec_and_log "vifs $VI_PARAMS --mkdir [$DS_ID]$DST_FOLDER" \ + "Cannot create $DST 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 +}