diff --git a/include/Image.h b/include/Image.h index f5626477ed..08949f6c72 100644 --- a/include/Image.h +++ b/include/Image.h @@ -77,7 +77,8 @@ public: { FILE = 0, /** < File-based disk */ CD_ROM = 1, /** < An ISO9660 disk */ - BLOCK = 2 /** < Block-device disk */ + BLOCK = 2, /** < Block-device disk */ + RBD = 3 /** < CEPH RBD disk */ }; /** @@ -92,6 +93,7 @@ public: case FILE: return "FILE" ; break; case CD_ROM: return "CDROM" ; break; case BLOCK: return "BLOCK" ; break; + case RBD: return "RBD" ; break; default: return ""; } }; diff --git a/install.sh b/install.sh index f1ab3a879e..7d64948adc 100755 --- a/install.sh +++ b/install.sh @@ -238,6 +238,7 @@ VAR_DIRS="$VAR_LOCATION/remotes \ $VAR_LOCATION/remotes/tm/vmfs \ $VAR_LOCATION/remotes/tm/iscsi \ $VAR_LOCATION/remotes/tm/lvm \ + $VAR_LOCATION/remotes/tm/ceph \ $VAR_LOCATION/remotes/hooks \ $VAR_LOCATION/remotes/hooks/ft \ $VAR_LOCATION/remotes/datastore \ @@ -247,6 +248,7 @@ VAR_DIRS="$VAR_LOCATION/remotes \ $VAR_LOCATION/remotes/datastore/vmfs \ $VAR_LOCATION/remotes/datastore/iscsi \ $VAR_LOCATION/remotes/datastore/lvm \ + $VAR_LOCATION/remotes/datastore/ceph \ $VAR_LOCATION/remotes/auth \ $VAR_LOCATION/remotes/auth/plain \ $VAR_LOCATION/remotes/auth/ssh \ @@ -440,6 +442,7 @@ INSTALL_FILES=( TM_VMFS_FILES:$VAR_LOCATION/remotes/tm/vmfs TM_ISCSI_FILES:$VAR_LOCATION/remotes/tm/iscsi TM_LVM_FILES:$VAR_LOCATION/remotes/tm/lvm + TM_CEPH_FILES:$VAR_LOCATION/remotes/tm/ceph TM_DUMMY_FILES:$VAR_LOCATION/remotes/tm/dummy DATASTORE_DRIVER_COMMON_SCRIPTS:$VAR_LOCATION/remotes/datastore/ DATASTORE_DRIVER_DUMMY_SCRIPTS:$VAR_LOCATION/remotes/datastore/dummy @@ -448,6 +451,7 @@ INSTALL_FILES=( DATASTORE_DRIVER_VMFS_SCRIPTS:$VAR_LOCATION/remotes/datastore/vmfs DATASTORE_DRIVER_ISCSI_SCRIPTS:$VAR_LOCATION/remotes/datastore/iscsi DATASTORE_DRIVER_LVM_SCRIPTS:$VAR_LOCATION/remotes/datastore/lvm + DATASTORE_DRIVER_CEPH_SCRIPTS:$VAR_LOCATION/remotes/datastore/ceph NETWORK_FILES:$VAR_LOCATION/remotes/vnm NETWORK_8021Q_FILES:$VAR_LOCATION/remotes/vnm/802.1Q NETWORK_DUMMY_FILES:$VAR_LOCATION/remotes/vnm/dummy @@ -888,6 +892,7 @@ NETWORK_VMWARE_FILES="src/vnm_mad/remotes/vmware/clean \ # - VMWARE TM, $VAR_LOCATION/tm/vmware # - ISCSI TM, $VAR_LOCATION/tm/iscsi # - LVM TM, $VAR_LOCATION/tm/lvm +# - CEPH TM, $VAR_LOCATION/tm/ceph #------------------------------------------------------------------------------- TM_FILES="src/tm_mad/tm_common.sh" @@ -963,6 +968,14 @@ TM_LVM_FILES="src/tm_mad/lvm/clone \ src/tm_mad/lvm/postmigrate \ src/tm_mad/lvm/delete" +TM_CEPH_FILES="src/tm_mad/ceph/clone \ + src/tm_mad/ceph/ln \ + src/tm_mad/ceph/mv \ + src/tm_mad/ceph/mvds \ + src/tm_mad/ceph/premigrate \ + src/tm_mad/ceph/postmigrate \ + src/tm_mad/ceph/delete" + #------------------------------------------------------------------------------- # Datastore drivers, to be installed under $REMOTES_LOCATION/datastore # - Dummy Image Repository, $REMOTES_LOCATION/datastore/dummy @@ -1016,6 +1029,13 @@ DATASTORE_DRIVER_LVM_SCRIPTS="src/datastore_mad/remotes/lvm/cp \ src/datastore_mad/remotes/lvm/clone \ src/datastore_mad/remotes/lvm/lvm.conf" +DATASTORE_DRIVER_CEPH_SCRIPTS="src/datastore_mad/remotes/ceph/cp \ + src/datastore_mad/remotes/ceph/mkfs \ + src/datastore_mad/remotes/ceph/stat \ + src/datastore_mad/remotes/ceph/rm \ + src/datastore_mad/remotes/ceph/clone \ + src/datastore_mad/remotes/ceph/ceph.conf" + #------------------------------------------------------------------------------- # Migration scripts for onedb command, to be installed under $LIB_LOCATION #------------------------------------------------------------------------------- diff --git a/share/etc/oned.conf b/share/etc/oned.conf index 0f97012654..5833e0e5e7 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -313,7 +313,7 @@ VM_MAD = [ TM_MAD = [ executable = "one_tm", - arguments = "-t 15 -d dummy,lvm,shared,qcow2,ssh,vmfs,iscsi" ] + arguments = "-t 15 -d dummy,lvm,shared,qcow2,ssh,vmfs,iscsi,ceph" ] #******************************************************************************* # Datastore Driver Configuration @@ -330,7 +330,7 @@ TM_MAD = [ DATASTORE_MAD = [ executable = "one_datastore", - arguments = "-t 15 -d fs,vmware,vmfs,iscsi,lvm" + arguments = "-t 15 -d fs,vmware,vmfs,iscsi,lvm,ceph" ] #******************************************************************************* diff --git a/src/cli/one_helper/onedatastore_helper.rb b/src/cli/one_helper/onedatastore_helper.rb index 72e141a188..9512eed32d 100644 --- a/src/cli/one_helper/onedatastore_helper.rb +++ b/src/cli/one_helper/onedatastore_helper.rb @@ -110,6 +110,7 @@ class OneDatastoreHelper < OpenNebulaHelper::OneHelper puts str % ["DS_MAD", datastore['DS_MAD']] puts str % ["TM_MAD", datastore['TM_MAD']] puts str % ["BASE PATH",datastore['BASE_PATH']] + puts str % ["DISK_TYPE",Image::DISK_TYPES[datastore['DISK_TYPE'].to_i]] puts CLIHelper.print_header(str_h1 % "PERMISSIONS",false) diff --git a/src/cli/one_helper/oneimage_helper.rb b/src/cli/one_helper/oneimage_helper.rb index dc3bf1c93b..9f007f0c11 100644 --- a/src/cli/one_helper/oneimage_helper.rb +++ b/src/cli/one_helper/oneimage_helper.rb @@ -102,14 +102,14 @@ class OneImageHelper < OpenNebulaHelper::OneHelper { :name => "disk_type", :large => "--disk_type disk_type", - :description => "Type of the image (BLOCK, CDROM or FILE)", + :description => "Type of the image (BLOCK, CDROM, RBD or FILE)", :format => String, :proc => lambda do |o, options| type=o.strip.upcase - if %w{BLOCK CDROM FILE}.include? type + if %w{BLOCK CDROM FILE RBD}.include? type [0, type] else - [-1, "Disk type must be BLOCK, CDROM or FILE"] + [-1, "Disk type must be BLOCK, CDROM, RBD or FILE"] end end }, diff --git a/src/datastore/Datastore.cc b/src/datastore/Datastore.cc index 261766788a..2b2af549cd 100644 --- a/src/datastore/Datastore.cc +++ b/src/datastore/Datastore.cc @@ -174,7 +174,7 @@ int Datastore::insert(SqlDB *db, string& error_str) if ( type == IMAGE_DS ) { - get_template_attribute("DISK_TYPE", s_disk_type); + erase_template_attribute("DISK_TYPE", s_disk_type); if (s_disk_type == "BLOCK") { @@ -184,6 +184,10 @@ int Datastore::insert(SqlDB *db, string& error_str) { disk_type = Image::CD_ROM; } + else if (s_disk_type == "RBD") + { + disk_type = Image::RBD; + } } if ( tm_mad.empty() == true ) diff --git a/src/datastore_mad/remotes/ceph/ceph.conf b/src/datastore_mad/remotes/ceph/ceph.conf new file mode 100644 index 0000000000..36d4df0058 --- /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=/var/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 < "CX" } + DISK_TYPES=%w{FILE CD_ROM BLOCK RBD} + # Creates an Image description with just its identifier # this method should be used to create plain Image objects. # +id+ the id of the image diff --git a/src/tm_mad/ceph/clone b/src/tm_mad/ceph/clone new file mode 100755 index 0000000000..25a8d96401 --- /dev/null +++ b/src/tm_mad/ceph/clone @@ -0,0 +1,75 @@ +#!/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. # +#--------------------------------------------------------------------------- # + +# clone fe:SOURCE host:remote_system_ds/disk.i size +# - fe is the front-end hostname +# - SOURCE is the path of the disk image in the form DS_BASE_PATH/disk +# - host is the target host to deploy the VM +# - remote_system_ds is the path for the system datastore in the host + +SRC=$1 +DST=$2 +VM_ID=$3 +DS_ID=$4 + +if [ -z "${ONE_LOCATION}" ]; then + TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh +else + TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh +fi + +DRIVER_PATH=$(dirname $0) + +source $TMCOMMON +source ${DRIVER_PATH}/../../datastore/ceph/ceph.conf + +#------------------------------------------------------------------------------- +# Get Image information +#------------------------------------------------------------------------------- + +DISK_ID=$(echo "$DST_PATH" | $AWK -F. '{print $NF}') + +XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin" + +unset i XPATH_ELEMENTS + +while IFS= read -r -d '' element; do + XPATH_ELEMENTS[i++]="$element" +done < <(onedatastore show -x $DS_ID | $XPATH \ + /DATASTORE/TEMPLATE/HOST) + +unset i + +CEPH_HOST="${XPATH_ELEMENTS[i++]}" + +#------------------------------------------------------------------------------- +# Compute the destination image name +#------------------------------------------------------------------------------- + +SRC_PATH=`arg_path $SRC` + +DISK_ID=$(echo $DST|awk -F. '{print $NF}') +RBD_DST="${SRC_PATH}-${VM_ID}-${DISK_ID}" + +#------------------------------------------------------------------------------- +# Clone the image +#------------------------------------------------------------------------------- + +ssh_exec_and_log "$CEPH_HOST" "$RBD copy $SRC_PATH $RBD_DST" \ + "Error cloning $SRC_PATH to $RBD_DST in $CEPH_HOST" +exit 0 diff --git a/src/tm_mad/ceph/delete b/src/tm_mad/ceph/delete new file mode 100755 index 0000000000..3adff3d505 --- /dev/null +++ b/src/tm_mad/ceph/delete @@ -0,0 +1,93 @@ +#!/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. # +#--------------------------------------------------------------------------- # + +# DELETE +# - host is the target host to deploy the VM +# - remote_system_ds is the path for the system datastore in the host + +DST=$1 +VM_ID=$2 +DS_ID=$3 + +if [ -z "${ONE_LOCATION}" ]; then + TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh +else + TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh +fi + +DRIVER_PATH=$(dirname $0) + +source $TMCOMMON +source ${DRIVER_PATH}/../../datastore/ceph/ceph.conf + +#------------------------------------------------------------------------------- +# Process destination +#------------------------------------------------------------------------------- + +DST_PATH=`arg_path $DST` +DST_HOST=`arg_host $DST` + +#------------------------------------------------------------------------------- +# Delete and exit if directory +#------------------------------------------------------------------------------- + +if [ `is_disk $DST_PATH` -eq 0 ]; then + # Directory + log "Deleting $DST_PATH" + ssh_exec_and_log "$DST_HOST" "rm -rf $DST_PATH" "Error deleting $DST_PATH" + exit 0 +fi + +#------------------------------------------------------------------------------- +# Get Image information +#------------------------------------------------------------------------------- + +DISK_ID=$(echo "$DST_PATH" | $AWK -F. '{print $NF}') + +XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin" + +unset i j XPATH_ELEMENTS + +while IFS= read -r -d '' element; do + XPATH_ELEMENTS[i++]="$element" +done < <(onevm show -x $VM_ID| $XPATH \ + /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SOURCE \ + /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/PERSISTENT) + +SRC="${XPATH_ELEMENTS[j++]}" +PERSISTENT="${XPATH_ELEMENTS[j++]}" + +# Exit if persistent +[ -n "$PERSISTENT" ] && exit 0 + +# non persistent, so the name will be "/one---" +RBD_SRC="${SRC}-${VM_ID}-${DISK_ID}" + +#------------------------------------------------------------------------------- +# Delete the device +#------------------------------------------------------------------------------- + +log "Deleting $DST_PATH" + +# Note that this command, as opposed to the rest of $RBD commands in this set of +# drivers, is executed in the worker node and not in the CEPH frontend. + +ssh_exec_and_log "$DST_HOST" "$RBD rm $RBD_SRC" \ + "Error deleting $RBD_SRC in $DST_HOST" + +exit 0 diff --git a/src/tm_mad/ceph/ln b/src/tm_mad/ceph/ln new file mode 100755 index 0000000000..b9925ea312 --- /dev/null +++ b/src/tm_mad/ceph/ln @@ -0,0 +1,25 @@ +#!/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. # +#--------------------------------------------------------------------------- # + +# clone fe:SOURCE host:remote_system_ds/disk.i size +# - fe is the front-end hostname +# - SOURCE is the path of the disk image in the form DS_BASE_PATH/disk +# - host is the target host to deploy the VM +# - remote_system_ds is the path for the system datastore in the host + +exit 0 diff --git a/src/tm_mad/ceph/mv b/src/tm_mad/ceph/mv new file mode 100755 index 0000000000..2c409c7eac --- /dev/null +++ b/src/tm_mad/ceph/mv @@ -0,0 +1,19 @@ +#!/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. # +#--------------------------------------------------------------------------- # + +exit 0 diff --git a/src/tm_mad/ceph/mvds b/src/tm_mad/ceph/mvds new file mode 100755 index 0000000000..b777e5d3bb --- /dev/null +++ b/src/tm_mad/ceph/mvds @@ -0,0 +1,82 @@ +#!/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. # +#--------------------------------------------------------------------------- # + +# mvds host:remote_system_ds/disk.i fe:SOURCE +# - fe is the front-end hostname +# - SOURCE is the path of the disk image in the form DS_BASE_PATH/disk +# - host is the target host to deploy the VM +# - remote_system_ds is the path for the system datastore in the host + +SRC=$1 +DST=$2 +VM_ID=$3 +DS_ID=$4 + +if [ -z "${ONE_LOCATION}" ]; then + TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh +else + TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh +fi + +DRIVER_PATH=$(dirname $0) + +source $TMCOMMON +source ${DRIVER_PATH}/../../datastore/ceph/ceph.conf + +#------------------------------------------------------------------------------- +# Set dst path and dir +#------------------------------------------------------------------------------- + +SRC_HOST=`arg_host $SRC` +SRC_PATH=`arg_path $SRC` + +#------------------------------------------------------------------------------- +# Get Image information +#------------------------------------------------------------------------------- + +DISK_ID=$(echo "$SRC_PATH" | $AWK -F. '{print $NF}') + +XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin" + +unset i j XPATH_ELEMENTS + +while IFS= read -r -d '' element; do + XPATH_ELEMENTS[i++]="$element" +done < <(onevm show -x $VM_ID| $XPATH \ + /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SOURCE \ + /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/PERSISTENT) + +RBD_SRC="${XPATH_ELEMENTS[j++]}" +PERSISTENT="${XPATH_ELEMENTS[j++]}" + +# Exit if persistent +[ -n "$PERSISTENT" ] && exit 0 + +# non persistent, so the name will be "/one---" +RBD_DST="${RBD_SRC}-${VM_ID}-${DISK_ID}" + +#------------------------------------------------------------------------------- +# Move the image back to the datastore +#------------------------------------------------------------------------------- + +log "Dumping $RBD_DST to $DST" + +ssh_exec_and_log "$SRC_HOST" "$RBD rename $RBD_DST $DST" \ + "Error saving $RBD_DST as $DST in $SRC_HOST" + +exit 0 diff --git a/src/tm_mad/ceph/postmigrate b/src/tm_mad/ceph/postmigrate new file mode 120000 index 0000000000..d580dd8260 --- /dev/null +++ b/src/tm_mad/ceph/postmigrate @@ -0,0 +1 @@ +../common/postmigrate \ No newline at end of file diff --git a/src/tm_mad/ceph/premigrate b/src/tm_mad/ceph/premigrate new file mode 120000 index 0000000000..0e108a8a26 --- /dev/null +++ b/src/tm_mad/ceph/premigrate @@ -0,0 +1 @@ +../common/premigrate \ No newline at end of file diff --git a/src/vmm/LibVirtDriverKVM.cc b/src/vmm/LibVirtDriverKVM.cc index d1030ba911..56872d9bdb 100644 --- a/src/vmm/LibVirtDriverKVM.cc +++ b/src/vmm/LibVirtDriverKVM.cc @@ -56,6 +56,9 @@ int LibVirtDriver::deployment_description_kvm( string ro = ""; string driver = ""; string cache = ""; + string source = ""; + string clone = ""; + int disk_id; string default_driver = ""; string default_driver_cache = ""; @@ -305,7 +308,7 @@ int LibVirtDriver::deployment_description_kvm( if ( disk == 0 ) { - continue; + continue; } type = disk->vector_value("TYPE"); @@ -313,6 +316,9 @@ int LibVirtDriver::deployment_description_kvm( ro = disk->vector_value("READONLY"); driver = disk->vector_value("DRIVER"); cache = disk->vector_value("CACHE"); + source = disk->vector_value("SOURCE"); + clone = disk->vector_value("CLONE"); + disk->vector_value_str("DISK_ID", disk_id); if (target.empty()) @@ -342,6 +348,19 @@ int LibVirtDriver::deployment_description_kvm( << "\t\t\t" << endl; } + else if ( type == "RBD" ) + { + file << "\t\t" << endl + << "\t\t\t" << endl; + } else if ( type == "CDROM" ) { file << "\t\t" << endl