Add vm-migrate script

This commit is contained in:
Victor LABORIE 2018-09-12 15:29:11 +02:00
parent 4dc0b423b2
commit 33c452464f
2 changed files with 25 additions and 0 deletions

View file

@ -5,6 +5,7 @@ This repository contain scripts for managing KVM hypervisors used with DRBD and
It contains the following scripts.
- add-vm: create DBRD volumes and virtual machines.
- vm-migrate: migrate a DRBD based virtual machine
- kvmstats: gives informations about defined virtual machines.
## Install

24
vm-migrate Executable file
View file

@ -0,0 +1,24 @@
#!/bin/bash
set -eu
error() {
msg="${1:-$(cat /dev/stdin)}"
echo "ERROR : ${msg}" >&2
exit 1
}
vmname="${1:-}"
[ -n "${vmname}" ] || error "You must provide <vmname> !"
virsh list --name | grep -qE "^${vmname}$" || error "${vmname} is not a running VM !"
[ -f "/etc/evolinux/add-vm.cnf" ] && . /etc/evolinux/add-vm.cnf
slaveKVMIP="${slaveKVMIP:-}"
ssh "${slaveKVMIP}" virsh exit || error "Cannot connect to libvirt on ${slaveKVMIP} !"
ssh "${slaveKVMIP}" drbdadm primary "${vmname}"
virsh migrate --live --unsafe --verbose "${vmname}" "qemu+ssh://${slaveKVMIP}/system" "tcp://${slaveKVMIP}/"
virsh dumpxml "${vmname}" | ssh "${slaveKVMIP}" virsh define /dev/stdin
virsh undefine "${vmname}"
drbdadm secondary "${vmname}"