mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
feature #1112: Use tar for tm_ssh/mv copies. Use iscsi helper functions
This commit is contained in:
parent
c7e6724c96
commit
891a7172b4
@ -22,3 +22,7 @@ VG_NAME=vg-one
|
||||
|
||||
# Starting TID for iSCSI targets
|
||||
BASE_TID=1
|
||||
|
||||
# Lists of hosts (separated by spaces) for which no iscsiadm login or logout
|
||||
# is performed.
|
||||
NO_ISCSI="$HOSTNAME"
|
||||
|
@ -38,6 +38,7 @@ SCP=scp
|
||||
SED=sed
|
||||
SSH=ssh
|
||||
SUDO=sudo
|
||||
TAR=tar
|
||||
TGTADM=tgtadm
|
||||
WGET=wget
|
||||
|
||||
@ -304,3 +305,31 @@ function iscsiadm_logout {
|
||||
echo "$ISCSIADM -m node --targetname $IQN --logout"
|
||||
}
|
||||
|
||||
function is_iscsi {
|
||||
if echo "$NO_ISCSI"|grep -q "\b$1\b"; then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
function iqn_get_lv_name {
|
||||
IQN="$1"
|
||||
TARGET=`echo "$IQN"|$CUT -d: -f2`
|
||||
echo $TARGET|$AWK -F. '{print $(NF)}'
|
||||
}
|
||||
|
||||
function iqn_get_vg_name {
|
||||
IQN="$1"
|
||||
TARGET=`echo "$IQN"|$CUT -d: -f2`
|
||||
echo $TARGET|$AWK -F. '{print $(NF-1)}'
|
||||
}
|
||||
|
||||
function iqn_get_host {
|
||||
IQN="$1"
|
||||
|
||||
LV_NAME=$(iqn_get_lv_name "$IQN")
|
||||
VG_NAME=$(iqn_get_vg_name "$IQN")
|
||||
|
||||
echo ${TARGET%%.$VG_NAME.$LV_NAME}
|
||||
}
|
||||
|
@ -22,8 +22,8 @@
|
||||
# - host is the target host to deploy the VM
|
||||
# - remote_system_ds is the path for the system datastore in the host
|
||||
|
||||
SRC=$1 # iqn.2012-02.org.opennebula:o200.vg-one.lv-one-0
|
||||
DST=$2 # o202:/var/lib/one//datastores/0/0/disk.0
|
||||
SRC=$1
|
||||
DST=$2
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
|
||||
@ -37,19 +37,18 @@ fi
|
||||
# Set dst path and dir
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
TARGET=`arg_path $SRC` # o200.vg-one.lv-one-0
|
||||
DST_PATH=`arg_path $DST` # /var/lib/one/datastores/0/0/disk.0
|
||||
DST_HOST=`arg_host $DST` # o202
|
||||
DST_DIR=`dirname $DST_PATH` # /var/lib/one/datastores/0/0
|
||||
TARGET=`arg_path $SRC`
|
||||
DST_PATH=`arg_path $DST`
|
||||
DST_HOST=`arg_host $DST`
|
||||
DST_DIR=`dirname $DST_PATH`
|
||||
|
||||
BASE_IQN=`echo $SRC|$CUT -d: -f1`
|
||||
TARGET=`echo $SRC|$CUT -d: -f2`
|
||||
LV_NAME=`echo $TARGET|$AWK -F. '{print $(NF)}'`
|
||||
VG_NAME=`echo $TARGET|$AWK -F. '{print $(NF-1)}'`
|
||||
IQN="$SRC"
|
||||
|
||||
LV_NAME=`iqn_get_lv_name "$IQN"`
|
||||
VG_NAME=`iqn_get_vg_name "$IQN"`
|
||||
DEV="/dev/$VG_NAME/$LV_NAME"
|
||||
|
||||
exit
|
||||
ssh_make_path $DST_HOST $DST_DIR
|
||||
ssh_make_path "$DST_HOST" "$DST_DIR"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Copy files to the remote host
|
||||
|
@ -20,7 +20,7 @@
|
||||
# - host is the target host to deploy the VM
|
||||
# - remote_system_ds is the path for the system datastore in the host
|
||||
|
||||
DST=$1 # o202:/var/lib/one//datastores/0/0/disk.0
|
||||
DST=$1
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
|
||||
|
@ -24,6 +24,7 @@
|
||||
SRC=$1
|
||||
DST=$2
|
||||
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
|
||||
else
|
||||
@ -32,6 +33,10 @@ fi
|
||||
|
||||
. $TMCOMMON
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
|
||||
source ${DRIVER_PATH}/../../datastore/iscsi/iscsi.conf
|
||||
|
||||
# {:path=>
|
||||
# "/var/lib/one/remotes/tm/iscsi/mv o202:/var/lib/one//datastores/0/3/disk.0 rama:/var/lib/one/datastores/0/3/disk.0",
|
||||
# :result=>"SUCCESS",
|
||||
@ -47,11 +52,22 @@ fi
|
||||
# directory for the VM
|
||||
#-------------------------------------------------------------------------------
|
||||
SRC_PATH=`arg_path $SRC`
|
||||
DST_PATH=`arg_path $DST`
|
||||
|
||||
SRC_HOST=`arg_host $SRC`
|
||||
DST_HOST=`arg_host $DST`
|
||||
|
||||
DST_DIR=`dirname $DST_PATH`
|
||||
|
||||
if [ `is_disk $SRC_PATH` -eq 0 ]; then
|
||||
log "Removing directory"
|
||||
ssh_exec_and_log "$SRC_HOST" "rm -rf $SRC_PATH"
|
||||
ssh_make_path $DST_HOST $DST_DIR
|
||||
|
||||
log "Moving $SRC to $DST"
|
||||
|
||||
exec_and_log "$SCP -r $SRC $DST" "Could not copy $SRC to $DST"
|
||||
|
||||
ssh_exec_and_log "$SRC_HOST" "rm -rf $SRC_PATH" \
|
||||
"Could not remove $SRC_HOST:$SRC_PATH"
|
||||
|
||||
exit 0
|
||||
fi
|
||||
@ -61,14 +77,50 @@ if [ "$SRC" == "$DST" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
log "Logging out $IQN"
|
||||
if is_iscsi "$SRC_HOST"; then
|
||||
log "Logging out of $IQN in $SRC_HOST"
|
||||
|
||||
LOGOUT_CMD=$(cat <<EOF
|
||||
set -e
|
||||
$SUDO $(iscsiadm_logout "$IQN")
|
||||
LOGOUT_CMD=$(cat <<EOF
|
||||
set -e
|
||||
IQN=\$(readlink $SRC_PATH |grep -o 'iqn.*$')
|
||||
IQN=\${IQN%-lun-1}
|
||||
$SUDO $(iscsiadm_logout "\$IQN")
|
||||
EOF
|
||||
)
|
||||
ssh_exec_and_log "$SRC_HOST" "$LOGOUT_CMD" \
|
||||
"Error logging out $IQN"
|
||||
ssh_exec_and_log "$SRC_HOST" "$LOGOUT_CMD" \
|
||||
"Error logging out $SRC_HOST:$SRC_PATH (IQN)"
|
||||
fi
|
||||
|
||||
if is_iscsi "$DST_HOST"; then
|
||||
log "Logging in to IQN in $SRC_HOST"
|
||||
|
||||
log "Getting IQN from $SRC_HOST:$SRC_PATH"
|
||||
|
||||
IQN=$($SSH "$SRC_HOST" "readlink $SRC_PATH |grep -o 'iqn.*$'" )
|
||||
IQN=${IQN%-lun-1}
|
||||
|
||||
if [ -z "$IQN" ]; then
|
||||
log_error "Error getting IQN"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TARGET_HOST=$(iqn_get_host "$IQN")
|
||||
|
||||
LOGIN_CMD=$(cat <<EOF
|
||||
set -e
|
||||
mkdir -p $DST_DIR
|
||||
$SUDO $(iscsiadm_discovery "$TARGET_HOST")
|
||||
$SUDO $(iscsiadm_discovery "$TARGET_HOST")
|
||||
$SUDO $(iscsiadm_login "$IQN" "$TARGET_HOST")
|
||||
sleep 1
|
||||
DISK_BY_PATH=\$(ls /dev/disk/by-path/*$IQN-lun-1)
|
||||
ln -s "\$DISK_BY_PATH" "$DST_PATH"
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "$DST_HOST" "$LOGIN_CMD" \
|
||||
"Error logging in $IQN"
|
||||
fi
|
||||
|
||||
|
||||
exit 0
|
||||
|
@ -16,8 +16,8 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
# MV <hostA:system_ds/disk.i|hostB:system_ds/disk.i>
|
||||
# <hostA:system_ds/|hostB:system_ds/>
|
||||
# MV <hostA:system_ds/disk.i|hostB:system_ds/disk.i>
|
||||
# <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
|
||||
|
||||
@ -34,7 +34,7 @@ fi
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Return if moving a disk, we will move them when moving the whole system_ds
|
||||
# directory for the VM
|
||||
# directory for the VM
|
||||
#-------------------------------------------------------------------------------
|
||||
SRC_PATH=`arg_path $SRC`
|
||||
DST_PATH=`arg_path $DST`
|
||||
@ -53,11 +53,17 @@ if [ "$SRC" == "$DST" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
ssh_make_path $DST_HOST $DST_DIR
|
||||
ssh_make_path "$DST_HOST" "$DST_DIR"
|
||||
|
||||
log "Moving $SRC to $DST"
|
||||
|
||||
exec_and_log "$SCP -r $SRC $DST" "Could not copy $SRC to $DST"
|
||||
ssh_exec_and_log "$DST_HOST" "rm -rf '$DST_PATH'" \
|
||||
"Error removing target path to prevent overwrite errors"
|
||||
|
||||
TAR_COPY="$SSH $SRC_HOST '$TAR -C $SRC_PATH/.. -cf - .'"
|
||||
TAR_COPY="$TAR_COPY | $SSH $DST_HOST '$TAR -C $DST_DIR -xf -'"
|
||||
|
||||
exec_and_log "eval $TAR_COPY" "Error copying disk directory to target host"
|
||||
|
||||
exec_and_log "$SSH $SRC_HOST rm -rf $SRC_PATH"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user