mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-07 17:17:41 +03:00
feature #1727: add clone resize to ssh, shared and qcow2
This commit is contained in:
parent
eca7640da1
commit
66b83c0f75
@ -38,6 +38,8 @@ fi
|
||||
|
||||
. $TMCOMMON
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set dst path and dir
|
||||
#-------------------------------------------------------------------------------
|
||||
@ -52,6 +54,26 @@ SRC_DS_PATH="$(dirname $(dirname $SRC_ARG_PATH))"
|
||||
|
||||
SRC_PATH="${DST_DS_PATH}${SRC_ARG_PATH##$SRC_DS_PATH}"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Get Image information
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
DISK_ID=$(basename ${DST_PATH} | cut -d. -f2)
|
||||
|
||||
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/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SIZE \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/ORIGINAL_SIZE)
|
||||
|
||||
SIZE="${XPATH_ELEMENTS[j++]}"
|
||||
ORIGINAL_SIZE="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
|
||||
ssh_make_path $DST_HOST $DST_DIR
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@ -68,7 +90,17 @@ http://*)
|
||||
*)
|
||||
log "Cloning $SRC_PATH in $DST"
|
||||
|
||||
CLONE_CMD="cd $DST_DIR; rm -f $DST_PATH; $QEMU_IMG create -b $SRC_PATH -f qcow2 $DST_PATH"
|
||||
if [ -n $ORIGINAL_SIZE ]; then
|
||||
ORIGINAL_SIZE="0"
|
||||
fi
|
||||
|
||||
if [ "$SIZE" -ge "$ORIGINAL_SIZE" ]; then
|
||||
RESIZE_CMD="; qemu-img resize ${DST_PATH} ${SIZE}M"
|
||||
fi
|
||||
|
||||
CLONE_CMD="cd $DST_DIR; \
|
||||
rm -f $DST_PATH; $QEMU_IMG create -b $SRC_PATH -f qcow2 $DST_PATH \
|
||||
${RESIZE_CMD}"
|
||||
ssh_exec_and_log "$DST_HOST" "$CLONE_CMD" "Error copying $SRC to $DST"
|
||||
;;
|
||||
esac
|
||||
|
@ -38,6 +38,8 @@ fi
|
||||
|
||||
. $TMCOMMON
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set dst path and dir
|
||||
#-------------------------------------------------------------------------------
|
||||
@ -52,6 +54,26 @@ SRC_DS_PATH="$(dirname $(dirname $SRC_ARG_PATH))"
|
||||
|
||||
SRC_PATH="${DST_DS_PATH}${SRC_ARG_PATH##$SRC_DS_PATH}"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Get Image information
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
DISK_ID=$(basename ${DST_PATH} | cut -d. -f2)
|
||||
|
||||
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/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SIZE \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/ORIGINAL_SIZE)
|
||||
|
||||
SIZE="${XPATH_ELEMENTS[j++]}"
|
||||
ORIGINAL_SIZE="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Create DST path
|
||||
#-------------------------------------------------------------------------------
|
||||
@ -72,8 +94,21 @@ http://*)
|
||||
|
||||
*)
|
||||
log "Cloning $SRC_PATH in $DST"
|
||||
|
||||
if [ -n $ORIGINAL_SIZE ]; then
|
||||
ORIGINAL_SIZE="0"
|
||||
fi
|
||||
|
||||
if [ "$SIZE" -ge "$ORIGINAL_SIZE" ]; then
|
||||
RESIZE_CMD="; qemu-img resize ${DST_PATH} ${SIZE}M"
|
||||
fi
|
||||
|
||||
CLONE_CMD="cd ${DST_DIR}; \
|
||||
cp ${SRC_PATH} ${DST_PATH} \
|
||||
${RESIZE_CMD}"
|
||||
|
||||
ssh_exec_and_log $DST_HOST \
|
||||
"cd $DST_DIR; cp $SRC_PATH $DST_PATH" \
|
||||
"$CLONE_CMD" \
|
||||
"Error copying $SRC to $DST"
|
||||
;;
|
||||
esac
|
||||
|
@ -38,6 +38,8 @@ fi
|
||||
|
||||
. $TMCOMMON
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set dst path and dir
|
||||
#-------------------------------------------------------------------------------
|
||||
@ -53,6 +55,25 @@ DST_DIR=`dirname $DST_PATH`
|
||||
|
||||
ssh_make_path $DST_HOST $DST_DIR
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Get Image information
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
DISK_ID=$(basename ${DST_PATH} | cut -d. -f2)
|
||||
|
||||
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/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SIZE \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/ORIGINAL_SIZE)
|
||||
|
||||
SIZE="${XPATH_ELEMENTS[j++]}"
|
||||
ORIGINAL_SIZE="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Copy files to the remote host
|
||||
#-------------------------------------------------------------------------------
|
||||
@ -71,6 +92,16 @@ http://*)
|
||||
exec_and_log "$SCP -r ${SRC_PATH_SNAP} ${DST_PATH_SNAP}" \
|
||||
"Error copying $SRC to $DST"
|
||||
fi
|
||||
|
||||
if [ -n $ORIGINAL_SIZE ]; then
|
||||
ORIGINAL_SIZE="0"
|
||||
fi
|
||||
|
||||
if [ "$SIZE" -ge "$ORIGINAL_SIZE" ]; then
|
||||
RESIZE_CMD="qemu-img resize ${DST_PATH} ${SIZE}M"
|
||||
ssh_exec_and_log "$DST_HOST" "$RESIZE_CMD" \
|
||||
"Error resizing image $DST"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user