mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
feature #1437: Add clone action to VMFS datastore
This commit is contained in:
parent
8981255a0d
commit
fa4634f4d6
83
src/datastore_mad/remotes/vmfs/clone
Executable file
83
src/datastore_mad/remotes/vmfs/clone
Executable file
@ -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"
|
@ -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:]]*$"`
|
||||
|
Loading…
x
Reference in New Issue
Block a user