Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
2 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3650f75
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There were the following issues with your Pull Request
Guidelines are available at https://github.com/OpenNebula/one/blob/master/share/doc/dev/COMMIT_MESSAGES.md
This message was auto-generated by https://gitcop.com
3650f75
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There were the following issues with your Pull Request
Guidelines are available at https://github.com/OpenNebula/one/blob/master/share/doc/dev/COMMIT_MESSAGES.md
This message was auto-generated by https://gitcop.com
3650f75
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There were the following issues with your Pull Request
Guidelines are available at https://github.com/OpenNebula/one/blob/master/share/doc/dev/COMMIT_MESSAGES.md
This message was auto-generated by https://gitcop.com