From a64f23372a0b79d81e35862e533e71caf2f9c044 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Wed, 13 Feb 2013 17:55:38 +0100 Subject: [PATCH] Feature #1068: Add the datastore drivers for Ceph --- src/datastore_mad/remotes/ceph/ceph.conf | 27 +++++ src/datastore_mad/remotes/ceph/clone | 71 +++++++++++++ src/datastore_mad/remotes/ceph/cp | 130 +++++++++++++++++++++++ src/datastore_mad/remotes/ceph/mkfs | 108 +++++++++++++++++++ src/datastore_mad/remotes/ceph/rm | 60 +++++++++++ src/datastore_mad/remotes/ceph/stat | 1 + src/datastore_mad/remotes/libfs.sh | 15 ++- src/mad/sh/scripts_common.sh | 2 + 8 files changed, 411 insertions(+), 3 deletions(-) create mode 100644 src/datastore_mad/remotes/ceph/ceph.conf create mode 100755 src/datastore_mad/remotes/ceph/clone create mode 100755 src/datastore_mad/remotes/ceph/cp create mode 100755 src/datastore_mad/remotes/ceph/mkfs create mode 100755 src/datastore_mad/remotes/ceph/rm create mode 120000 src/datastore_mad/remotes/ceph/stat diff --git a/src/datastore_mad/remotes/ceph/ceph.conf b/src/datastore_mad/remotes/ceph/ceph.conf new file mode 100644 index 0000000000..4345385e7c --- /dev/null +++ b/src/datastore_mad/remotes/ceph/ceph.conf @@ -0,0 +1,27 @@ +# -------------------------------------------------------------------------- # +# 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. # +#--------------------------------------------------------------------------- # + +# Default POOL_NAME +POOL_NAME=one + +# Default Ceph server host. Storage operations will be performed in this host. +HOST=localhost + +# Staging directory +# A directory in the Ceph server host where image will be transferred to +# temporarily during the create/mkfs processes. This directoy MUST exist, +# have enough space and be writeable by 'oneadmin' +STAGING_DIR=/tmp diff --git a/src/datastore_mad/remotes/ceph/clone b/src/datastore_mad/remotes/ceph/clone new file mode 100755 index 0000000000..54c49b4cf2 --- /dev/null +++ b/src/datastore_mad/remotes/ceph/clone @@ -0,0 +1,71 @@ +#!/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 +source ${DRIVER_PATH}/ceph.conf + +# -------- 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/TEMPLATE/HOST \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/POOL_NAME \ + /DS_DRIVER_ACTION_DATA/IMAGE/PATH \ + /DS_DRIVER_ACTION_DATA/IMAGE/SIZE) + +unset i + +BASE_PATH="${XPATH_ELEMENTS[i++]}" +UMASK="${XPATH_ELEMENTS[i++]}" +DST_HOST="${XPATH_ELEMENTS[i++]:-$HOST}" +POOL_NAME="${XPATH_ELEMENTS[i++]:-$POOL_NAME}" +SRC="${XPATH_ELEMENTS[i++]}" +SIZE="${XPATH_ELEMENTS[i++]}" + +SAFE_DIRS="" + +IMAGE_NAME="one-${ID}" +RBD_DST="${POOL_NAME}/${IMAGE_NAME}" + +ssh_exec_and_log "$DST_HOST" "$RBD copy $SRC $RBD_DST" \ + "Error cloning $SRC to $RBD_DST in $DST_HOST" + +echo "$RBD_DST" diff --git a/src/datastore_mad/remotes/ceph/cp b/src/datastore_mad/remotes/ceph/cp new file mode 100755 index 0000000000..e72268c6a7 --- /dev/null +++ b/src/datastore_mad/remotes/ceph/cp @@ -0,0 +1,130 @@ +#!/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 +source ${DRIVER_PATH}/ceph.conf + +# -------- 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/DATASTORE/TEMPLATE/HOST \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/POOL_NAME \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/STAGING_DIR \ + /DS_DRIVER_ACTION_DATA/IMAGE/PATH \ + /DS_DRIVER_ACTION_DATA/IMAGE/SIZE \ + /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) + +unset i + +BASE_PATH="${XPATH_ELEMENTS[i++]}" +RESTRICTED_DIRS="${XPATH_ELEMENTS[i++]}" +SAFE_DIRS="${XPATH_ELEMENTS[i++]}" +UMASK="${XPATH_ELEMENTS[i++]}" +DST_HOST="${XPATH_ELEMENTS[i++]:-$HOST}" +POOL_NAME="${XPATH_ELEMENTS[i++]:-$POOL_NAME}" +STAGING_DIR="${XPATH_ELEMENTS[i++]:-$STAGING_DIR}" +SRC="${XPATH_ELEMENTS[i++]}" +SIZE="${XPATH_ELEMENTS[i++]}" +MD5="${XPATH_ELEMENTS[i++]}" +SHA1="${XPATH_ELEMENTS[i++]}" +NO_DECOMPRESS="${XPATH_ELEMENTS[i++]}" +LIMIT_TRANSFER_BW="${XPATH_ELEMENTS[i++]}" + +set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK" + +IMAGE_HASH=`generate_image_hash` +TMP_DST="$STAGING_DIR/$IMAGE_HASH" + +IMAGE_NAME="one-${ID}" +RBD_SOURCE="${POOL_NAME}/${IMAGE_NAME}" + +DOWNLOADER_ARGS=`set_downloader_args "$MD5" "$SHA1" "$NO_DECOMPRESS" "$LIMIT_TRANSFER_BW" "$SRC" -` + +COPY_COMMAND="$UTILS_PATH/downloader.sh $DOWNLOADER_ARGS" + +case $SRC in +http://*|https://*) + log "Downloading $SRC to the image repository" + + DUMP="$COPY_COMMAND" + ;; + +*) + 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 image $SRC to the image repository" + + DUMP="$COPY_COMMAND" + ;; +esac + +exec_and_log "eval $DUMP | $SSH $DST_HOST $SUDO $DD of=$TMP_DST bs=64k" \ + "Error dumping $SRC to $DST_HOST:$TMP_DST" + +REGISTER_CMD=$(cat <