OpenStack: Live migrate VM to another OpenStack hypervisor

show migrate state / log

nova migration-list --instance-uuid  ${SERVER_ID}
 
# show multiple migrations by date
nova migration-list | grep 2020-02-20 | awk -F"|" '{ print $8}' | sort | uniq -dc

CLI

VM=foo-u1804
 
# list all vms on a hypervisor
openstack server list --all --status ACTIVE --host com1.example.com
 
# get current hypervisor
openstack server show ${VM} -c OS-EXT-SRV-ATTR:host -f value
 
# list avaiable hypervisors
openstack host list -c "Host Name" -c Service -f value | grep compute | cut -d" " -f1
 
# live migrate VM to specific compute node
# deprected: openstack server migrate ${VM} --live ${TARGET_COMPUTE_NODE} --wait
openstack server migrate --live-migration --wait ${SERVER_ID}
 
# get state
openstack server show ${VM} -c name -c OS-EXT-SRV-ATTR:host -c status -f value | paste - - -
 
# migrate all VMs
openstack server list --all --host ${COMPUTE_NODE}
 
# migrae VMs
nova host-evacuate-live ${COMPUTE_NODE} [--max-servers 10]
 
# show remaining VMs
VMS=999
while [ ${VMS} -gt 0 ]; do
    echo ${VMS} VMs remaining on ${OS_NODE}
    VMS=$(openstack server list --all --status MIGRATING --host ${OS_NODE} -f value | wc -l)
    sleep 15
done
 
# migrae VMs
for VMID in $(openstack server list --all --status ACTIVE --host ${OS_NODE} -c ID -f value); do
    # start live migration
    date
    openstack server show ${VMID} -c id -c name -c OS-EXT-SRV-ATTR:host -c status -f value | paste - - - -
    nova live-migration ${VMID}
 
    # show migration status
    openstack server show ${VMID} -c id -c name -c OS-EXT-SRV-ATTR:host -c status -f value | paste - - - -
 
    # wait until migration has been completed
    while [ "$(openstack server show ${VMID} -c status -f value)" == "MIGRATING" ]; do sleep 1; done
 
    # show migration status
    openstack server show ${VMID} -c id -c name -c OS-EXT-SRV-ATTR:host -c status -f value | paste - - - -
    date
 
    echo
    sleep 10
done
 
 
# define VMs
VMIDS="
3fa95ff3-49b4-0000-1111-a0633720000
3fa95ff3-49b4-0000-1111-a0633720111
"
 
# all active VMs on specific host
VMIDS=$(openstack server list --all --status=ACTIVE -c ID -f value --host compute1-dev)
 
# live migrate VMs
for VMID in ${VMIDS}; do
    echo ${VMID}
    openstack server migrate ${VMID} --live compute2-prod --wait
    echo
done
 
# test
nova live-migration VM_ID
# nova host-evacuate-live
# --live-migration --wait
# nova server-migration-list

Cold migrate
https://docs.openstack.org/nova/rocky/admin/migration.html

openstack server list --all --status SHUTOFF --host ${COMPUTE_NODE}
 
# single VM
openstack server migrate ${VMID} 
openstack server resize --confirm ${VMID}
 
# multiple VMs
VMIDS="
111111-22222-3333-0000-111111111111
111111-22222-3333-0000-222222222222
"
 
VMIDS=$(openstack server list --all --host compute1-dev --status=SHUTOFF -c ID -f value)
 
for VMID in ${VMIDS}; do
    echo ${VMID}
    #openstack server show ${VMID}
    openstack server migrate ${VMID}
    sleep 30
    openstack server resize --confirm ${VMID}
    sleep 10
    #openstack server show ${VMID}
done
 
openstack server list --all --status=VERIFY_RESIZE

qemu / libvirt

# fix DestinationDiskExists_Remote issue
docker exec -t -u root nova_libvirt ls -l  /var/lib/nova/instances/${SERVER_ID}

Links
https://docs.openstack.org/nova/latest/admin/live-migration-usage.html
http://www.danplanet.com/blog/2016/03/03/evacuate-in-nova-one-command-to-confuse-us-all/