scripts: Add VM host maintenance scripts
The `migrate-all.sh` script is used to migrate one or more VMs (default: all) from one VM host to the other on demand. The `shutdown-vmhost.sh` script prepares a VM host to shut down by evicting Kubernetes Pods from the Nodes running on that host and then shutting them down, followed by migrating the rest of the running VMs to the other host.
This commit is contained in:
28
scripts/migrate-all.sh
Executable file
28
scripts/migrate-all.sh
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/bin/sh
|
||||
# vim: set sw=4 ts=4 sts=4 et :
|
||||
|
||||
list_vms() {
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "$@" | xargs -n1
|
||||
else
|
||||
virsh list --name
|
||||
fi
|
||||
}
|
||||
|
||||
src=$1
|
||||
shift 2>&-
|
||||
dest=$1
|
||||
shift 2>&-
|
||||
|
||||
if [ -z "${src}" ] || [ -z "${dest}" ]; then
|
||||
printf 'usage: %s source_uri dest_uri [name [...]]\n' "${0##*/}"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
export LIBVIRT_DEFAULT_URI="${src}"
|
||||
|
||||
list_vms "$@" | while read name; do
|
||||
[ -n "${name}" ] || continue
|
||||
printf 'Migrating %s ...\n' "${name}"
|
||||
virsh migrate "${name}" "${dest}" --live --persistent --undefinesource --verbose
|
||||
done
|
||||
Reference in New Issue
Block a user