1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

feature #1437: Finishing VMDS Datastore

This commit is contained in:
Tino Vazquez 2012-09-11 15:44:09 +02:00
parent 8d8247ab8e
commit b22ce33616
3 changed files with 51 additions and 27 deletions

View File

@ -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"

View File

@ -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

View File

@ -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