Feature #2097: Get rid of VMware DS

Get rid of VMware specific code in TM shared
This commit is contained in:
Tino Vazquez committed 2013-06-19 14:44:26 +02:00
1 parent a93f7d83aa
commit d62afe545f
13 files changed
+18 -365

No files matched your search

-1
View File
@@ -1 +0,0 @@
../common/clone
-112
View File
@@ -1,112 +0,0 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
###############################################################################
# This script is used to copy a VM image (SRC) to the image repository as DST
# Several SRC types are supported
###############################################################################
# -------- Set up the environment to source common tools & conf ------------
if [ -z "${ONE_LOCATION}" ]; then
LIB_LOCATION=/usr/lib/one
else
LIB_LOCATION=$ONE_LOCATION/lib
fi
. $LIB_LOCATION/sh/scripts_common.sh
DRIVER_PATH=$(dirname $0)
source ${DRIVER_PATH}/../libfs.sh
# -------- Get cp and datastore arguments from OpenNebula core ------------
DRV_ACTION=$1
ID=$2
UTILS_PATH="${DRIVER_PATH}/.."
XPATH="$UTILS_PATH/xpath.rb -b $DRV_ACTION"
unset i XPATH_ELEMENTS
while IFS= read -r -d '' element; do
XPATH_ELEMENTS[i++]="$element"
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/IMAGE/PATH \
/DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/MD5 \
/DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/SHA1 \
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/NO_DECOMPRESS \
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/LIMIT_TRANSFER_BW)
BASE_PATH="${XPATH_ELEMENTS[0]}"
RESTRICTED_DIRS="${XPATH_ELEMENTS[1]}"
SAFE_DIRS="${XPATH_ELEMENTS[2]}"
SRC="${XPATH_ELEMENTS[3]}"
MD5="${XPATH_ELEMENTS[4]}"
SHA1="${XPATH_ELEMENTS[5]}"
NO_DECOMPRESS="${XPATH_ELEMENTS[6]}"
LIMIT_TRANSFER_BW="${XPATH_ELEMENTS[7]}"
mkdir -p "$BASE_PATH"
set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS"
DST=`generate_image_path`
DOWNLOADER_ARGS=`set_downloader_args "$MD5" "$SHA1" "$NO_DECOMPRESS" "$LIMIT_TRANSFER_BW" "$SRC" "$DST"`
COPY_COMMAND="$UTILS_PATH/downloader.sh $DOWNLOADER_ARGS"
# ------------ Copy the image to the repository -------------
case $SRC in
http://*|https://* )
log "Downloading $SRC to the image repository"
exec_and_log "$COPY_COMMAND" "Error downloading $SRC"
;;
*)
if [ `check_restricted $SRC` -eq 1 ]; then
log_error "Not allowed to copy images from $RESTRICTED_DIRS"
error_message "Not allowed to copy image file $SRC"
exit -1
fi
log "Copying local disk folder $SRC to the image repository"
if [ -d "$SRC" ]; then
exec_and_log "cp -rf $SRC $DST" "Error copying $SRC to $DST"
else
exec_and_log "$COPY_COMMAND" "Error copying $SRC to $DST"
fi
;;
esac
if [ -d "$DST" -a ! -f "$DST/disk.vmdk" ]; then
BASE_DISK_FILE=`ls $DST | grep '\.vmdk$' | grep -v '\-\(flat\|delta\|s[0-9]*\)\.vmdk$'`
exec_and_log "mv -f $DST/$BASE_DISK_FILE $DST/disk.vmdk" \
"Error renaming disk file $BASE_DISK_FILE to disk.vmdk"
fi
# ---------------- Get the size of the image ------------
echo "$DST"
-88
View File
@@ -1,88 +0,0 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
###############################################################################
# This script is used to create a VM image (SRC) of size (SIZE) and formatted
# as (FS)
###############################################################################
# -------- Set up the environment to source common tools & conf ------------
if [ -z "${ONE_LOCATION}" ]; then
LIB_LOCATION=/usr/lib/one
else
LIB_LOCATION=$ONE_LOCATION/lib
fi
. $LIB_LOCATION/sh/scripts_common.sh
DRIVER_PATH=$(dirname $0)
source ${DRIVER_PATH}/../libfs.sh
# -------- Get mkfs and datastore arguments from OpenNebula core ------------
DRV_ACTION=$1
ID=$2
XPATH="${DRIVER_PATH}/../xpath.rb -b $DRV_ACTION"
unset i XPATH_ELEMENTS
while IFS= read -r -d '' element; do
XPATH_ELEMENTS[i++]="$element"
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/IMAGE/FSTYPE \
/DS_DRIVER_ACTION_DATA/IMAGE/SIZE)
BASE_PATH="${XPATH_ELEMENTS[0]}"
RESTRICTED_DIRS="${XPATH_ELEMENTS[1]}"
SAFE_DIRS="${XPATH_ELEMENTS[2]}"
FSTYPE="${XPATH_ELEMENTS[3]}"
SIZE="${XPATH_ELEMENTS[4]}"
mkdir -p "$BASE_PATH"
set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS"
DST=`generate_image_path`
# ------------ Image to save_as disk, no need to create a FS ------------
if [ "$FSTYPE" = "save_as" ]; then
echo "$DST"
exit 0
fi
# ------------ Create the image to the repository ------------
DISK=$DST/disk.vmdk
DISK_TMP=$DISK.tmp
IMAGE_FORMAT=vmdk
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 "$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"
echo "$DST"
-75
View File
@@ -1,75 +0,0 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
###############################################################################
# This script is used to remove a VM image (SRC) from the image repository
###############################################################################
# ------------ Set up the environment to source common tools ------------
if [ -z "${ONE_LOCATION}" ]; then
LIB_LOCATION=/usr/lib/one
else
LIB_LOCATION=$ONE_LOCATION/lib
fi
. $LIB_LOCATION/sh/scripts_common.sh
DRIVER_PATH=$(dirname $0)
source ${DRIVER_PATH}/../libfs.sh
# -------- Get rm and datastore arguments from OpenNebula core ------------
DRV_ACTION=$1
ID=$2
XPATH="${DRIVER_PATH}/../xpath.rb -b $DRV_ACTION"
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)
SRC="${XPATH_ELEMENTS[0]}"
BASE_PATH="${XPATH_ELEMENTS[1]}"
BASENAME_SRC=`basename "${SRC##$BASE_PATH}"`
# ------------ Remove the image from the repository ------------
if [ -d "$SRC" -a `dirname "$SRC"` = "$BASE_PATH" -a -n "$BASENAME_SRC" ]
then
log "Removing disk $SRC from the image repository"
exec_and_log "rm -r $SRC" \
"Error deleting $SRC"
else
if [ -f "$SRC" -a `dirname "$SRC"` = "$BASE_PATH" -a -n "$BASENAME_SRC" ]
then
log "Removing CDROM $SRC from the image repository"
exec_and_log "rm $SRC" \
"Error deleting $SRC"
else
log_error "Bad formed or unavailable Image source: ${SRC}"
exit 1
fi
fi
-1
View File
@@ -1 +0,0 @@
../common/stat
+4 -3
View File
@@ -52,6 +52,10 @@ DST_PATH=`arg_path $DST`
DST_HOST=`arg_host $DST`
DST_DIR=`dirname $DST_PATH`
#-------------------------------------------------------------------------------
# Create DST path
#-------------------------------------------------------------------------------
ssh_make_path $DST_HOST $DST_DIR
#-------------------------------------------------------------------------------
@@ -96,9 +100,6 @@ exec_and_set_error "$MKISOFS -o $ISO_FILE -J -R $ISO_DIR" \
exec_and_set_error "$SCP $ISO_FILE $DST" "Error copying context ISO to $DST"
[ -n "$ERROR" ] && exit_error
# Creates symbolic link to add a .iso suffix, needed for VMware CDROMs
ssh_exec_and_log $DST_HOST "$LN -s $DST_PATH $DST_PATH.iso" "Error creating ISO symbolic link"
rm -rf $ISO_DIR > /dev/null 2>&1
exit 0
+1 -1
View File
@@ -43,6 +43,6 @@ DST_PATH=`arg_path $DST`
DST_HOST=`arg_host $DST`
log "Deleting $DST_PATH"
ssh_exec_and_log $DST_HOST "rm -rf $DST_PATH" "Error deleting $DST_PATH"
ssh_exec_and_log $DST_HOST "rm -f $DST_PATH" "Error deleting $DST_PATH"
exit 0
+2 -10
View File
@@ -49,17 +49,9 @@ DST_DIR=`dirname $DST_PATH`
#-------------------------------------------------------------------------------
# Make the new image (file-based)
#-------------------------------------------------------------------------------
case "$FSTYPE" in
"vmdk_"*)
ssh_make_path $DST_HOST $DST_PATH
CREATE_IMAGE=""
;;
*)
ssh_make_path $DST_HOST $DST_DIR
CREATE_IMAGE="$DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M"
;;
esac
ssh_make_path $DST_HOST $DST_DIR
CREATE_IMAGE="$DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M"
MKFS_CMD=`mkfs_command $DST_PATH $FSTYPE $SIZE`
MKSCRIPT=$(cat <<EOF
+5 -14
View File
@@ -52,14 +52,12 @@ SRC_DS_PATH="$(dirname $(dirname $SRC_ARG_PATH))"
SRC_PATH="${DST_DS_PATH}${SRC_ARG_PATH##$SRC_DS_PATH}"
#-------------------------------------------------------------------------------
# Create DST path
#-------------------------------------------------------------------------------
ssh_make_path $DST_HOST $DST_DIR
#-------------------------------------------------------------------------------
# Get image information
#-------------------------------------------------------------------------------
DISK_TYPE=$(disk_type)
#-------------------------------------------------------------------------------
# Clone (cp) SRC into DST
#-------------------------------------------------------------------------------
@@ -75,16 +73,9 @@ http://*)
*)
log "Cloning $SRC_PATH in $DST"
ssh_exec_and_log $DST_HOST \
"cd $DST_DIR; cp -r $SRC_PATH $DST_PATH" \
"cd $DST_DIR; cp $SRC_PATH $DST_PATH" \
"Error copying $SRC to $DST"
;;
esac
# Add a symlink for CDROM images
if [ "$DISK_TYPE" = "CDROM" ]; then
ssh_exec_and_log $DST_HOST \
"ln -s ${DST_PATH} ${DST_PATH}.iso" \
"Error linking ${DST_PATH} to ${DST_PATH}.iso"
fi
exit 0
-2
View File
@@ -62,8 +62,6 @@ DST_READLN=\$($READLINK -f $DST_PATH)
if [ -d $SRC_PATH ] ; then
if [ \( -L $SRC_PATH \) -a \( "\$SRC_READLN" = "\$DST_READLN" \) ] ; then
echo "Not moving files to image repo, they are the same"
elif [ -f $SRC_PATH/.is_persistent ]; then
echo "Not moving files to image repo, they are the same"
else
cp -rf $SRC_PATH/* $DST_PATH
fi
+6 -37
View File
@@ -54,48 +54,17 @@ SRC_DS_PATH="$(dirname $(dirname $SRC_ARG_PATH))"
SRC_PATH="${DST_DS_PATH}${SRC_ARG_PATH##$SRC_DS_PATH}"
#-------------------------------------------------------------------------------
# Get image information
# Create DST path
#-------------------------------------------------------------------------------
DISK_TYPE=$(disk_type)
ssh_make_path $DST_HOST $DST_DIR
#-------------------------------------------------------------------------------
# Link (ln) SRC into DST
#-------------------------------------------------------------------------------
log "Linking $SRC_PATH in $DST"
# Is it a file or a folder (VMware)?
if [ -d `arg_path $SRC` ]; then
ssh_make_path $DST_HOST $DST_PATH
log "Link all files in $SRC_PATH to $DST_PATH"
LINK_SCRIPT=$(cat <<EOF
for file in \$(find $SRC_PATH -type f); do
(cd $DST_PATH ; ln -sf \$file)
done
touch $DST_PATH/.is_persistent
EOF
)
ssh_exec_and_log $DST_HOST "$LINK_SCRIPT" "Could not link dir files from source DS to system DS"
else
ssh_make_path $DST_HOST $DST_DIR
# Just link a file
log "Linking $SRC_PATH in $DST"
ssh_exec_and_log $DST_HOST \
"cd $DST_DIR; rm $DST_PATH ; ln -s $SRC_PATH $DST_PATH" \
"Error linking $SRC to $DST"
# Add a symlink for CDROM images
if [ "$DISK_TYPE" = "CDROM" ]; then
ssh_exec_and_log $DST_HOST \
"ln -s ${DST_PATH} ${DST_PATH}.iso" \
"Error linking ${DST_PATH} to ${DST_PATH}.iso"
fi
fi
ssh_exec_and_log $DST_HOST \
"cd $DST_DIR; rm $DST_PATH ; ln -s $SRC_PATH $DST_PATH" \
"Error linking $SRC to $DST"
exit 0
-2
View File
@@ -62,8 +62,6 @@ DST_READLN=\$($READLINK -f $DST_PATH)
if [ -d $SRC_PATH ] ; then
if [ \( -L $SRC_PATH \) -a \( "\$SRC_READLN" = "\$DST_READLN" \) ] ; then
echo "Not moving files to image repo, they are the same"
elif [ -f $SRC_PATH/.is_persistent ]; then
echo "Not moving files to image repo, they are the same"
else
mv -f $SRC_PATH/* $DST_PATH
fi
-19
View File
@@ -76,22 +76,3 @@ function make_relative {
echo $dots${src#$common/}
}
#Return DISK_TYPE
function disk_type
{
# Let's check if it is a CDROM
DISK_ID=$(echo "$DST_PATH" | $AWK -F. '{print $NF}')
XPATH="${ONE_LOCAL_VAR}/remotes/datastore/xpath.rb --stdin"
unset i XPATH_ELEMENTS
while IFS= read -r -d '' element; do
XPATH_ELEMENTS[i++]="$element"
done < <(onevm show -x $VMID| $XPATH \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/TYPE )
DISK_TYPE="${XPATH_ELEMENTS[0]}"
echo $DISK_TYPE
}