3
# -------------------------------------------------------------------------- #
4
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
6
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
7
# not use this file except in compliance with the License. You may obtain #
8
# a copy of the License at #
10
# http://www.apache.org/licenses/LICENSE-2.0 #
12
# Unless required by applicable law or agreed to in writing, software #
13
# distributed under the License is distributed on an "AS IS" BASIS, #
14
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
15
# See the License for the specific language governing permissions and #
16
# limitations under the License. #
17
#--------------------------------------------------------------------------- #
19
# MV <hostA:system_ds/disk.i|hostB:system_ds/disk.i>
20
# <hostA:system_ds/|hostB:system_ds/>
21
# - hostX is the target host to deploy the VM
22
# - system_ds is the path for the system datastore in the host
27
if [ -z "${ONE_LOCATION}" ]; then
28
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
30
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
35
DRIVER_PATH=$(dirname $0)
37
source ${DRIVER_PATH}/../../datastore/iscsi/iscsi.conf
39
#-------------------------------------------------------------------------------
40
# Return if moving a disk, we will move them when moving the whole system_ds
41
# directory for the VM
42
#-------------------------------------------------------------------------------
43
SRC_PATH=`arg_path $SRC`
44
DST_PATH=`arg_path $DST`
46
SRC_HOST=`arg_host $SRC`
47
DST_HOST=`arg_host $DST`
49
DST_DIR=`dirname $DST_PATH`
51
if [ `is_disk $SRC_PATH` -eq 0 ]; then
52
ssh_make_path $DST_HOST $DST_DIR
54
log "Moving $SRC to $DST"
56
exec_and_log "$SCP -r $SRC $DST" "Could not copy $SRC to $DST"
58
ssh_exec_and_log "$SRC_HOST" "rm -rf $SRC_PATH" \
59
"Could not remove $SRC_HOST:$SRC_PATH"
64
if [ "$SRC" == "$DST" ]; then
65
log "Not moving $SRC to $DST, they are the same path"
69
if is_iscsi "$SRC_HOST"; then
70
log "Logging out of $IQN in $SRC_HOST"
72
LOGOUT_CMD=$(cat <<EOF
74
IQN=\$(readlink $SRC_PATH |grep -o 'iqn.*$')
76
$SUDO $(iscsiadm_logout "\$IQN")
79
ssh_exec_and_log "$SRC_HOST" "$LOGOUT_CMD" \
80
"Error logging out $SRC_HOST:$SRC_PATH (IQN)"
83
if is_iscsi "$DST_HOST"; then
84
log "Logging in to IQN in $SRC_HOST"
86
log "Getting IQN from $SRC_HOST:$SRC_PATH"
88
IQN=$($SSH "$SRC_HOST" "readlink $SRC_PATH |grep -o 'iqn.*$'" )
91
if [ -z "$IQN" ]; then
92
log_error "Error getting IQN"
96
TARGET_HOST=$(iqn_get_host "$IQN")
101
$SUDO $(iscsiadm_discovery "$TARGET_HOST")
102
$SUDO $(iscsiadm_login "$IQN" "$TARGET_HOST")
104
DISK_BY_PATH=\$(ls /dev/disk/by-path/*$IQN-lun-1)
105
ln -sf "\$DISK_BY_PATH" "$DST_PATH"
109
ssh_exec_and_log "$DST_HOST" "$LOGIN_CMD" \
110
"Error logging in $IQN"