mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
feature #1441: Add stub for VMFS datastore
This commit is contained in:
parent
9c4027e695
commit
e63a0893ac
@ -137,3 +137,21 @@ function check_restricted {
|
||||
|
||||
echo 0
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Gets the ESX host to be used as bridge to register a VMware disk
|
||||
# Implements a round robin for the bridges
|
||||
# @param $1 - Path to the list of ESX hosts to be used as bridges
|
||||
# @return host to be used as bridge
|
||||
#-------------------------------------------------------------------------------
|
||||
function get_destination_host {
|
||||
CONF_FILE_PATH="$1/bridgelist"
|
||||
|
||||
BRIDGE_HOST=`head -1 $CONF_FILE_PATH`
|
||||
|
||||
sed -i -e "1d" $CONF_FILE_PATH
|
||||
|
||||
cat $BRIDGE_HOST >> $CONF_FILE_PATH
|
||||
|
||||
echo $BRIDGE_HOST
|
||||
}
|
||||
|
3
src/datastore_mad/remotes/vmfs/bridgelist
Normal file
3
src/datastore_mad/remotes/vmfs/bridgelist
Normal file
@ -0,0 +1,3 @@
|
||||
bridge-esx-1.mydomain
|
||||
bridge-esx-2.mydomain
|
||||
bridge-esx-3.mydomain
|
150
src/datastore_mad/remotes/vmfs/cp
Executable file
150
src/datastore_mad/remotes/vmfs/cp
Executable file
@ -0,0 +1,150 @@
|
||||
#!/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
|
||||
|
||||
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/DATASTORE/TEMPLATE/UMASK \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/PATH \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/MD5 \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/SHA1)
|
||||
|
||||
BASE_PATH="${XPATH_ELEMENTS[0]}"
|
||||
RESTRICTED_DIRS="${XPATH_ELEMENTS[1]}"
|
||||
SAFE_DIRS="${XPATH_ELEMENTS[2]}"
|
||||
UMASK="${XPATH_ELEMENTS[3]}"
|
||||
SRC="${XPATH_ELEMENTS[4]}"
|
||||
MD5="${XPATH_ELEMENTS[5]}"
|
||||
SHA1="${XPATH_ELEMENTS[6]}"
|
||||
|
||||
# Set up the datastore
|
||||
set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK"
|
||||
|
||||
DST=`generate_image_path`
|
||||
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)`
|
||||
VI_PARAMS="--server $DST_HOST --username $USERNAME --password $PASSWORD"
|
||||
fi
|
||||
|
||||
# Create DST in DST_HOST
|
||||
if [ "$SSH" == "yes" ]; then
|
||||
ssh_make_path $DST_HOST $DST
|
||||
else
|
||||
exec_and_log 'vifs $VI_PARAMS --mkdir "$DST"' "Cannot create $DST in $DST_HOST"
|
||||
fi
|
||||
|
||||
# Prepare for a possible download in the front-end
|
||||
if [ ! -d $TMP_DIR ]; then
|
||||
mkdir -p $TMP_DIR
|
||||
fi
|
||||
|
||||
HASHES=""
|
||||
|
||||
if [ -n "$MD5" ]; then
|
||||
HASHES="$HASHES --md5 $MD5"
|
||||
fi
|
||||
|
||||
if [ -n "$SHA1" ]; then
|
||||
HASHES="$HASHES --sha1 $SHA1"
|
||||
fi
|
||||
|
||||
COPY_COMMAND="$UTILS_PATH/downloader.sh $HASHES $SRC $TMP_DIR/$IMAGE_HASH"
|
||||
|
||||
# ------------ 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 "$COPY_COMMAND" "Error copying $SRC to $TMP_DIR/$IMAGE_HASH"
|
||||
fi
|
||||
|
||||
SRC="$TMP_DIR/$IMAGE_HASH"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Rename the disk filename to disk.vmdk (warning: it does so in SRC)
|
||||
if [ ! -f $SRC/disk.vmdk ]; then
|
||||
BASE_DISK_FILE=`ls $SRC | 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
|
||||
|
||||
# Make the final hop, front-end -> VMFS Datastore
|
||||
if [ "$SSH" == "yes" ]; then
|
||||
exec_and_log "$SCP -r $SRC $DST" "Error copying $SRC to $DST through SCP"
|
||||
else
|
||||
cd $SRC
|
||||
for file in $(find . -type f); do
|
||||
FNAME=$(basename $file)
|
||||
exec_and_log 'vifs $VI_PARAMS -p $file $DST/$FNAME' "Cannot upload $file to $DST/$FNAME on $DST_HOST"
|
||||
done
|
||||
fi
|
||||
|
||||
echo "$DST"
|
94
src/datastore_mad/remotes/vmfs/mkfs
Executable file
94
src/datastore_mad/remotes/vmfs/mkfs
Executable file
@ -0,0 +1,94 @@
|
||||
#!/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 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/DATASTORE/TEMPLATE/UMASK \
|
||||
/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]}"
|
||||
UMASK="${XPATH_ELEMENTS[3]}"
|
||||
FSTYPE="${XPATH_ELEMENTS[4]}"
|
||||
SIZE="${XPATH_ELEMENTS[5]}"
|
||||
|
||||
mkdir -p "$BASE_PATH"
|
||||
set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK"
|
||||
|
||||
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
|
||||
|
||||
MKFS_CMD=`mkfs_command $DISK_TMP $FSTYPE`
|
||||
|
||||
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"
|
||||
|
||||
echo "$DST"
|
66
src/datastore_mad/remotes/vmfs/rm
Executable file
66
src/datastore_mad/remotes/vmfs/rm
Executable file
@ -0,0 +1,66 @@
|
||||
#!/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 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 $SRC from the image repository"
|
||||
|
||||
exec_and_log "rm -r $SRC" \
|
||||
"Error deleting $SRC"
|
||||
else
|
||||
log_error "Bad formed or unavailable Image source: ${SRC}"
|
||||
exit 1
|
||||
fi
|
18
src/datastore_mad/remotes/vmfs/vmfsrc
Normal file
18
src/datastore_mad/remotes/vmfs/vmfsrc
Normal file
@ -0,0 +1,18 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
TMP_DIR=/var/lib/one/tmp
|
||||
SSH=no
|
Loading…
x
Reference in New Issue
Block a user