diff --git a/src/datastore_mad/remotes/vmfs/clone b/src/datastore_mad/remotes/vmfs/clone new file mode 100755 index 0000000000..e7ea970e13 --- /dev/null +++ b/src/datastore_mad/remotes/vmfs/clone @@ -0,0 +1,83 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) # +# # +# 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 + 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 cp 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/UMASK \ + /DS_DRIVER_ACTION_DATA/DATASTORE/ID \ + /DS_DRIVER_ACTION_DATA/IMAGE/PATH) + +BASE_PATH="${XPATH_ELEMENTS[0]}" +UMASK="${XPATH_ELEMENTS[1]}" +DS_ID="${XPATH_ELEMENTS[2]}" +SRC="${XPATH_ELEMENTS[3]}" +SRC_FOLDER=`basename $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 + +set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK" + +DST=`generate_image_path` +DST_FOLDER=`basename $DST` + +# ------------ Copy the image to the repository ------------- + +log "Copying local image $SRC to the image repository" + +if [ "$SSH" == "yes" ]; then + ssh_exec_and_log "$VMKFSTOOLS $VI_PARAMS $SRC $DST" "Error copying $SRC to $DST" +else + exec_and_log 'vifs $VI_PARAMS --copy "[$DS_ID] $SRC_FOLDER" "[$DS_ID] $DST_FOLDER"' "Error copying $SRC to $DST" +fi + +echo "$DST" diff --git a/src/datastore_mad/remotes/vmfs/rm b/src/datastore_mad/remotes/vmfs/rm index 01bd6f2528..6a5b4cb279 100755 --- a/src/datastore_mad/remotes/vmfs/rm +++ b/src/datastore_mad/remotes/vmfs/rm @@ -68,7 +68,9 @@ fi log "Removing $SRC from the image repository" if [ "$SSH" == "yes" ]; then - ssh_exec_and_log $DST_HOST "rm -r /vmfs/volumes/$DS_NAME/$FOLDER_TO_ERASE" "Error deleting $SRC" + if [ -n $DS_NAME -a -n $FOLDER_TO_ERASE -a -d /vmfs/volumes/$DS_NAME/$FOLDER_TO_ERASE ]; then + ssh_exec_and_log $DST_HOST "rm -rf /vmfs/volumes/$DS_NAME/$FOLDER_TO_ERASE" "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] $FOLDER_TO_ERASE"|grep -v "Content Listing"|grep -v "\-\-\-\-\-\-\-\-"|egrep -v "^[[:space:]]*$"`