Migrate instances¶
Note
This documentation is about cold migration. For live migration usage, see Live-migrate instances.
When you want to move an instance from one compute host to another, you can migrate the instance. The migration operation, which is also known as the cold migration operation to distinguish it from the live migration operation, functions similarly to the resize operation with the main difference being that a cold migration does not change the flavor of the instance. As with resize, the scheduler chooses the destination compute host based on its settings. This process does not assume that the instance has shared storage available on the target host. If you are using SSH tunneling, you must ensure that each node is configured with SSH key authentication so that the Compute service can use SSH to move disks to other nodes. For more information, see Configure SSH between compute nodes.
To list the VMs you want to migrate, run:
$ openstackserverlist
Once you have the name or UUID of the server you wish to migrate, migrate it using the openstack server migrate command:
$ openstackservermigrateSERVER
Once an instance has successfully migrated, you can use the openstack server migrate confirm command to confirm it:
$ openstackservermigrateconfirmSERVER
Alternatively, you can use the openstack server migrate revert command to revert the migration and restore the instance to its previous host:
$ openstackservermigraterevertSERVER
Note
You can configure automatic confirmation of migrations and resizes. Refer to
the resize_confirm_window
option for more information.
Example¶
To migrate an instance and watch the status, use this example script:
#!/bin/bash # Provide usage usage(){ echo"Usage: 0ドル VM_ID" exit1 } [[$#-eq0]]&&usage VM_ID=1ドル # Show the details for the VM echo"Instance details:" openstackservershow${VM_ID} # Migrate the VM to an alternate hypervisor echo-n"Migrating instance to alternate host " openstackservermigrate${VM_ID} while[["$(openstackservershow${VM_ID}-fvalue-cstatus)"!="VERIFY_RESIZE"]];do echo-n"." sleep2 done openstackservermigrateconfirm${VM_ID} echo" instance migrated and resized." # Show the details for the migrated VM echo"Migrated instance details:" openstackservershow${VM_ID} # Pause to allow users to examine VM details read-p"Pausing, press <enter> to exit."
Note
If you see the following error, it means you are either running the command
with the wrong credentials, such as a non-admin user, or the policy.yaml
file prevents migration for your user:
Policy doesn't allow os_compute_api:os-migrate-server:migrate to be performed. (HTTP 403)
Note
If you see the following error, similar to this message, SSH tunneling was not set up between the compute nodes:
ProcessExecutionError: Unexpected error while running command. Stderr: u Host key verification failed.\r\n
The instance is booted from a new host, but preserves its configuration including instance ID, name, IP address, any metadata, and other properties.