From 3642a8eb08407f3a3e388615858ce247844aeb5f Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Thu, 14 Feb 2013 18:54:34 +0100 Subject: [PATCH] Feature #1068: add Ceph TMs --- src/tm_mad/ceph/clone | 75 ++++++++++++++++++++++++++++++ src/tm_mad/ceph/delete | 93 +++++++++++++++++++++++++++++++++++++ src/tm_mad/ceph/ln | 25 ++++++++++ src/tm_mad/ceph/mv | 19 ++++++++ src/tm_mad/ceph/mvds | 82 ++++++++++++++++++++++++++++++++ src/tm_mad/ceph/postmigrate | 1 + src/tm_mad/ceph/premigrate | 1 + 7 files changed, 296 insertions(+) create mode 100755 src/tm_mad/ceph/clone create mode 100755 src/tm_mad/ceph/delete create mode 100755 src/tm_mad/ceph/ln create mode 100755 src/tm_mad/ceph/mv create mode 100755 src/tm_mad/ceph/mvds create mode 120000 src/tm_mad/ceph/postmigrate create mode 120000 src/tm_mad/ceph/premigrate 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