mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-21 12:22:38 +09:00
Fixed/Extended DS MAD FS snapshot script to work via BRIDGE_LIST on remote hosts
Signed-off-by: Kristian Feldsam <feldsam@gmail.com> Signed-off-by: Vlastimil Holer <vlastimil.holer@gmail.com>
This commit is contained in:
1 parent
06b4c8f838
commit
2836eb9e36
3 files changed
+74
-30
No files matched your search
@@ -20,16 +20,19 @@ DRV_ACTION=$1
|
||||
ID=$2
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
|
||||
DATASTORES=/var/lib/one/datastores
|
||||
LIB_LOCATION=/usr/lib/one
|
||||
else
|
||||
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
|
||||
DATASTORES=$ONE_LOCATION/var/datastores
|
||||
LIB_LOCATION=$ONE_LOCATION/lib
|
||||
fi
|
||||
|
||||
TMCOMMON=$LIB_LOCATION/var/remotes/tm/tm_common.sh
|
||||
DATASTORES=$LIB_LOCATION/var/datastores
|
||||
|
||||
. $TMCOMMON
|
||||
. $LIB_LOCATION/sh/scripts_common.sh
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
source ${DRIVER_PATH}/../libfs.sh
|
||||
|
||||
# -------- Get image and datastore arguments from OpenNebula core ------------
|
||||
|
||||
@@ -42,9 +45,11 @@ unset i j XPATH_ELEMENTS
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <($XPATH /DS_DRIVER_ACTION_DATA/IMAGE/SOURCE \
|
||||
done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/SOURCE \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/TARGET_SNAPSHOT)
|
||||
|
||||
BRIDGE_LIST="${XPATH_ELEMENTS[j++]}"
|
||||
DISK_SRC="${XPATH_ELEMENTS[j++]}"
|
||||
SNAP_ID="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
@@ -55,5 +60,11 @@ SYSTEM_DS_PATH=$(dirname ${SRC_PATH})
|
||||
SNAP_DIR="${DISK_SRC}.snap"
|
||||
SNAP_PATH="${SNAP_DIR}/${SNAP_ID}"
|
||||
|
||||
rm ${SNAP_PATH}
|
||||
|
||||
if [ -n "$BRIDGE_LIST" ]; then
|
||||
log "Delete remote snapshot $SNAP_PATH"
|
||||
DST_HOST=`get_destination_host $ID`
|
||||
ssh_exec_and_log "$DST_HOST" "rm -f $SNAP_PATH" "Error deleting snapshot $SNAP_PATH"
|
||||
else
|
||||
log "Delete local snapshot $SNAP_PATH"
|
||||
rm -f ${SNAP_PATH}
|
||||
fi
|
||||
@@ -20,16 +20,19 @@ DRV_ACTION=$1
|
||||
ID=$2
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
|
||||
DATASTORES=/var/lib/one/datastores
|
||||
LIB_LOCATION=/usr/lib/one
|
||||
else
|
||||
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
|
||||
DATASTORES=$ONE_LOCATION/var/datastores
|
||||
LIB_LOCATION=$ONE_LOCATION/lib
|
||||
fi
|
||||
|
||||
TMCOMMON=$LIB_LOCATION/var/remotes/tm/tm_common.sh
|
||||
DATASTORES=$LIB_LOCATION/var/datastores
|
||||
|
||||
. $TMCOMMON
|
||||
. $LIB_LOCATION/sh/scripts_common.sh
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
source ${DRIVER_PATH}/../libfs.sh
|
||||
|
||||
# -------- Get image and datastore arguments from OpenNebula core ------------
|
||||
|
||||
@@ -42,10 +45,12 @@ unset i j XPATH_ELEMENTS
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <($XPATH /DS_DRIVER_ACTION_DATA/IMAGE/SOURCE \
|
||||
done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/SOURCE \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/TARGET_SNAPSHOT \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TM_MAD )
|
||||
|
||||
BRIDGE_LIST="${XPATH_ELEMENTS[j++]}"
|
||||
DISK_SRC="${XPATH_ELEMENTS[j++]}"
|
||||
SNAP_ID="${XPATH_ELEMENTS[j++]}"
|
||||
TM_MAD="${XPATH_ELEMENTS[j++]}"
|
||||
@@ -60,11 +65,22 @@ DISK_PATH="${DISK_SRC}"
|
||||
SNAP_DIR="${DISK_PATH}.snap"
|
||||
SNAP_PATH="${SNAP_DIR}/${SNAP_ID}"
|
||||
|
||||
if [ "$TM_MAD" = "qcow2" ]; then
|
||||
qemu-img convert -O qcow2 ${SNAP_PATH} ${DISK_PATH}.tmp
|
||||
mv "${DISK_PATH}.tmp" "${DISK_PATH}"
|
||||
if [ -n "$BRIDGE_LIST" ]; then
|
||||
log "Flatten remote image $DISK_ID"
|
||||
DST_HOST=`get_destination_host $ID`
|
||||
if [ "$TM_MAD" = "qcow2" ]; then
|
||||
ssh_exec_and_log "$DST_HOST" "qemu-img convert -O qcow2 $SNAP_PATH $DISK_PATH.tmp; mv -f $DISK_PATH.tmp $DISK_PATH; rm -rf $SNAP_DIR" "Error flattening image $SNAP_PATH to $DISK_PATH"
|
||||
else
|
||||
ssh_exec_and_log "$DST_HOST" "mv -f $SNAP_PATH $DISK_PATH; rm -rf $SNAP_DIR" "Error flattening image $SNAP_PATH to $DISK_PATH"
|
||||
fi
|
||||
else
|
||||
mv ${SNAP_PATH} ${DISK_PATH}
|
||||
fi
|
||||
log "Flatten local image $DISK_ID"
|
||||
if [ "$TM_MAD" = "qcow2" ]; then
|
||||
qemu-img convert -O qcow2 ${SNAP_PATH} ${DISK_PATH}.tmp
|
||||
mv "${DISK_PATH}.tmp" "${DISK_PATH}"
|
||||
else
|
||||
mv ${SNAP_PATH} ${DISK_PATH}
|
||||
fi
|
||||
|
||||
rm -rf ${SNAP_DIR}
|
||||
rm -rf ${SNAP_DIR}
|
||||
fi
|
||||
@@ -20,16 +20,19 @@ DRV_ACTION=$1
|
||||
ID=$2
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
|
||||
DATASTORES=/var/lib/one/datastores
|
||||
LIB_LOCATION=/usr/lib/one
|
||||
else
|
||||
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
|
||||
DATASTORES=$ONE_LOCATION/var/datastores
|
||||
LIB_LOCATION=$ONE_LOCATION/lib
|
||||
fi
|
||||
|
||||
TMCOMMON=$LIB_LOCATION/var/remotes/tm/tm_common.sh
|
||||
DATASTORES=$LIB_LOCATION/var/datastores
|
||||
|
||||
. $TMCOMMON
|
||||
. $LIB_LOCATION/sh/scripts_common.sh
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
source ${DRIVER_PATH}/../libfs.sh
|
||||
|
||||
# -------- Get image and datastore arguments from OpenNebula core ------------
|
||||
|
||||
@@ -42,10 +45,12 @@ unset i j XPATH_ELEMENTS
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <($XPATH /DS_DRIVER_ACTION_DATA/IMAGE/SOURCE \
|
||||
done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/SOURCE \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/TARGET_SNAPSHOT \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TM_MAD )
|
||||
|
||||
BRIDGE_LIST="${XPATH_ELEMENTS[j++]}"
|
||||
DISK_SRC="${XPATH_ELEMENTS[j++]}"
|
||||
SNAP_ID="${XPATH_ELEMENTS[j++]}"
|
||||
TM_MAD="${XPATH_ELEMENTS[j++]}"
|
||||
@@ -57,13 +62,25 @@ SYSTEM_DS_PATH=$(dirname ${SRC_PATH})
|
||||
SNAP_DIR="${DISK_SRC}.snap"
|
||||
SNAP_PATH="${SNAP_DIR}/${SNAP_ID}"
|
||||
|
||||
if [ "$TM_MAD" = "qcow2" ]; then
|
||||
ACTIVE_SNAP_ID=$(ls ${SNAP_DIR} | sort -n | tail -n 1)
|
||||
ACTIVE_SNAP_PATH="${SNAP_DIR}/${ACTIVE_SNAP_ID}"
|
||||
if [ -n "$BRIDGE_LIST" ]; then
|
||||
log "Revert remote snapshot $SNAP_PATH"
|
||||
DST_HOST=`get_destination_host $ID`
|
||||
if [ "$TM_MAD" = "qcow2" ]; then
|
||||
ACTIVE_SNAP_ID=$(ssh_monitor_and_log "$DST_HOST" "ls $SNAP_DIR | grep '^[[:digit:]]*$' | sort -n | tail -n 1" "Get active snapshot id" 2>&1)
|
||||
ACTIVE_SNAP_PATH="${SNAP_DIR}/${ACTIVE_SNAP_ID}"
|
||||
|
||||
rm ${ACTIVE_SNAP_PATH}
|
||||
qemu-img create -f qcow2 -b ${SNAP_PATH} ${ACTIVE_SNAP_PATH}
|
||||
ssh_exec_and_log "$DST_HOST" "rm -f $ACTIVE_SNAP_PATH; qemu-img create -f qcow2 -b $SNAP_PATH $ACTIVE_SNAP_PATH" "Error reverting snapshot to $SNAP_PATH"
|
||||
else
|
||||
ssh_exec_and_log "$DST_HOST" "mv -f $SNAP_PATH $DISK_SRC" "Error reverting snapshot to $SNAP_PATH"
|
||||
fi
|
||||
else
|
||||
mv ${SNAP_PATH} ${DISK_SRC}
|
||||
fi
|
||||
if [ "$TM_MAD" = "qcow2" ]; then
|
||||
ACTIVE_SNAP_ID=$(ls ${SNAP_DIR} | grep '^[[:digit:]]*$' | sort -n | tail -n 1)
|
||||
ACTIVE_SNAP_PATH="${SNAP_DIR}/${ACTIVE_SNAP_ID}"
|
||||
|
||||
rm ${ACTIVE_SNAP_PATH}
|
||||
qemu-img create -f qcow2 -b ${SNAP_PATH} ${ACTIVE_SNAP_PATH}
|
||||
else
|
||||
mv -f ${SNAP_PATH} ${DISK_SRC}
|
||||
fi
|
||||
fi
|
||||
Reference in new issue
Block a user