mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-22 13:33:52 +03:00
parent
ed088ef826
commit
0bef8ee722
@ -1 +1 @@
|
||||
oneadmin ALL=(ALL) NOPASSWD: ONE_CEPH, ONE_HA, ONE_MARKET
|
||||
oneadmin ALL=(ALL) NOPASSWD: ONE_CEPH, ONE_HA, ONE_MARKET, ONE_LVM
|
||||
|
@ -44,68 +44,51 @@ source ${DRIVER_PATH}/../../datastore/libfs.sh
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set dst path and dir
|
||||
#-------------------------------------------------------------------------------
|
||||
SRC_PATH=`arg_path $SRC`
|
||||
SRC_HOST=`arg_host $SRC`
|
||||
SRC_PATH=$(arg_path "$SRC")
|
||||
SRC_HOST=$(arg_host "$SRC")
|
||||
|
||||
DST_PATH=`arg_path $DST`
|
||||
DST_HOST=`arg_host $DST`
|
||||
DST_PATH=$(arg_path "$DST")
|
||||
|
||||
DISK_ID=$(echo $SRC_PATH|$AWK -F. '{print $NF}')
|
||||
DS_SYS_ID=$(echo $SRC_PATH|$AWK -F/ '{print $(NF-2)}')
|
||||
DISK_ID=$(echo "$SRC_PATH"|$AWK -F. '{print $NF}')
|
||||
DS_SYS_ID=$(echo "$SRC_PATH"|$AWK -F/ '{print $(NF-2)}')
|
||||
|
||||
LV_NAME="lv-one-$VM_ID-$DISK_ID"
|
||||
VG_NAME="vg-one-$DS_SYS_ID"
|
||||
|
||||
DEV="/dev/${VG_NAME}/${LV_NAME}"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Get VM information
|
||||
#-------------------------------------------------------------------------------
|
||||
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
|
||||
|
||||
unset i j XPATH_ELEMENTS
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <(onevm show -x $VM_ID| $XPATH \
|
||||
'/VM/LCM_STATE' \
|
||||
'/VM/HISTORY_RECORDS/HISTORY[last()]/HOSTNAME')
|
||||
|
||||
LCM_STATE="${XPATH_ELEMENTS[j++]}"
|
||||
LAST_HOST="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
# Undeployed VM state
|
||||
if [ "$LCM_STATE" = '67' ] || [ "$LCM_STATE" = '68' ]; then
|
||||
if is_undeployed "$VM_ID" "$SRC_HOST"; then
|
||||
|
||||
# get BRIDGE_LIST from datastore
|
||||
IFS= read -r -d '' BRIDGE_LIST < <(onedatastore show -x $DS_SYS_ID \
|
||||
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
|
||||
IFS= read -r -d '' BRIDGE_LIST < <(onedatastore show -x "$DS_SYS_ID" \
|
||||
| $XPATH /DATASTORE/TEMPLATE/BRIDGE_LIST )
|
||||
|
||||
if [ -n "$BRIDGE_LIST" ]; then
|
||||
SRC_HOST=$(get_destination_host)
|
||||
elif [ -n "$LAST_HOST" ]; then
|
||||
SRC_HOST=$LAST_HOST
|
||||
else
|
||||
log_error "Unknown last VM host nor BRIDGE_LIST"
|
||||
exit -1
|
||||
fi
|
||||
ACTIVATE="$SUDO $LVCHANGE -ay "$DEV""
|
||||
DEACTIVATE="$SUDO $LVCHANGE -an "$DEV""
|
||||
#else we assume that FE have access to LVM storage
|
||||
|
||||
DUMP_CMD=$(cat <<EOF
|
||||
set -e -o pipefail
|
||||
$SUDO $LVCHANGE -ay $DEV > /dev/null 2>&1
|
||||
$DD if=$DEV of=$DST_PATH bs=${DD_BLOCK_SIZE:-64k}
|
||||
$SUDO $LVCHANGE -an $DEV > /dev/null 2>&1
|
||||
EOF
|
||||
)
|
||||
else
|
||||
DUMP_CMD=$(cat <<EOF
|
||||
set -e -o pipefail
|
||||
$DD if=$DEV of=$DST_PATH bs=${DD_BLOCK_SIZE:-64k}
|
||||
EOF
|
||||
)
|
||||
fi
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Move the image back to the datastore
|
||||
#-------------------------------------------------------------------------------
|
||||
DUMP_CMD=$(cat <<EOF
|
||||
$ACTIVATE
|
||||
$DD if=$DEV of=$DST_PATH bs=${DD_BLOCK_SIZE:-64k}
|
||||
$DEACTIVATE
|
||||
EOF
|
||||
)
|
||||
|
||||
log "Dumping $SRC to $DST"
|
||||
|
||||
ssh_exec_and_log "$SRC_HOST" "$DUMP_CMD" \
|
||||
"Error dumping $SRC to $DST"
|
||||
ssh_exec_and_log "$SRC_HOST" "$DUMP_CMD" "Error dumping $SRC to $DST"
|
||||
|
||||
exit 0
|
||||
|
@ -41,94 +41,55 @@ source ${DRIVER_PATH}/../../datastore/libfs.sh
|
||||
# Return if deleting a disk, we will delete them when removing the
|
||||
# remote_system_ds directory for the VM (remotely)
|
||||
#-------------------------------------------------------------------------------
|
||||
DST_PATH=`arg_path $DST`
|
||||
DST_HOST=`arg_host $DST`
|
||||
DST_PATH=$(arg_path "$DST")
|
||||
DST_HOST=$(arg_host "$DST")
|
||||
DST_HOST_LVM="$DST_HOST"
|
||||
|
||||
if [ `is_disk $DST_PATH` -eq 1 ]; then
|
||||
DS_SYS_ID=$(echo $DST_PATH | $AWK -F '/' '{print $(NF-2)}')
|
||||
if [ "$(is_disk "$DST_PATH")" -eq 1 ]; then
|
||||
DS_SYS_ID=$(echo "$DST_PATH" | $AWK -F '/' '{print $(NF-2)}')
|
||||
else
|
||||
DS_SYS_ID=$(echo $DST_PATH | $AWK -F '/' '{print $(NF-1)}')
|
||||
DS_SYS_ID=$(echo "$DST_PATH" | $AWK -F '/' '{print $(NF-1)}')
|
||||
fi
|
||||
|
||||
unset i j XPATH_ELEMENTS
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <(onevm show -x $VM_ID | $XPATH \
|
||||
'/VM/HISTORY_RECORDS/HISTORY[last()]/HOSTNAME')
|
||||
if is_undeployed "$VM_ID" "$DST_HOST"; then
|
||||
|
||||
LAST_HOST="${XPATH_ELEMENTS[j++]}"
|
||||
# get BRIDGE_LIST from datastore
|
||||
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
|
||||
IFS= read -r -d '' BRIDGE_LIST < <(onedatastore show -x "$DS_SYS_ID" \
|
||||
| $XPATH /DATASTORE/TEMPLATE/BRIDGE_LIST )
|
||||
|
||||
|
||||
# Change DST_HOST to one of the BRIDGE_LIST to prevent
|
||||
# running on frontend for undeployed VMs
|
||||
if [ "$LAST_HOST" != "$DST_HOST" ]; then
|
||||
unset i j XPATH_ELEMENTS
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <(onedatastore show -x $DS_SYS_ID | $XPATH \
|
||||
/DATASTORE/TEMPLATE/BRIDGE_LIST)
|
||||
|
||||
BRIDGE_LIST="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
if [ -n "$BRIDGE_LIST" ]; then
|
||||
DST_HOST=$(get_destination_host)
|
||||
if [ -n "$BRIDGE_LIST" ]; then # If BRIDGE_LIST is not defined FE must have access to LVM cluster
|
||||
DST_HOST_LVM=$(get_destination_host)
|
||||
fi
|
||||
fi
|
||||
|
||||
# Activate device
|
||||
ACTIVATE_CMD=$(cat <<EOF
|
||||
set -ex -o pipefail
|
||||
if [ -L "$DST_PATH" ]; then
|
||||
DEV=\$(readlink $DST_PATH)
|
||||
if echo "\$DEV" | grep "^/dev/" &>/dev/null; then
|
||||
# Get DEV
|
||||
DEV=$($SSH "$DST_HOST" "readlink $DST_PATH 2> /dev/null | grep \"^/dev/\"")
|
||||
|
||||
if [ -n "$DEV" ]; then
|
||||
|
||||
if [ "${ZERO_LVM_ON_DELETE}" = "yes" ]; then
|
||||
# Activate device
|
||||
ACTIVATE_CMD=$(cat <<EOF
|
||||
set -ex -o pipefail
|
||||
${SYNC}
|
||||
${SUDO} ${LVSCAN}
|
||||
${SUDO} ${LVCHANGE} -ay "\${DEV}"
|
||||
fi
|
||||
fi
|
||||
${SUDO} ${LVCHANGE} -ay "${DEV}"
|
||||
EOF
|
||||
)
|
||||
LOCK="tm-fs_lvm-${DS_SYS_ID}.lock"
|
||||
exclusive "${LOCK}" 120 ssh_exec_and_log "$DST_HOST_LVM" "$ACTIVATE_CMD" \
|
||||
"Error activating disk $SRC_PATH"
|
||||
|
||||
# Zero space
|
||||
ZERO_CMD=$(cat <<EOF
|
||||
set -ex -o pipefail
|
||||
if [ -L "$DST_PATH" ]; then
|
||||
DEV=\$(readlink $DST_PATH)
|
||||
if echo "\$DEV" | grep "^/dev/" &>/dev/null; then
|
||||
${DD} if=/dev/zero of="\${DEV}" bs=${DD_BLOCK_SIZE:-64k} || :
|
||||
fi
|
||||
fi
|
||||
EOF
|
||||
)
|
||||
|
||||
# Delete the device if it's a clone (LVM snapshot)
|
||||
DELETE_CMD=$(cat <<EOF
|
||||
set -ex -o pipefail
|
||||
|
||||
if [ -d "$DST_PATH" ]; then
|
||||
rm -rf "$DST_PATH"
|
||||
exit 0
|
||||
# It's separeted from ACTIVATE_CMD to avoid blocking while writing in the device
|
||||
ssh_exec_and_log_no_error "$DST_HOST_LVM" "${DD} if=/dev/zero of=\"${DEV}\" bs=${DD_BLOCK_SIZE:-64k}" \
|
||||
"Error cleaning $DST_PATH"
|
||||
fi
|
||||
|
||||
if [ -L "$DST_PATH" ]; then
|
||||
DEV=\$(readlink $DST_PATH)
|
||||
if echo "\$DEV" | grep "^/dev/" &>/dev/null; then
|
||||
$SUDO $LVREMOVE -f "\$DEV"
|
||||
fi
|
||||
fi
|
||||
|
||||
rm -f "$DST_PATH"
|
||||
EOF
|
||||
)
|
||||
|
||||
if [ "${ZERO_LVM_ON_DELETE}" = "yes" ]; then
|
||||
LOCK="tm-fs_lvm-${DS_SYS_ID}.lock"
|
||||
exclusive "${LOCK}" 120 ssh_exec_and_log "$DST_HOST" "$ACTIVATE_CMD" \
|
||||
"Error activating disk $SRC_PATH"
|
||||
|
||||
ssh_exec_and_log "$DST_HOST" "$ZERO_CMD" "Error cleaning $DST_PATH"
|
||||
exclusive "${LOCK}" 120 ssh_exec_and_log "$DST_HOST_LVM" "$SUDO $LVREMOVE -f \"$DEV\"" \
|
||||
"Error deleting $DST_PATH"
|
||||
fi
|
||||
|
||||
LOCK="tm-fs_lvm-${DS_SYS_ID}.lock"
|
||||
exclusive "${LOCK}" 120 ssh_exec_and_log "$DST_HOST" "$DELETE_CMD" \
|
||||
"Error deleting $DST_PATH"
|
||||
ssh_exec_and_log "$DST_HOST" "rm -rf \"$DST_PATH\"" \
|
||||
"Error removing \"$DST_PATH\" from $DST_HOST"
|
||||
|
@ -47,39 +47,30 @@ source ${DRIVER_PATH}/../../etc/tm/fs_lvm/fs_lvm.conf
|
||||
|
||||
#--------------------------------------------------------------------------------
|
||||
|
||||
SRC=`fix_dir_slashes $SRC`
|
||||
DST=`fix_dir_slashes $DST`
|
||||
SRC=$(fix_dir_slashes "$SRC")
|
||||
DST=$(fix_dir_slashes "$DST")
|
||||
|
||||
SRC_PATH=`arg_path $SRC`
|
||||
DST_PATH=`arg_path $DST`
|
||||
SRC_PATH=$(arg_path "$SRC")
|
||||
DST_PATH=$(arg_path "$DST")
|
||||
|
||||
SRC_HOST=`arg_host $SRC`
|
||||
DST_HOST=`arg_host $DST`
|
||||
SRC_HOST=$(arg_host "$SRC")
|
||||
DST_HOST=$(arg_host "$DST")
|
||||
|
||||
SRC_DIR=`dirname $SRC_PATH`
|
||||
DST_DIR=`dirname $DST_PATH`
|
||||
SRC_DIR=$(dirname "$SRC_PATH")
|
||||
DST_DIR=$(dirname "$DST_PATH")
|
||||
|
||||
# Activate the disk in the target host
|
||||
if [ `is_disk $SRC_PATH` -eq 1 ]; then
|
||||
if [ "$(is_disk "$SRC_PATH")" -eq 1 ]; then
|
||||
#---------------------------------------------------------------------------
|
||||
# Get Image information
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
SRC_DS_SYS_ID=$(echo $SRC_DIR | $AWK -F '/' '{print $(NF-1)}')
|
||||
DST_DS_SYS_ID=$(echo $DST_DIR | $AWK -F '/' '{print $(NF-1)}')
|
||||
SRC_DS_SYS_ID=$(echo "$SRC_DIR" | $AWK -F '/' '{print $(NF-1)}')
|
||||
DST_DS_SYS_ID=$(echo "$DST_DIR" | $AWK -F '/' '{print $(NF-1)}')
|
||||
|
||||
DISK_ID=${SRC_PATH##*.}
|
||||
|
||||
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
|
||||
|
||||
unset i j XPATH_ELEMENTS
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <(onevm show -x $VMID | $XPATH \
|
||||
/VM/LCM_STATE )
|
||||
|
||||
LCM_STATE="${XPATH_ELEMENTS[j++]}"
|
||||
LCM_STATE=$(lcm_state "$VMID")
|
||||
|
||||
LV_NAME="lv-one-${VMID}-${DISK_ID}"
|
||||
SRC_VG_NAME="vg-one-${SRC_DS_SYS_ID}"
|
||||
|
@ -35,32 +35,59 @@ fi
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
|
||||
source ${DRIVER_PATH}/../../etc/tm/fs_lvm/fs_lvm.conf
|
||||
|
||||
source $TMCOMMON
|
||||
source ${DRIVER_PATH}/../../etc/tm/fs_lvm/fs_lvm.conf
|
||||
source ${DRIVER_PATH}/../../datastore/libfs.sh
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set dst path and dir
|
||||
#-------------------------------------------------------------------------------
|
||||
SRC_PATH=`arg_path $SRC`
|
||||
SRC_HOST=`arg_host $SRC`
|
||||
SRC_PATH=$(arg_path "$SRC")
|
||||
SRC_HOST=$(arg_host "$SRC")
|
||||
|
||||
DST_PATH=`arg_path $DST`
|
||||
DST_HOST=`arg_host $DST`
|
||||
DST_PATH=$(arg_path "$DST")
|
||||
|
||||
DISK_ID=$(echo $SRC_PATH|$AWK -F. '{print $NF}')
|
||||
DS_SYS_ID=$(echo $SRC_PATH|$AWK -F/ '{print $(NF-2)}')
|
||||
DISK_ID=$(echo "$SRC_PATH"|$AWK -F. '{print $NF}')
|
||||
DS_SYS_ID=$(echo "$SRC_PATH"|$AWK -F/ '{print $(NF-2)}')
|
||||
|
||||
LV_NAME="lv-one-$VM_ID-$DISK_ID"
|
||||
VG_NAME="vg-one-$DS_SYS_ID"
|
||||
|
||||
DEV="/dev/${VG_NAME}/${LV_NAME}"
|
||||
|
||||
DUMP_CMD=$(cat <<EOF
|
||||
set -e -o pipefail
|
||||
$DD if=$DEV of=$DST_PATH bs=${DD_BLOCK_SIZE:-64k}
|
||||
if is_undeployed "$VM_ID" "$SRC_HOST"; then
|
||||
|
||||
# get BRIDGE_LIST from datastore
|
||||
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
|
||||
IFS= read -r -d '' BRIDGE_LIST < <(onedatastore show -x "$DS_SYS_ID" \
|
||||
| $XPATH /DATASTORE/TEMPLATE/BRIDGE_LIST )
|
||||
|
||||
if [ -n "$BRIDGE_LIST" ]; then
|
||||
SRC_HOST=$(get_destination_host)
|
||||
fi
|
||||
# we assume that FE have access to LVM storage
|
||||
|
||||
DUMP_CMD=$(cat <<EOF
|
||||
set -e -o pipefail
|
||||
$SUDO $LVCHANGE -ay $DEV > /dev/null 2>&1
|
||||
$DD if=$DEV of=$DST_PATH bs=${DD_BLOCK_SIZE:-64k}
|
||||
$SUDO $LVCHANGE -an $DEV > /dev/null 2>&1
|
||||
EOF
|
||||
)
|
||||
else
|
||||
DUMP_CMD=$(cat <<EOF
|
||||
set -e -o pipefail
|
||||
$DD if=$DEV of=$DST_PATH bs=${DD_BLOCK_SIZE:-64k}
|
||||
EOF
|
||||
)
|
||||
fi
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Move the image back to the datastore
|
||||
#-------------------------------------------------------------------------------
|
||||
log "Dumping $SRC to $DST"
|
||||
|
||||
ssh_exec_and_log "$SRC_HOST" "$DUMP_CMD" "Error dumping $SRC to $DST"
|
||||
|
||||
DELETE_CMD=$(cat <<EOF
|
||||
set -e -o pipefail
|
||||
@ -68,14 +95,6 @@ DELETE_CMD=$(cat <<EOF
|
||||
EOF
|
||||
)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Move the image back to the datastore
|
||||
#-------------------------------------------------------------------------------
|
||||
log "Dumping $SRC to $DST"
|
||||
|
||||
ssh_exec_and_log "$SRC_HOST" "$DUMP_CMD" \
|
||||
"Error dumping $SRC to $DST"
|
||||
|
||||
LOCK="tm-fs_lvm-${DS_SYS_ID}.lock"
|
||||
exclusive "${LOCK}" 120 ssh_exec_and_log "$SRC_HOST" "$DELETE_CMD" \
|
||||
"Error dumping $SRC to $DST"
|
||||
|
@ -42,14 +42,13 @@ source ${DRIVER_PATH}/../../etc/tm/fs_lvm/fs_lvm.conf
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set dst path and dir
|
||||
#-------------------------------------------------------------------------------
|
||||
SRC_PATH=`arg_path $SRC`
|
||||
SRC_HOST=`arg_host $SRC`
|
||||
SRC_PATH=$(arg_path "$SRC")
|
||||
SRC_HOST=$(arg_host "$SRC")
|
||||
|
||||
DST_PATH=`arg_path $DST`
|
||||
DST_HOST=`arg_host $DST`
|
||||
DST_PATH=$(arg_path "$DST")
|
||||
|
||||
DISK_ID=$(echo $SRC_PATH|$AWK -F. '{print $NF}')
|
||||
DS_SYS_ID=$(echo $SRC_PATH|$AWK -F/ '{print $(NF-2)}')
|
||||
DISK_ID=$(echo "$SRC_PATH"|$AWK -F. '{print $NF}')
|
||||
DS_SYS_ID=$(echo "$SRC_PATH"|$AWK -F/ '{print $(NF-2)}')
|
||||
|
||||
LV_NAME="lv-one-$VM_ID-$DISK_ID"
|
||||
VG_NAME="vg-one-$DS_SYS_ID"
|
||||
@ -59,34 +58,19 @@ DEV="/dev/${VG_NAME}/${LV_NAME}"
|
||||
#-------------------------------------------------------------------------------
|
||||
# Get VM information
|
||||
#-------------------------------------------------------------------------------
|
||||
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
|
||||
|
||||
unset i j XPATH_ELEMENTS
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <(onevm show -x $VM_ID| $XPATH \
|
||||
'/VM/LCM_STATE' \
|
||||
'/VM/HISTORY_RECORDS/HISTORY[last()]/HOSTNAME')
|
||||
|
||||
LCM_STATE="${XPATH_ELEMENTS[j++]}"
|
||||
LAST_HOST="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
# HOTPLUG_SAVEAS_UNDEPLOYED || HOTPLUG_SAVEAS_STOPPED (i.e VM not present in HV node)
|
||||
if [ "$LCM_STATE" = '67' ] || [ "$LCM_STATE" = '68' ]; then
|
||||
if is_undeployed "$VM_ID" "$SRC_HOST"; then
|
||||
|
||||
# get BRIDGE_LIST from datastore
|
||||
IFS= read -r -d '' BRIDGE_LIST < <(onedatastore show -x $DS_SYS_ID \
|
||||
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
|
||||
IFS= read -r -d '' BRIDGE_LIST < <(onedatastore show -x "$DS_SYS_ID" \
|
||||
| $XPATH /DATASTORE/TEMPLATE/BRIDGE_LIST )
|
||||
|
||||
if [ -n "$BRIDGE_LIST" ]; then
|
||||
SRC_HOST=$(get_destination_host)
|
||||
elif [ -n "$LAST_HOST" ]; then
|
||||
SRC_HOST=$LAST_HOST
|
||||
else
|
||||
log_error "Unknown last VM host nor BRIDGE_LIST"
|
||||
exit -1
|
||||
fi
|
||||
# else we assume that FE have access to LVM storage
|
||||
|
||||
ACTIVATE="$SUDO $LVCHANGE -ay $DEV > /dev/null 2>&1"
|
||||
DEACTIVATE="$SUDO $LVCHANGE -an $DEV > /dev/null 2>&1"
|
||||
fi
|
||||
@ -97,31 +81,20 @@ fi
|
||||
|
||||
log "Dumping $SRC to $DST"
|
||||
|
||||
# Copy from possibly remote host to possible remote host
|
||||
if [ "$(fix_dir_slashes $DST_HOST)" != "$DST_PATH" ]; then
|
||||
# TODO, this branch is not used. Remove it or leave just in case?
|
||||
if [ -n "$ACTIVATE" ]; then
|
||||
DUMP_CMD=$(cat <<EOF
|
||||
set -e -o pipefail
|
||||
$ACTIVATE
|
||||
$DD if=\"$DEV\" bs=${DD_BLOCK_SIZE:-64k} conv=sparse | $SSH "$DST_HOST" "cat - > $DST_PATH"
|
||||
$DEACTIVATE
|
||||
|
||||
EOF
|
||||
)
|
||||
ssh_forward ssh_exec_and_log "$SRC_HOST" "$DUMP_CMD" "Error dumping $SRC to $DST"
|
||||
else # Copy from possibly remote host to local
|
||||
DUMP_CMD=$(cat <<EOF
|
||||
|
||||
if [ -n "$ACTIVATE" ]; then
|
||||
$SSH "$SRC_HOST" "$ACTIVATE; $DD if=\"$DEV\" bs=${DD_BLOCK_SIZE:-64k} conv=sparse; $DEACTIVATE" | \
|
||||
$SSH "$SRC_HOST" "$ACTIVATE; $DD if=\"$DEV\" bs=${DD_BLOCK_SIZE:-64k} conv=sparse; $DEACTIVATE" | \
|
||||
cat - > "$DST_PATH"
|
||||
else
|
||||
$SSH "$SRC_HOST" "$DD if=\"$DEV\" bs=${DD_BLOCK_SIZE:-64k} conv=sparse" | cat - > "$DST_PATH"
|
||||
fi
|
||||
EOF
|
||||
)
|
||||
|
||||
multiline_exec_and_log "$DUMP_CMD" "Error dumping $SRC to $DST"
|
||||
else
|
||||
DUMP_CMD=$(cat <<EOF
|
||||
$SSH "$SRC_HOST" "$DD if=\"$DEV\" bs=${DD_BLOCK_SIZE:-64k} conv=sparse" | cat - > "$DST_PATH"
|
||||
EOF
|
||||
)
|
||||
fi
|
||||
|
||||
|
||||
multiline_exec_and_log "$DUMP_CMD" "Error dumping $SRC to $DST"
|
||||
|
||||
exit 0
|
||||
|
@ -47,39 +47,30 @@ source ${DRIVER_PATH}/../../etc/tm/fs_lvm/fs_lvm.conf
|
||||
|
||||
#--------------------------------------------------------------------------------
|
||||
|
||||
SRC=`fix_dir_slashes $SRC`
|
||||
DST=`fix_dir_slashes $DST`
|
||||
SRC=$(fix_dir_slashes "$SRC")
|
||||
DST=$(fix_dir_slashes "$DST")
|
||||
|
||||
SRC_PATH=`arg_path $SRC`
|
||||
DST_PATH=`arg_path $DST`
|
||||
SRC_PATH=$(arg_path "$SRC")
|
||||
DST_PATH=$(arg_path "$DST")
|
||||
|
||||
SRC_HOST=`arg_host $SRC`
|
||||
DST_HOST=`arg_host $DST`
|
||||
SRC_HOST=$(arg_host "$SRC")
|
||||
DST_HOST=$(arg_host "$DST")
|
||||
|
||||
SRC_DIR=`dirname $SRC_PATH`
|
||||
DST_DIR=`dirname $DST_PATH`
|
||||
SRC_DIR=$(dirname "$SRC_PATH")
|
||||
DST_DIR=$(dirname "$DST_PATH")
|
||||
|
||||
# Activate the disk in the target host
|
||||
if [ `is_disk $SRC_PATH` -eq 1 ]; then
|
||||
if [ "$(is_disk "$SRC_PATH")" -eq 1 ]; then
|
||||
#---------------------------------------------------------------------------
|
||||
# Get Image information
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
SRC_DS_SYS_ID=$(echo $SRC_DIR | $AWK -F '/' '{print $(NF-1)}')
|
||||
DST_DS_SYS_ID=$(echo $DST_DIR | $AWK -F '/' '{print $(NF-1)}')
|
||||
SRC_DS_SYS_ID=$(echo "$SRC_DIR" | $AWK -F '/' '{print $(NF-1)}')
|
||||
DST_DS_SYS_ID=$(echo "$DST_DIR" | $AWK -F '/' '{print $(NF-1)}')
|
||||
|
||||
DISK_ID=${SRC_PATH##*.}
|
||||
|
||||
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
|
||||
|
||||
unset i j XPATH_ELEMENTS
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <(onevm show -x $VMID | $XPATH \
|
||||
/VM/LCM_STATE )
|
||||
|
||||
LCM_STATE="${XPATH_ELEMENTS[j++]}"
|
||||
LCM_STATE=$(lcm_state "$VMID")
|
||||
|
||||
LV_NAME="lv-one-${VMID}-${DISK_ID}"
|
||||
SRC_VG_NAME="vg-one-${SRC_DS_SYS_ID}"
|
||||
@ -112,6 +103,8 @@ EOF
|
||||
# 10(41) = EPILOG_STOP(+FAILURE)
|
||||
# 30(42) = EPILOG_UNDEPLOY(+FAILURE)
|
||||
if [[ "$LCM_STATE" =~ ^(10|30|41|42)$ ]]; then
|
||||
# After managing LV deactivation on hosts, transfer normal files
|
||||
"$(dirname "$0")"/../ssh/mv "$@"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
@ -168,4 +161,4 @@ EOF
|
||||
fi
|
||||
|
||||
# After managing LV de/activation on different hosts, transfer normal files
|
||||
$(dirname "$0")/../ssh/mv "$@"
|
||||
"$(dirname "$0")"/../ssh/mv "$@"
|
||||
|
@ -35,57 +35,62 @@ fi
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
|
||||
source ${DRIVER_PATH}/../../etc/tm/fs_lvm/fs_lvm.conf
|
||||
source ${DRIVER_PATH}/../../datastore/libfs.sh
|
||||
|
||||
source $TMCOMMON
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set dst path and dir
|
||||
#-------------------------------------------------------------------------------
|
||||
SRC_PATH=`arg_path $SRC`
|
||||
SRC_HOST=`arg_host $SRC`
|
||||
SRC_PATH=$(arg_path "$SRC")
|
||||
SRC_HOST=$(arg_host "$SRC")
|
||||
|
||||
DST_PATH=`arg_path $DST`
|
||||
DST_HOST=`arg_host $DST`
|
||||
DST_PATH=$(arg_path "$DST")
|
||||
|
||||
DISK_ID=$(echo $SRC_PATH|$AWK -F. '{print $NF}')
|
||||
DS_SYS_ID=$(echo $SRC_PATH|$AWK -F/ '{print $(NF-2)}')
|
||||
DISK_ID=$(echo "$SRC_PATH"|$AWK -F. '{print $NF}')
|
||||
DS_SYS_ID=$(echo "$SRC_PATH"|$AWK -F/ '{print $(NF-2)}')
|
||||
|
||||
LV_NAME="lv-one-$VM_ID-$DISK_ID"
|
||||
VG_NAME="vg-one-$DS_SYS_ID"
|
||||
|
||||
DEV="/dev/${VG_NAME}/${LV_NAME}"
|
||||
|
||||
if is_undeployed "$VM_ID" "$SRC_HOST"; then
|
||||
|
||||
# get BRIDGE_LIST from datastore
|
||||
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
|
||||
IFS= read -r -d '' BRIDGE_LIST < <(onedatastore show -x "$DS_SYS_ID" \
|
||||
| $XPATH /DATASTORE/TEMPLATE/BRIDGE_LIST )
|
||||
|
||||
if [ -n "$BRIDGE_LIST" ]; then
|
||||
SRC_HOST=$(get_destination_host)
|
||||
fi
|
||||
# else we assume that FE have access to LVM storage
|
||||
|
||||
ACTIVATE="$SUDO $LVCHANGE -ay $DEV > /dev/null 2>&1"
|
||||
DEACTIVATE="$SUDO $LVCHANGE -an $DEV > /dev/null 2>&1"
|
||||
fi
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Move the image back to the datastore
|
||||
#-------------------------------------------------------------------------------
|
||||
log "Dumping $SRC to $DST"
|
||||
|
||||
# Copy from possibly remote host to possible remote host
|
||||
if [ "$(fix_dir_slashes $DST_HOST)" != "$DST_PATH" ]; then
|
||||
|
||||
if [ -n "$ACTIVATE" ]; then
|
||||
DUMP_CMD=$(cat <<EOF
|
||||
set -e -o pipefail
|
||||
$ACTIVATE
|
||||
$DD if=\"$DEV\" bs=${DD_BLOCK_SIZE:-64k} conv=sparse | $SSH "$DST_HOST" "cat - > $DST_PATH"
|
||||
$DEACTIVATE
|
||||
EOF
|
||||
)
|
||||
ssh_forward ssh_exec_and_log "$SRC_HOST" "$DUMP_CMD" "Error dumping $SRC to $DST"
|
||||
else # Copy from possibly remote host to local
|
||||
DUMP_CMD=$(cat <<EOF
|
||||
set -e -o pipefail
|
||||
|
||||
if [ -n "$ACTIVATE" ]; then
|
||||
$SSH "$SRC_HOST" "$ACTIVATE; $DD if=\"$DEV\" bs=${DD_BLOCK_SIZE:-64k} conv=sparse; $DEACTIVATE" | \
|
||||
$SSH "$SRC_HOST" "$ACTIVATE; $DD if=\"$DEV\" bs=${DD_BLOCK_SIZE:-64k} conv=sparse; $DEACTIVATE" | \
|
||||
cat - > "$DST_PATH"
|
||||
else
|
||||
$SSH "$SRC_HOST" "$DD if=\"$DEV\" bs=${DD_BLOCK_SIZE:-64k} conv=sparse" | cat - > "$DST_PATH"
|
||||
fi
|
||||
EOF
|
||||
)
|
||||
multiline_exec_and_log "$DUMP_CMD" "Error dumping $SRC to $DST"
|
||||
else
|
||||
DUMP_CMD=$(cat <<EOF
|
||||
$SSH "$SRC_HOST" "$DD if=\"$DEV\" bs=${DD_BLOCK_SIZE:-64k} conv=sparse" | cat - > "$DST_PATH"
|
||||
EOF
|
||||
)
|
||||
fi
|
||||
|
||||
multiline_exec_and_log "$DUMP_CMD" "Error dumping $SRC to $DST"
|
||||
|
||||
DELETE_CMD=$(cat <<EOF
|
||||
set -e -o pipefail
|
||||
$SUDO $LVREMOVE -f $DEV
|
||||
@ -94,6 +99,6 @@ EOF
|
||||
|
||||
LOCK="tm-fs_lvm-${DS_SYS_ID}.lock"
|
||||
exclusive "${LOCK}" 120 ssh_exec_and_log "$SRC_HOST" "$DELETE_CMD" \
|
||||
"Error removing $DEV"
|
||||
"Error dumping $SRC to $DST"
|
||||
|
||||
exit 0
|
||||
|
@ -117,6 +117,29 @@ function lcm_state
|
||||
echo $LCM_STATE
|
||||
}
|
||||
|
||||
# Check if the VM is undeployed/stopped
|
||||
|
||||
function is_undeployed
|
||||
{
|
||||
XPATH="${ONE_LOCAL_VAR}/remotes/datastore/xpath.rb --stdin"
|
||||
|
||||
unset i XPATH_ELEMENTS
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <(onevm show -x "${1:-$VMID}" | $XPATH \
|
||||
'/VM/HISTORY_RECORDS/HISTORY[last()]/HOSTNAME' )
|
||||
|
||||
LAST_HOST="${XPATH_ELEMENTS[0]}"
|
||||
CURRENT_HOST="$2"
|
||||
|
||||
if [ "$LAST_HOST" != "$CURRENT_HOST" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
function migrate_other
|
||||
{
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user