forked from OpenNebula/one
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
F OpenNebula#4985: Support for cluster replicas to ssh driver
The initial caching mechanism will be exteneded with: - Cache remplacement policy - Optimize recovery snapshot with qcow2 format - Add support for automatic snapshot VM disks co-authored-by: Jan Orel <[email protected]>
- Loading branch information
1 parent
4bc1e59
commit 901843d
Showing
15 changed files
with
454 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,4 +71,6 @@ else | |
|
||
exec_and_log "rm ${SNAP_PATH}" \ | ||
"Error deleting snapshot $SNAP_PATH" | ||
|
||
rm -f ${SRC_PATH}.md5sum | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,5 +103,7 @@ else | |
|
||
exec_and_log "rm -rf ${SNAP_DIR}" \ | ||
"Error removing ${SNAP_DIR}" | ||
|
||
rm -f ${SRC_PATH}.md5sum | ||
fi | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
#!/bin/bash | ||
|
||
# -------------------------------------------------------------------------- # | ||
# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems # | ||
# # | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may # | ||
# not use this file except in compliance with the License. You may obtain # | ||
# a copy of the License at # | ||
# # | ||
# http://www.apache.org/licenses/LICENSE-2.0 # | ||
# # | ||
# Unless required by applicable law or agreed to in writing, software # | ||
# distributed under the License is distributed on an "AS IS" BASIS, # | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # | ||
# See the License for the specific language governing permissions and # | ||
# limitations under the License. # | ||
#--------------------------------------------------------------------------- # | ||
|
||
# clone fe:SOURCE host:remote_system_ds/disk.i vmid dsid [replica_host] | ||
# - fe is the front-end hostname | ||
# - SOURCE is the path of the disk image in the form DS_BASE_PATH/disk | ||
# - host is the target host to deploy the VM | ||
# - remote_system_ds is the path for the system datastore in the host | ||
# - vmid is the id of the VM | ||
# - dsid is the target datastore (0 is the system datastore | ||
# - replica_host is an optional paramter when called from the tm/ssh/clone | ||
|
||
SRC=$1 | ||
DST=$2 | ||
|
||
VMID=$3 | ||
DSID=$4 | ||
|
||
REPLICA_HOST=$5 | ||
|
||
if [ -z "${ONE_LOCATION}" ]; then | ||
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh | ||
SSH_RC=/var/lib/one/remotes/tm/ssh/sshrc | ||
else | ||
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh | ||
SSH_RC=$ONE_LOCATION/var/remotes/tm/ssh/sshrc | ||
fi | ||
|
||
. $TMCOMMON | ||
. $SSH_RC | ||
|
||
DRIVER_PATH=$(dirname $0) | ||
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin" | ||
|
||
#------------------------------------------------------------------------------- | ||
# Set dst path and dir | ||
#------------------------------------------------------------------------------- | ||
SRC_PATH=$(arg_path $SRC) | ||
DST_PATH=$(arg_path $DST) | ||
SRC_FILE=$(basename $SRC_PATH) | ||
DST_FILE=$(basename $DST_PATH) | ||
|
||
SRC_HOST=$(arg_host $SRC) | ||
DST_HOST=$(arg_host $DST) | ||
|
||
SRC_DIR=$(dirname $SRC_PATH) | ||
DST_DIR=$(dirname $DST_PATH) | ||
|
||
#------------------------------------------------------------------------------- | ||
# Get Image and System DS information | ||
#------------------------------------------------------------------------------- | ||
DISK_ID=$(basename ${DST_PATH} | cut -d. -f2) | ||
|
||
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 \ | ||
/VM/HISTORY_RECORDS/HISTORY[last\(\)]/DS_ID) | ||
|
||
SIZE="${XPATH_ELEMENTS[j++]}" | ||
ORIGINAL_SIZE="${XPATH_ELEMENTS[j++]}" | ||
SYS_DS_ID="${XPATH_ELEMENTS[j++]}" | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Get REPLICA_HOST from DATASTORE (if not passed as 5th arg) | ||
# ------------------------------------------------------------------------------ | ||
if [ -z "$REPLICA_HOST" ]; then | ||
REPLICA_HOST=$(get_replica_host $SYS_DS_ID) | ||
|
||
if [ -z "$REPLICA_HOST" ]; then | ||
error_message "No REPLICA_HOST in datastore $SYS_DS_ID template" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
#------------------------------------------------------------------------------- | ||
# Create DST path | ||
#------------------------------------------------------------------------------- | ||
ssh_make_path $DST_HOST $DST_DIR "ssh" | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Get REPLICA_STORAGE_IP from host template | ||
# ------------------------------------------------------------------------------ | ||
REPLICA_STORAGE_IP=$(awk 'gsub(/[\0]/, x)' \ | ||
<( onehost show $DST_HOST -x | $XPATH /HOST/TEMPLATE/REPLICA_STORAGE_IP )) | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Synchronize Image Datastore in the Replica Host. Use a recovery snapshot | ||
# if present in the RECOVERY_SNAPS_DIR | ||
# ------------------------------------------------------------------------------ | ||
if ssh $REPLICA_HOST \ | ||
"test -e ${REPLICA_RECOVERY_SNAPS_DIR}/$VMID/${DST_FILE}.replica_snap"; then | ||
|
||
# point to [disk].replica_snap files | ||
SRC_DIR=${REPLICA_RECOVERY_SNAPS_DIR}/$VMID | ||
SRC_FILE="${DST_FILE}.replica_snap" | ||
else | ||
rsync_img_to_replica "$SRC_PATH" "$REPLICA_HOST" | ||
|
||
if [ -n "$ORIGINAL_SIZE" -a "$SIZE" -gt "$ORIGINAL_SIZE" ]; then | ||
RESIZE_CMD="qemu-img resize ${DST_PATH} ${SIZE}M" | ||
fi | ||
fi | ||
|
||
#------------------------------------------------------------------------------- | ||
# Clone (tar|ssh) SRC into DST | ||
#------------------------------------------------------------------------------- | ||
log "Cloning $SRC_PATH via replica $REPLICA_HOST in $DST" | ||
|
||
# copy locally, we hit the replica | ||
if [ "$REPLICA_HOST" = "$DST_HOST" ]; then | ||
CLONE_CMD=$(cat <<EOF | ||
cd $SRC_DIR | ||
cp $SRC_FILE $DST_PATH | ||
if [ -d $SRC_PATH.snap ]; then | ||
cp -r $SRC_PATH.snap $DST_PATH.snap | ||
fi | ||
EOF | ||
) | ||
else | ||
# copy to remote using faster tar|ssh | ||
CLONE_CMD=$(cat <<EOF | ||
if [ -d "${SRC_PATH}.snap" ]; then | ||
SRC_SNAP="${SRC_FILE}.snap" | ||
fi | ||
cd $SRC_DIR | ||
tar --transform="flags=r;s|$SRC_FILE|$DST_FILE|" -cSf - $SRC_FILE \$SRC_SNAP | \ | ||
ssh $REPLICA_SSH_OPTS ${REPLICA_STORAGE_IP:-$DST_HOST} "tar xSf - -C $DST_DIR" | ||
EOF | ||
) | ||
fi | ||
|
||
ssh_forward ssh_exec_and_log $REPLICA_HOST "$CLONE_CMD" \ | ||
"Error copying $SRC to $DST" | ||
|
||
if [ -n "$RESIZE_CMD" ]; then | ||
ssh_exec_and_log "$DST_HOST" "$RESIZE_CMD" \ | ||
"Error resizing image $DST" | ||
fi | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
clone.replica |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.