diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 02ddfdea50d..a1d29659da1 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -2035,11 +2035,11 @@ class VirtualMachine : public PoolObjectSQL * netowrking updates. * @param context attribute of the VM * @param error string if any - * @param only_auto boolean to generate context only for vnets + * @param only_auto boolean to generate context only for vnets * with NETWORK_MODE = auto * @return 0 on success */ - int generate_network_context(VectorAttribute * context, string& error, + int generate_network_context(VectorAttribute * context, string& error, bool only_auto); /** diff --git a/include/VirtualMachineDisk.h b/include/VirtualMachineDisk.h index eb9fb0cccb8..ed26f369fe1 100644 --- a/include/VirtualMachineDisk.h +++ b/include/VirtualMachineDisk.h @@ -154,7 +154,7 @@ class VirtualMachineDisk : public VirtualMachineAttribute /** * Return the TM_MAD_SYSTEM attribute */ - std::string get_tm_mad_system(); + std::string get_tm_mad_system() const; /* ---------------------------------------------------------------------- */ /* Image Manager Interface */ diff --git a/src/tm/TransferManager.cc b/src/tm/TransferManager.cc index db8d8d369cf..ba25df2926d 100644 --- a/src/tm/TransferManager.cc +++ b/src/tm/TransferManager.cc @@ -423,14 +423,18 @@ int TransferManager::prolog_transfer_command( // tm_mad fe:SOURCE host:remote_system_ds/disk.i vmid dsid if (clon == "YES") { - xfr << "CLONE "; + xfr << "CLONE"; } else { - xfr << "LN "; + xfr << "LN"; } - xfr << tm_mad << " "; + std::string tsys = disk->get_tm_mad_system(); + + xfr << "." << tsys; + + xfr << " " << tm_mad << " "; if ( source.find(":") == string::npos ) //Regular file { @@ -1121,7 +1125,14 @@ void TransferManager::epilog_transfer_command( return; } - //MVDS tm_mad hostname:remote_system_dir/disk.0 vmid dsid + + string tsys = disk->vector_value("TM_MAD_SYSTEM"); + if (!tsys.empty()) + { + tm_mad = tm_mad + "." + tsys; + } + + //MVDS tm_mad.(tm_mad_system) hostname:remote_system_dir/disk.0 vmid dsid xfr << "MVDS " << tm_mad << " " << host << ":" << vm->get_system_dir() << "/disk." << disk_id << " " @@ -1148,6 +1159,12 @@ void TransferManager::epilog_transfer_command( vv_rc = disk->vector_value("DATASTORE_ID", ds_id_i); } + string tsys = disk->vector_value("TM_MAD_SYSTEM"); + if (!tsys.empty()) + { + tm_mad = tm_mad + "." + tsys; + } + if ( !tm_mad.empty() && vv_rc == 0) { //DELETE tm_mad hostname:remote_system_dir/disk.i vmid ds_id @@ -1487,7 +1504,13 @@ int TransferManager::epilog_delete_commands(VirtualMachine *vm, } } - //DELETE tm_mad host:remote_system_dir/disk.i vmid dsid(image) + string tsys = (*disk)->vector_value("TM_MAD_SYSTEM"); + if (!tsys.empty()) + { + tm_mad = tm_mad + "." + tsys; + } + + //DELETE tm_mad(.tm_mad_system) host:remote_system_dir/disk.i vmid dsid(image) // *local* DELETE tm_mad fe:system_dir/disk.i vmid dsid(image) // *prev* DELETE tm_mad prev_host:remote_system_dir/disk.i vmid ds_id(image) xfr << "DELETE " @@ -2154,6 +2177,12 @@ void TransferManager::resize_command(VirtualMachine * vm, ds_id = disk->vector_value("DATASTORE_ID"); } + string tsys = disk->vector_value("TM_MAD_SYSTEM"); + if (!tsys.empty()) + { + tm_mad = tm_mad + "." + tsys; + } + //RESIZE tm_mad host:remote_system_dir/disk.i size vmid dsid xfr << "RESIZE " << tm_mad << " " diff --git a/src/tm_mad/ceph/clone b/src/tm_mad/ceph/clone index 888059eb2ad..6d1fc72ed15 100755 --- a/src/tm_mad/ceph/clone +++ b/src/tm_mad/ceph/clone @@ -74,15 +74,13 @@ done < <(onevm show -x $VM_ID| $XPATH \ /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CEPH_KEY \ /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CEPH_CONF \ /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SIZE \ - /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/ORIGINAL_SIZE \ - /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/TYPE ) + /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/ORIGINAL_SIZE ) CEPH_USER="${XPATH_ELEMENTS[j++]}" CEPH_KEY="${XPATH_ELEMENTS[j++]}" CEPH_CONF="${XPATH_ELEMENTS[j++]}" SIZE="${XPATH_ELEMENTS[j++]}" ORIGINAL_SIZE="${XPATH_ELEMENTS[j++]}" -TYPE="${XPATH_ELEMENTS[j++]}" #------------------------------------------------------------------------------- # Get Datastore information @@ -117,49 +115,26 @@ if [ -n "$EC_POOL_NAME" ]; then EC_POOL_OPT="--data-pool ${EC_POOL_NAME}" fi -if [ "${TYPE}" = 'FILE' ]; then - ssh_make_path $DST_HOST $DST_DIR 'ssh' +CLONE_CMD=$(cat </dev/null 2>&1 && exit 0 - rbd_make_snap $SRC_PATH + rbd_make_snap $SRC_PATH - set -e -o pipefail + set -e -o pipefail - if [ "\$(rbd_format $SRC_PATH)" = "2" ]; then - $RBD export "$SRC_PATH@snap" $DST_PATH - else - $RBD export $SRC_PATH $DST_PATH - fi + if [ "\$(rbd_format $SRC_PATH)" = "2" ]; then + $RBD ${EC_POOL_OPT} clone "$SRC_PATH@snap" $RBD_DST + else + $RBD copy $SRC_PATH $RBD_DST + fi - if [ -n "$ORIGINAL_SIZE" -a "$SIZE" -gt "$ORIGINAL_SIZE" ]; then - qemu-img resize ${DST_PATH} ${SIZE}M - fi + if [ -n "$ORIGINAL_SIZE" -a "$SIZE" -gt "$ORIGINAL_SIZE" ]; then + $RBD resize $RBD_DST --size $SIZE + fi EOF ) -else - CLONE_CMD=$(cat </dev/null 2>&1 && exit 0 - - rbd_make_snap $SRC_PATH - - set -e -o pipefail - - if [ "\$(rbd_format $SRC_PATH)" = "2" ]; then - $RBD ${EC_POOL_OPT} clone "$SRC_PATH@snap" $RBD_DST - else - $RBD copy $SRC_PATH $RBD_DST - fi - - if [ -n "$ORIGINAL_SIZE" -a "$SIZE" -gt "$ORIGINAL_SIZE" ]; then - $RBD resize $RBD_DST --size $SIZE - fi -EOF -) -fi ssh_exec_and_log_stdin "$DST_HOST" "$CLONE_CMD" "$CEPH_UTILS" \ "Error cloning $SRC_PATH to $RBD_DST in $DST_HOST" diff --git a/src/tm_mad/ceph/clone.ssh b/src/tm_mad/ceph/clone.ssh new file mode 100644 index 00000000000..1517d91192a --- /dev/null +++ b/src/tm_mad/ceph/clone.ssh @@ -0,0 +1,124 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems # +# # +# 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.ssh 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 + LIB_LOCATION=/usr/lib/one +else + TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh + LIB_LOCATION=$ONE_LOCATION/lib +fi + +DRIVER_PATH=$(dirname $0) + +source $TMCOMMON +source ${DRIVER_PATH}/../../etc/datastore/ceph/ceph.conf + +CEPH_UTILS=${DRIVER_PATH}/../../datastore/ceph/ceph_utils.sh + +#------------------------------------------------------------------------------- +# Compute the destination image name +#------------------------------------------------------------------------------- + +DST_HOST=`arg_host $DST` + +SRC_PATH=`arg_path $SRC` +DST_PATH=`arg_path $DST` + +DST_DIR=`dirname $DST_PATH` + +DISK_ID=$(echo $DST|awk -F. '{print $NF}') +RBD_DST="${SRC_PATH}-${VM_ID}-${DISK_ID}" + +#------------------------------------------------------------------------------- +# Get Image information +#------------------------------------------------------------------------------- + +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]/CEPH_USER \ + /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CEPH_KEY \ + /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CEPH_CONF \ + /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SIZE \ + /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/ORIGINAL_SIZE) + +CEPH_USER="${XPATH_ELEMENTS[j++]}" +CEPH_KEY="${XPATH_ELEMENTS[j++]}" +CEPH_CONF="${XPATH_ELEMENTS[j++]}" +SIZE="${XPATH_ELEMENTS[j++]}" +ORIGINAL_SIZE="${XPATH_ELEMENTS[j++]}" + +#------------------------------------------------------------------------------- +# Create @snap and export it +#------------------------------------------------------------------------------- + +if [ -n "$CEPH_USER" ]; then + RBD="$RBD --id ${CEPH_USER}" +fi + +if [ -n "$CEPH_KEY" ]; then + RBD="$RBD --keyfile ${CEPH_KEY}" +fi + +if [ -n "$CEPH_CONF" ]; then + RBD="$RBD --conf ${CEPH_CONF}" +fi + + +ssh_make_path $DST_HOST $DST_DIR 'ssh' + +CLONE_CMD=$(cat < persistnet) @@ -93,27 +88,12 @@ if [ -n "$CEPH_CONF" ]; then RBD="$RBD --conf ${CEPH_CONF}" fi -if [ "${TYPE}" = 'FILE' ]; then - ssh_make_path $DST_HOST $DST_DIR 'ssh' - - LN_CMD=$(cat < persistnet) +#------------------------------------------------------------------------------- + +if [ -n "$CEPH_USER" ]; then + RBD="$RBD --id ${CEPH_USER}" +fi + +if [ -n "$CEPH_KEY" ]; then + RBD="$RBD --keyfile ${CEPH_KEY}" +fi + +if [ -n "$CEPH_CONF" ]; then + RBD="$RBD --conf ${CEPH_CONF}" +fi + +ssh_make_path $DST_HOST $DST_DIR 'ssh' + +LN_CMD=$(cat <