mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
(cherry picked from commit 3650f75379624f9d1b762a04d5afaf342d5f8469)
This commit is contained in:
parent
54f3bfc5e0
commit
37d27227ec
@ -1 +0,0 @@
|
||||
../ssh/mv
|
106
src/tm_mad/ceph/mv
Executable file
106
src/tm_mad/ceph/mv
Executable file
@ -0,0 +1,106 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2021, 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
# MV <hostA:system_ds/disk.i|hostB:system_ds/disk.i> vmid dsid
|
||||
# <hostA:system_ds/|hostB:system_ds/>
|
||||
# - hostX is the target host to deploy the VM
|
||||
# - system_ds is the path for the system datastore in the host
|
||||
# - 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
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Return if moving a disk, we will move them when moving the whole system_ds
|
||||
# directory for the VM
|
||||
#-------------------------------------------------------------------------------
|
||||
SRC=$(fix_dir_slashes $SRC)
|
||||
DST=$(fix_dir_slashes $DST)
|
||||
|
||||
SRC_PATH=$(arg_path $SRC)
|
||||
DST_PATH=$(arg_path $DST)
|
||||
|
||||
SRC_HOST=$(arg_host $SRC)
|
||||
DST_HOST=$(arg_host $DST)
|
||||
|
||||
SRC_DIR=$(dirname $SRC_PATH)
|
||||
DST_DIR=$(dirname $DST_PATH)
|
||||
|
||||
SRC_DS_DIR=$(dirname $SRC_PATH)
|
||||
SRC_VM_DIR=$(basename $SRC_PATH)
|
||||
|
||||
if [ "$(is_disk $DST_PATH)" -eq 1 ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
#Do not try to move any files in PROLOG_MIGRATE_UNKNOWN (60),
|
||||
#PROLOG_MIGRATE_UNKNOWN_FAILURE (61) or UNKNOWN (16)
|
||||
LCM_STATE=$(lcm_state "$VMID")
|
||||
|
||||
if [[ "$LCM_STATE" =~ ^(16|60|61)$ ]]; then
|
||||
log "Not moving files from $SRC_HOST in FT mode or VM unknown"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# preserve .monitor content (if any)
|
||||
MONITOR_CMD=$(cat <<EOF
|
||||
if [ -r '${SRC_DIR}/.monitor' ]; then
|
||||
cat '${SRC_DIR}/.monitor' 2>/dev/null || :
|
||||
fi
|
||||
EOF
|
||||
)
|
||||
|
||||
MONITOR=$(ssh_monitor_and_log "$SRC_HOST" "$MONITOR_CMD" 'Get .monitor')
|
||||
|
||||
ssh_make_path "$DST_HOST" "$DST_PATH" "$MONITOR"
|
||||
|
||||
RANDOM_FILE=$(ssh "$DST_HOST" "mktemp -p \"$DST_DIR\"")
|
||||
trap "ssh $DST_HOST \"rm -f $RANDOM_FILE\"" EXIT
|
||||
if ssh "$SRC_HOST" "test -f $RANDOM_FILE"; then
|
||||
log "Not moving $SRC to $DST, they are the same path"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
log "Moving $SRC to $DST"
|
||||
|
||||
ssh_exec_and_log "$DST_HOST" "rm -rf '$DST_PATH'" \
|
||||
"Error removing target path to prevent overwrite errors"
|
||||
|
||||
TAR_SSH=$(cat <<EOF
|
||||
set -e -o pipefail
|
||||
|
||||
$TAR -C $SRC_DS_DIR --sparse -cf - $SRC_VM_DIR | $SSH $DST_HOST '$TAR -C $DST_DIR --sparse -xf -'
|
||||
rm -rf $SRC_PATH
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_forward ssh_exec_and_log "$SRC_HOST" "$TAR_SSH" "Error copying disk directory to target host"
|
||||
|
||||
exit 0
|
@ -79,9 +79,11 @@ if [ "$(is_disk "$SRC_PATH")" -eq 1 ]; then
|
||||
DST_DEV="/dev/${DST_VG_NAME}/${LV_NAME}"
|
||||
|
||||
# skip deactivate for `onevm resume` (after stop or undeploy)
|
||||
# or if VM is unknown
|
||||
# 9(49) = PROLOG_RESUME(+FAILURE)
|
||||
# 31(50) = PROLOG_UNDEPLOY(+FAILURE)
|
||||
if ! [[ "$LCM_STATE" =~ ^(9|31|49|50)$ ]]; then
|
||||
# 16 = UNKNOWN
|
||||
if ! [[ "$LCM_STATE" =~ ^(9|16|31|49|50)$ ]]; then
|
||||
# deactivate
|
||||
CMD=$(cat <<EOF
|
||||
set -ex -o pipefail
|
||||
@ -165,5 +167,10 @@ if [ "$SRC_PATH" == "$DST_PATH" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Return if VM is unknown, assume SRC host failure
|
||||
if [[ "$LCM_STATE" = "16" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
ssh_exec_and_log "$DST_HOST" "mv $SRC_PATH $DST_PATH" \
|
||||
"Error moving VM files to another System DS: $SRC_PATH to $DST_PATH in $DST_HOST"
|
||||
|
Loading…
x
Reference in New Issue
Block a user