Created
July 24, 2019 12:27
-
-
Save gersilex/10d0c57d8d283a53e1828c49e68896a3 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> | |
# | |
# (c) 2019 Immowelt Hamburg GmbH | |
# Released under the MIT License. | |
# | |
set -xeuo pipefail | |
source "$(dirname "$0")/kvmrc" | |
source "$(dirname "$0")/../../scripts_common.sh" | |
VIRSH_COMMAND="virsh --connect $LIBVIRT_URI" | |
get_disks(){ | |
ssh -n "$src_host" -- "$VIRSH_COMMAND" domblklist "$deploy_id" | strings | tail -n+3 | awk '{print $2}' | |
} | |
get_size_of_disk_img(){ | |
qemu_img_path="$1" | |
ssh -n "$src_host" -- qemu-img info -U "$qemu_img_path" --output json | sed -nE 's/^.*"virtual-size": ([0-9]+).*/\1/p' | |
} | |
create_target_disk_img(){ | |
qemu_img_path="$1" | |
size="$2" | |
ssh -n "$dest_host" -- mkdir -v -p "$(dirname "$qemu_img_path")" | |
ssh -n "$dest_host" -- qemu-img create -f qcow2 "$qemu_img_path" "$size" | |
} | |
deploy_id="$1" | |
dest_host="$2" | |
src_host="$3" | |
get_disks | while read -r disk | |
do | |
create_target_disk_img "$disk" "$(get_size_of_disk_img "$disk")" | |
done | |
# Snapshots must be removed before migration | |
snapshots="$(ssh -n "$src_host" -- "$VIRSH_COMMAND" snapshot-list "$deploy_id" --name)" | |
for snapshot in $snapshots | |
do | |
ssh -n "$src_host" -- "$VIRSH_COMMAND" snapshot-delete "$deploy_id" --snapshotname "$snapshot" --metadata | |
done | |
ssh -n "$src_host" -- "$VIRSH_COMMAND" migrate "$deploy_id" "$QEMU_PROTOCOL://$dest_host/system" --live --copy-storage-all |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've done this based on the scripts in 5.10 now - https://gist.github.com/mzealey/0cac6328c8bbc86c733a72e7a6af89a7