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/install.sh b/install.sh index a0055ee90c4..7a312158032 100755 --- a/install.sh +++ b/install.sh @@ -1230,8 +1230,10 @@ TM_FS_LVM_ETC_FILES="src/tm_mad/fs_lvm/fs_lvm.conf" TM_QCOW2_FILES="src/tm_mad/qcow2/clone \ + src/tm_mad/qcow2/clone.ssh \ src/tm_mad/qcow2/delete \ src/tm_mad/qcow2/ln \ + src/tm_mad/qcow2/ln.ssh \ src/tm_mad/qcow2/monitor \ src/tm_mad/qcow2/mkswap \ src/tm_mad/qcow2/mkimage \ @@ -1241,11 +1243,13 @@ TM_QCOW2_FILES="src/tm_mad/qcow2/clone \ src/tm_mad/qcow2/postmigrate \ src/tm_mad/qcow2/failmigrate \ src/tm_mad/qcow2/mvds \ + src/tm_mad/qcow2/mvds.ssh \ src/tm_mad/qcow2/snap_create \ src/tm_mad/qcow2/snap_create_live \ src/tm_mad/qcow2/snap_delete \ src/tm_mad/qcow2/snap_revert \ src/tm_mad/qcow2/cpds \ + src/tm_mad/qcow2/cpds.ssh \ src/tm_mad/qcow2/resize" TM_SSH_FILES="src/tm_mad/ssh/clone \ @@ -1288,10 +1292,14 @@ TM_DUMMY_FILES="src/tm_mad/dummy/clone \ src/tm_mad/dummy/resize" TM_CEPH_FILES="src/tm_mad/ceph/clone \ + src/tm_mad/ceph/clone.ssh \ src/tm_mad/ceph/ln \ + src/tm_mad/ceph/ln.ssh \ src/tm_mad/ceph/mv \ src/tm_mad/ceph/mvds \ + src/tm_mad/ceph/mvds.ssh \ src/tm_mad/ceph/cpds \ + src/tm_mad/ceph/cpds.ssh \ src/tm_mad/ceph/premigrate \ src/tm_mad/ceph/postmigrate \ src/tm_mad/ceph/snap_create \ @@ -1300,11 +1308,13 @@ TM_CEPH_FILES="src/tm_mad/ceph/clone \ src/tm_mad/ceph/snap_revert \ src/tm_mad/ceph/failmigrate \ src/tm_mad/ceph/delete \ + src/tm_mad/ceph/delete.ssh \ src/tm_mad/ceph/context \ src/tm_mad/ceph/mkimage \ src/tm_mad/ceph/monitor \ src/tm_mad/ceph/mkswap \ - src/tm_mad/ceph/resize" + src/tm_mad/ceph/resize \ + src/tm_mad/ceph/resize.ssh" TM_DEV_FILES="src/tm_mad/dev/clone \ src/tm_mad/dev/ln \ diff --git a/src/tm/TransferManager.cc b/src/tm/TransferManager.cc index 1706b356a5b..1c8cc5a91bd 100644 --- a/src/tm/TransferManager.cc +++ b/src/tm/TransferManager.cc @@ -333,6 +333,7 @@ int TransferManager::prolog_transfer_command( string size; string format; string tm_mad; + string tm_mad_system; string ds_id; int disk_id = disk->get_disk_id(); @@ -416,21 +417,27 @@ int TransferManager::prolog_transfer_command( one_util::toupper(clon); + std::string tsys = disk->get_tm_mad_system(); + if (!tsys.empty()) + { + tm_mad_system = "." + tsys; + } + // ----------------------------------------------------------------- // CLONE or LINK disk images // ----------------------------------------------------------------- - // tm_mad fe:SOURCE host:remote_system_ds/disk.i vmid dsid + // (.tm_mad_system) 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 << " "; + xfr << tm_mad_system << " " << tm_mad << " "; if ( source.find(":") == string::npos ) //Regular file { @@ -722,6 +729,7 @@ void TransferManager::prolog_migr_action(int vid) string xfr_name; string tm_mad; + string tm_mad_system; string vm_tm_mad; int ds_id; @@ -791,9 +799,17 @@ void TransferManager::prolog_migr_action(int vid) } } - //MV tm_mad prev_host:remote_system_dir/disk.i host:remote_system_dir/disk.i vmid dsid(image) - xfr << "MV " - << tm_mad << " " + (*disk)->vector_value("TM_MAD"); + string tsys = (*disk)->vector_value("TM_MAD_SYSTEM"); + if (!tsys.empty()) + { + tm_mad_system = "." + tsys; + } + + //MV(.tm_mad_system) tm_mad prev_host:remote_system_dir/disk.i host:remote_system_dir/disk.i vmid dsid(image) + xfr << "MV" + << tm_mad_system + << " " << tm_mad << " " << vm->get_previous_hostname() << ":" << vm->get_previous_system_dir() << "/disk." << disk_id << " " << vm->get_hostname() << ":" @@ -852,6 +868,7 @@ void TransferManager::prolog_resume_action(int vid) string xfr_name; string tm_mad; + string tm_mad_system; string vm_tm_mad; string token_password; @@ -926,9 +943,17 @@ void TransferManager::prolog_resume_action(int vid) } } - //MV tm_mad fe:system_dir/disk.i host:remote_system_dir/disk.i vmid dsid(image) - xfr << "MV " - << tm_mad << " " + (*disk)->vector_value("TM_MAD"); + string tsys = (*disk)->vector_value("TM_MAD_SYSTEM"); + if (!tsys.empty()) + { + tm_mad_system = "." + tsys; + } + + //MV(.tm_mad_system) tm_mad fe:system_dir/disk.i host:remote_system_dir/disk.i vmid dsid(image) + xfr << "MV" + << tm_mad_system + << " " << tm_mad << " " << nd.get_nebula_hostname() << ":" << vm->get_system_dir() << "/disk." << disk_id << " " << vm->get_hostname() << ":" @@ -1102,6 +1127,7 @@ void TransferManager::epilog_transfer_command( { string save = disk->vector_value("SAVE"); int disk_id = disk->get_disk_id(); + string tm_mad_system; if ( one_util::toupper(save) == "YES" ) { @@ -1121,9 +1147,14 @@ void TransferManager::epilog_transfer_command( return; } - //MVDS tm_mad hostname:remote_system_dir/disk.0 vmid dsid - xfr << "MVDS " - << tm_mad << " " + string tsys = disk->vector_value("TM_MAD_SYSTEM"); + if (!tsys.empty()) + { + tm_mad_system = "." + tsys; + } + //MVDS(.tm_mad_system) tm_mad hostname:remote_system_dir/disk.0 vmid dsid + xfr << "MVDS" << tm_mad_system + << " " << tm_mad << " " << host << ":" << vm->get_system_dir() << "/disk." << disk_id << " " << source << " " << vm->get_oid() << " " @@ -1148,10 +1179,17 @@ 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_system = "." + tsys; + } + if ( !tm_mad.empty() && vv_rc == 0) { - //DELETE tm_mad hostname:remote_system_dir/disk.i vmid ds_id - xfr << "DELETE " + //DELETE(.tm_mad_system) tm_mad hostname:remote_system_dir/disk.i vmid ds_id + xfr << "DELETE" + << tm_mad_system << " " << tm_mad << " " << host << ":" << vm->get_system_dir() << "/disk." << disk_id << " " << vm->get_oid() << " " @@ -1278,6 +1316,7 @@ void TransferManager::epilog_stop_action(int vid) string xfr_name; string tm_mad; + string tm_mad_system; string vm_tm_mad; int ds_id; @@ -1346,9 +1385,16 @@ void TransferManager::epilog_stop_action(int vid) } } + string tsys = (*disk)->vector_value("TM_MAD_SYSTEM"); + if (!tsys.empty()) + { + tm_mad_system = "." + tsys; + } + //MV tm_mad host:remote_system_dir/disk.i fe:system_dir/disk.i vmid dsid(image) - xfr << "MV " - << tm_mad << " " + xfr << "MV" + << tm_mad_system + << " " << tm_mad << " " << vm->get_hostname() << ":" << vm->get_system_dir() << "/disk." << disk_id << " " << nd.get_nebula_hostname() << ":" @@ -1409,6 +1455,7 @@ int TransferManager::epilog_delete_commands(VirtualMachine *vm, string vm_tm_mad; string tm_mad; + string tm_mad_system; string host; string system_dir; @@ -1487,11 +1534,17 @@ 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_system = "." + 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 " - << tm_mad << " " + xfr << "DELETE" << tm_mad_system + << " " << tm_mad << " " << host << ":" << system_dir << "/disk." << disk_id << " " << vm->get_oid() << " " @@ -1898,6 +1951,8 @@ void TransferManager::saveas_hot_action(int vid) string snap_id; string tm_mad; string ds_id; + string tsys; + string tm_mad_system; ostringstream os; @@ -1906,6 +1961,7 @@ void TransferManager::saveas_hot_action(int vid) VirtualMachine * vm; const TransferManagerDriver * tm_md; + VirtualMachineDisk * disk; Nebula& nd = Nebula::instance(); @@ -1944,9 +2000,19 @@ void TransferManager::saveas_hot_action(int vid) goto error_file; } + disk = vm->get_disk(disk_id); + if (disk != 0) + { + tsys = disk->vector_value("TM_MAD_SYSTEM"); + if (!tsys.empty()) + { + tm_mad_system = "." + tsys; + } + } + //CPDS tm_mad hostname:remote_system_dir/disk.0 source snapid vmid dsid - xfr << "CPDS " - << tm_mad << " " + xfr << "CPDS" << tm_mad_system + << " " << tm_mad << " " << vm->get_hostname() << ":" << vm->get_system_dir() << "/disk." << disk_id << " " << src << " " @@ -2015,9 +2081,12 @@ int TransferManager::snapshot_transfer_command( VirtualMachine * vm, const char * snap_action, ostream& xfr) { string tm_mad; + string tsys; + string tm_mad_system; int ds_id; int disk_id; int snap_id; + VirtualMachineDisk * disk; if (vm->get_snapshot_disk(ds_id, tm_mad, disk_id, snap_id) == -1) { @@ -2026,8 +2095,18 @@ int TransferManager::snapshot_transfer_command( return -1; } - //SNAP_CREATE tm_mad host:remote_system_dir/disk.0 snapid vmid dsid - xfr << snap_action << " " + disk = vm->get_disk(disk_id); + if (disk != 0) + { + tsys = disk->vector_value("TM_MAD_SYSTEM"); + if (!tsys.empty()) + { + tm_mad_system = "." + tsys; + } + } + + //SNAP_CREATE(.tm_mad_system) tm_mad host:remote_system_dir/disk.0 snapid vmid dsid + xfr << snap_action << tm_mad_system << " " << tm_mad << " " << vm->get_hostname() << ":" << vm->get_system_dir() << "/disk." << disk_id << " " @@ -2141,6 +2220,7 @@ void TransferManager::resize_command(VirtualMachine * vm, const VirtualMachineDisk * disk, ostream& xfr) { string tm_mad; + string tm_mad_system; string ds_id; if ( disk->is_volatile() ) @@ -2154,9 +2234,15 @@ void TransferManager::resize_command(VirtualMachine * vm, ds_id = disk->vector_value("DATASTORE_ID"); } - //RESIZE tm_mad host:remote_system_dir/disk.i size vmid dsid - xfr << "RESIZE " - << tm_mad << " " + string tsys = disk->vector_value("TM_MAD_SYSTEM"); + if (!tsys.empty()) + { + tm_mad_system = "." + tsys; + } + + //RESIZE.(tm_mad_system) tm_mad host:remote_system_dir/disk.i size vmid dsid + xfr << "RESIZE" << tm_mad_system + << " " << tm_mad << " " << vm->get_hostname() << ":" << vm->get_system_dir()<< "/disk."<< disk->vector_value("DISK_ID")<< " " << disk->vector_value("SIZE") << " " 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 100755 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 <&2 + RBD_DST=\$(rbd_find_snap $RBD_DST $SNAP_ID) + + if [ -z "\$RBD_DST" ]; then + echo "Target RBD not found." >&2 exit 1 fi - $RBD import $FORMAT_OPT $SRC_PATH $DST -EOF -) -else - COPY_CMD=$(cat <&2 - exit 1 - fi - - RBD_DST=\$RBD_DST@$SNAP_ID - else - RBD_DST=$RBD_DST - fi + RBD_DST=\$RBD_DST@$SNAP_ID + else + RBD_DST=$RBD_DST + fi - $RBD ${EC_POOL_OPT} copy \$RBD_DST $DST + $RBD ${EC_POOL_OPT} copy \$RBD_DST $DST EOF ) -fi ssh_exec_and_log_stdin "$SRC_HOST" "$COPY_CMD" "$CEPH_UTILS" \ "Error cloning $RBD_DST to $DST in $SRC_HOST" diff --git a/src/tm_mad/ceph/cpds.ssh b/src/tm_mad/ceph/cpds.ssh new file mode 100755 index 00000000000..a22f9075e2e --- /dev/null +++ b/src/tm_mad/ceph/cpds.ssh @@ -0,0 +1,128 @@ +#!/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. # +#--------------------------------------------------------------------------- # + +# cpds host:remote_system_ds/disk.i fe:SOURCE snapid vmid dsid +# - 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 +# - snapid is the snapshot id. "-1" for none + +SRC=$1 +DST=$2 +SNAP_ID=$3 +VM_ID=$4 +DS_ID=$5 + +#-------------------------------------------------------------------------------- + +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 +source ${DRIVER_PATH}/../../etc/vmm/kvm/kvmrc + +CEPH_UTILS=${DRIVER_PATH}/../../datastore/ceph/ceph_utils.sh + +#------------------------------------------------------------------------------- +# Set dst path and dir +#------------------------------------------------------------------------------- + +SRC_PATH=`arg_path $SRC` +SRC_HOST=`arg_host $SRC` +RBD_SRC=`arg_path $SRC` + +#------------------------------------------------------------------------------- +# Get Image information +#------------------------------------------------------------------------------- + +DISK_ID=$(echo "$RBD_SRC" | $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/DEPLOY_ID \ + /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SOURCE \ + /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CLONE \ + /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]/TYPE ) + +DEPLOY_ID="${XPATH_ELEMENTS[j++]}" +RBD_SRC="${XPATH_ELEMENTS[j++]}" +CLONE="${XPATH_ELEMENTS[j++]}" +CEPH_USER="${XPATH_ELEMENTS[j++]}" +CEPH_KEY="${XPATH_ELEMENTS[j++]}" +CEPH_CONF="${XPATH_ELEMENTS[j++]}" +TYPE="${XPATH_ELEMENTS[j++]}" + + +#------------------------------------------------------------------------------- +# Copy Image back to the datastore +#------------------------------------------------------------------------------- + +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 + +if [ "$RBD_FORMAT" = "2" ]; then + FORMAT_OPT="--image-format 2" +fi + +if [ "$SNAP_ID" != "-1" ]; then + error_message "$script_name: Operation not supported on disk type ${TYPE} with snapshots" + exit 1 +fi + +COPY_CMD=$(cat <&2 + exit 1 + fi + + $RBD import $FORMAT_OPT $SRC_PATH $DST +EOF +) + +ssh_exec_and_log_stdin "$SRC_HOST" "$COPY_CMD" "$CEPH_UTILS" \ + "Error cloning $RBD_DST to $DST in $SRC_HOST" diff --git a/src/tm_mad/ceph/delete b/src/tm_mad/ceph/delete index f0937e9dd6f..fa2033ea9a7 100755 --- a/src/tm_mad/ceph/delete +++ b/src/tm_mad/ceph/delete @@ -115,8 +115,7 @@ 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]/POOL_NAME \ - /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/TYPE ) + /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/POOL_NAME) SRC="${XPATH_ELEMENTS[j++]}" CLONE="${XPATH_ELEMENTS[j++]}" @@ -124,7 +123,6 @@ CEPH_USER="${XPATH_ELEMENTS[j++]}" CEPH_KEY="${XPATH_ELEMENTS[j++]}" CEPH_CONF="${XPATH_ELEMENTS[j++]}" POOL_NAME="${XPATH_ELEMENTS[j++]:-$POOL_NAME}" -TYPE="${XPATH_ELEMENTS[j++]}" # No need to delete no cloned images if [ "$CLONE" = "NO" ]; then @@ -159,24 +157,20 @@ fi log "Deleting $DST_PATH" -if [ "${TYPE}" = 'FILE' ]; then - exit 0 -else - DELETE_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 <&2 + exit 1 + fi + + ${QEMU_IMG} convert ${SRC_PATH} -O qcow2 ${DST_PATH} +fi +EOF +) +else + CPDS_CMD_EXPORT="${QEMU_IMG} convert ${SRC_PATH} -O qcow2 ${DST_PATH}" +fi + +CPDS_CMD=$(cat <&2 + +exit 0 diff --git a/src/tm_mad/shared/mvds b/src/tm_mad/shared/mvds index c8f103aece0..b123e037422 100755 --- a/src/tm_mad/shared/mvds +++ b/src/tm_mad/shared/mvds @@ -24,60 +24,5 @@ # - vmid is the id of the VM # - dsid is the target datastore (0 is the system datastore) -SRC=$1 -DST=$2 - -VMID=$3 -DSID=$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 - -. $TMCOMMON - -DRIVER_PATH=$(dirname $0) - -#------------------------------------------------------------------------------- -# Set dst path and dir -#------------------------------------------------------------------------------- - -SRC_PATH="$(arg_path $SRC)" -SRC_HOST="$(arg_host $SRC)" - -DST_PATH="$(arg_path $DST)" - -#------------------------------------------------------------------------------- -# Get Image information -#------------------------------------------------------------------------------- - -DISK_ID=$(basename ${SRC_PATH} | cut -d. -f2) - -XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin" - -unset i j XPATH_ELEMENTS - -set -x - -while IFS= read -r -d '' element; do - XPATH_ELEMENTS[i++]="$element" -done < <(onevm show -x $VMID| $XPATH \ - /VM/HISTORY_RECORDS/HISTORY[last\(\)]/TM_MAD) - -TM_MAD="${XPATH_ELEMENTS[j++]}" - -#------------------------------------------------------------------------------- -# Move the image back to the datastore -#------------------------------------------------------------------------------- - -if [ "${TM_MAD}" = 'ssh' ]; then - log "Moving $SRC to datastore as $DST" - - ssh_exec_and_log "${SRC_HOST}" \ - "cp -r ${SRC_PATH} ${DST_PATH}" \ - "Error copying ${SRC} to ${DST}" >&2 -fi - +# Nothing to do exit 0 diff --git a/src/vm/VirtualMachineDisk.cc b/src/vm/VirtualMachineDisk.cc index 1374e298cb7..30b230d5a61 100644 --- a/src/vm/VirtualMachineDisk.cc +++ b/src/vm/VirtualMachineDisk.cc @@ -140,7 +140,7 @@ int VirtualMachineDisk::get_image_id(int &id, int uid) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -string VirtualMachineDisk::get_tm_mad_system() +string VirtualMachineDisk::get_tm_mad_system() const { std::string tm_mad_system; diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 2de809b0db2..215d39faa98 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -1094,7 +1094,7 @@ def disk_snapshot_create(id, drv_message) tm_command = ensure_xpath(xml_data, id, action, 'TM_COMMAND') || return tm_command_split = tm_command.split - tm_command_split[0] += '_LIVE' + tm_command_split[0].sub!('.', '_LIVE.') or tm_command_split[0] += '_LIVE' action = VmmAction.new(self, id, :disk_snapshot_create, drv_message)