diff --git a/src/datastore_mad/remotes/iscsi/iscsi.conf b/src/datastore_mad/remotes/iscsi/iscsi.conf index ec117b652f..2938398891 100644 --- a/src/datastore_mad/remotes/iscsi/iscsi.conf +++ b/src/datastore_mad/remotes/iscsi/iscsi.conf @@ -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" diff --git a/src/mad/sh/scripts_common.sh b/src/mad/sh/scripts_common.sh index 204b87eb38..d499d6db1d 100755 --- a/src/mad/sh/scripts_common.sh +++ b/src/mad/sh/scripts_common.sh @@ -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} +} diff --git a/src/tm_mad/iscsi/clone b/src/tm_mad/iscsi/clone index 39edcbe028..cf172ed818 100755 --- a/src/tm_mad/iscsi/clone +++ b/src/tm_mad/iscsi/clone @@ -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 diff --git a/src/tm_mad/iscsi/delete b/src/tm_mad/iscsi/delete index c30639d900..fb4a4fbd0c 100755 --- a/src/tm_mad/iscsi/delete +++ b/src/tm_mad/iscsi/delete @@ -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 diff --git a/src/tm_mad/iscsi/mv b/src/tm_mad/iscsi/mv index d564daf8c9..38005f85b4 100755 --- a/src/tm_mad/iscsi/mv +++ b/src/tm_mad/iscsi/mv @@ -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 < -# +# MV +# # - 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"