-
-
Save mzealey/0cac6328c8bbc86c733a72e7a6af89a7 to your computer and use it in GitHub Desktop.
OpenNebula Live Migration Examples
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
#!/usr/bin/env bash | |
# | |
# Live migration-over-SSH script for use with OpenNebula. | |
# Set the 'migrate' action to run this script in /etc/one/oned.conf | |
# for your respective virtualization type. Only KVM is supported right now. | |
# | |
# Author: Leroy Förster <[email protected]> | |
# Contributor: Paul Jost <paul.jost.immonet.de> | |
# Contributor: Mark Zealey - port to ONE 5.10 | |
# | |
# (c) 2019 Immowelt Hamburg GmbH | |
# Released under the MIT License. | |
source $(dirname $0)/../../etc/vmm/kvm/kvmrc | |
source $(dirname $0)/../../scripts_common.sh | |
deploy_id=$1 | |
dest_host=$2 | |
src_host=$3 | |
set -eo pipefail | |
get_disks() { | |
virsh --connect $QEMU_PROTOCOL://$src_host/system domblklist "$deploy_id" | strings | tail -n+3 | awk '{print $2}' | tr '\n' ' ' | |
} | |
get_size_of_disk_img() { | |
qemu_img_path="$1" | |
ssh_monitor_and_log "$src_host" "qemu-img info -U '$qemu_img_path' --output json | sed -nE 's/^.*virtual-size.: ([0-9]+).*/\1/p'" \ | |
"Failed to get image size for $qemu_img_path" | |
} | |
create_target_disk_img() { | |
qemu_img_path="$1" | |
size="$2" | |
ssh_monitor_and_log "$dest_host" "mkdir -v -p '$(dirname "$qemu_img_path")'" "Failed to make remote directory for $qemu_img_path image" | |
ssh_monitor_and_log "$dest_host" "qemu-img create -f qcow2 '$qemu_img_path' '$size'" "Failed to create new qcow image for $qemu_img_path" | |
} | |
DISKS=$(get_disks) | |
if [[ -z "$DISKS" ]]; then | |
echo "No disks discovered on remote host" | |
exit 1 | |
fi | |
for disk in $DISKS; do | |
create_target_disk_img "$disk" "$(get_size_of_disk_img "$disk")" | |
done | |
# migration can't be done with domain snapshots, drop them first | |
snaps=$(monitor_and_log \ | |
"virsh --connect $QEMU_PROTOCOL://$src_host/system snapshot-list $deploy_id --name 2>/dev/null" \ | |
"Failed to get snapshots for $deploy_id") | |
for snap in $snaps; do | |
exec_and_log \ | |
"virsh --connect $QEMU_PROTOCOL://$src_host/system snapshot-delete $deploy_id --snapshotname $snap --metadata" \ | |
"Failed to delete snapshot $snap from $deploy_id" | |
done | |
virsh --connect $QEMU_PROTOCOL://$src_host/system \ | |
migrate --live --copy-storage-all $deploy_id $MIGRATE_OPTIONS $QEMU_PROTOCOL://$dest_host/system --verbose | |
# Clean up the source images. ENABLE THIS WHEN YOU HAVE TESTED WELL | |
#ssh_monitor_and_log "$src_host" "rm -f $DISKS" || exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment