diff --git a/src/tm_mad/qcow2/clone b/src/tm_mad/qcow2/clone index 4cf935cc43..61b80177f7 100755 --- a/src/tm_mad/qcow2/clone +++ b/src/tm_mad/qcow2/clone @@ -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 diff --git a/src/tm_mad/shared/clone b/src/tm_mad/shared/clone index e81e53b92b..69525d0621 100755 --- a/src/tm_mad/shared/clone +++ b/src/tm_mad/shared/clone @@ -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 diff --git a/src/tm_mad/ssh/clone b/src/tm_mad/ssh/clone index bcd2a00701..8e01fa89aa 100755 --- a/src/tm_mad/ssh/clone +++ b/src/tm_mad/ssh/clone @@ -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