Scripts for managing KVM hypervisors used with DRBD and LVM.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

vm-migrate 833B

1234567891011121314151617181920212223242526
  1. #!/bin/bash
  2. set -eu
  3. error() {
  4. msg="${1:-$(cat /dev/stdin)}"
  5. echo "ERROR : ${msg}" >&2
  6. exit 1
  7. }
  8. vmname="${1:-}"
  9. [ -n "${vmname}" ] || error "You must provide <vmname> !"
  10. virsh list --name | grep -qE "^${vmname}$" || error "${vmname} is not a running VM !"
  11. [ -f "/etc/evolinux/add-vm.cnf" ] && . /etc/evolinux/add-vm.cnf
  12. slaveKVMIP="${slaveKVMIP:-}"
  13. ssh "${slaveKVMIP}" virsh exit || error "Cannot connect to libvirt on ${slaveKVMIP} !"
  14. drbdadm net-options --protocol=C --allow-two-primaries "${vmname}"
  15. ssh "${slaveKVMIP}" drbdadm primary "${vmname}"
  16. virsh migrate --live --unsafe --verbose "${vmname}" "qemu+ssh://${slaveKVMIP}/system" "tcp://${slaveKVMIP}/"
  17. virsh dumpxml "${vmname}" | ssh "${slaveKVMIP}" virsh define /dev/stdin
  18. virsh undefine "${vmname}"
  19. drbdadm secondary "${vmname}"
  20. drbdadm adjust "${vmname}"