Openstack - Nova Migration (Manually) between Region

## Nova Migration Type

http://docs.openstack.org/admin-guide-cloud/compute-configuring-migrations.html

> **The migration types are:**
>
> 1. **Non-live migration** (sometimes referred to simply as ‘migration’)
> The instance is shut down for a period of time to be moved to another hypervisor. In this case, the instance recognizes that it was rebooted.
>
> 2. **Live migration** (or ‘true live migration’)
> Almost no instance downtime. Useful when the instances must be kept running during the migration.
> The different types of live migration are:
>     - 2-1. **Shared storage-based live migration** <br>
>            Both hypervisors have access to shared storage.
>     - 2-2. **Block live migration** <br>
>            No shared storage is required. Incompatible with read-only devices such as CD-ROMs and Configuration Drive (config_drive).
>     - 2-3. **Volume-backed live migration** <br>
>            Instances are backed by volumes rather than ephemeral disk, no shared storage is required, and migration is supported (currently only available for libvirt-based hypervisors).

## What's this?

`nova migrate` は Region 間の移動は出来ないので、手動で Nova instance を別の Region へ移動。

Brief summary procedure:

1. [Region1] Take a Nova instance snapshot, the snapshot is stored in Glance as image.
2. [Somewhere installed openstack client tool] Download the image from Region1
3. [Somewhere installed openstack client tool] Upload the image to Region2
4. [Region2] Create a Nova instance from the snapshot image


## [Region1]

### Initial state

    $ nova list --field name,status,,OS-EXT-STS:vm_state,OS-EXT-AZ:availability_zone
    +--------------------------------------+------------+---------+--+----------------------+------------------------------+
    | ID                                   | Name       | Status  |  | OS-EXT-STS: Vm State | OS-EXT-AZ: Availability Zone |
    +--------------------------------------+------------+---------+--+----------------------+------------------------------+
    | 400b58b5-0d50-4163-8a92-27b26f0b7a5b | admin_vm01 | ACTIVE  |  | active               | nova                         |
    +--------------------------------------+------------+---------+--+----------------------+------------------------------+

### Nova snapshot

#### Take Nova snapshot

Recommend to stop a instance before take a snapshot.

    $ nova image-create --poll admin_vm01 admin_vm01_ss
    Server snapshotting... 100% complete
    Finished

#### List Glance images

    $ glance image-list --name admin_vm01_ss
    +--------------------------------------+---------------+-------------+------------------+------------+--------+
    | ID                                   | Name          | Disk Format | Container Format | Size       | Status |
    +--------------------------------------+---------------+-------------+------------------+------------+--------+
    | 95385cef-879c-4b36-91d7-e96f87c0c8ed | admin_vm01_ss | raw         | bare             | 1073741824 | active |
    +--------------------------------------+---------------+-------------+------------------+------------+--------+

    $ glance image-show admin_vm01_ss | egrep "Property|instance_uuid"
    | Property                              | Value                                |
    | Property 'instance_uuid'              | 400b58b5-0d50-4163-8a92-27b26f0b7a5b            |


## [Somewhere installed openstack client tool]

### Download from Region1

    $ glance image-download --file admin_vm01.qcow2 admin_vm01_ss

    $ ls -l
    -rw-r--r-- 1 root root 1073741824 Feb 10 15:58 admin_vm01.qcow2

### Upload to Region2

    $ glance image-create --name admin_vm01 \
                          --disk-format qcow2 \
                          --container-format bare \
                          --is-public True \
                          --file admin_vm01.qcow2
    +------------------+--------------------------------------+
    | Property         | Value                                |
    +------------------+--------------------------------------+
    | checksum         | 0f4db50348b63ff6f09e6d0ed616c9d2     |
    | container_format | bare                                 |
    | created_at       | 2015-02-10T07:09:19                  |
    | deleted          | False                                |
    | deleted_at       | None                                 |
    | disk_format      | qcow2                                |
    | id               | 6e6eac4e-b151-4ce2-9a8b-970f9ea7962c |
    | is_public        | True                                 |
    | min_disk         | 0                                    |
    | min_ram          | 0                                    |
    | name             | admin_vm01                           |
    | owner            | 103cfcfb3a094c3382441d21ccff32b3     |
    | protected        | False                                |
    | size             | 1073741824                           |
    | status           | active                               |
    | updated_at       | 2015-02-10T07:10:50                  |
    | virtual_size     | None                                 |
    +------------------+--------------------------------------+

## [Region2]

### Boot Nova instance from the Glance image uploaded from Region1

#### AZ

    $ nova availability-zone-list | grep -A 5 "^| nova"
    | nova                  | available                              |
    | |- node-99            |                                        |
    | | |- nova-compute     | enabled :-) 2015-02-10T07:18:27.000000 |


#### Nova boot

    $ nova boot --flavor m1.tiny \
                --image admin_vm01 \
                --security-groups default \
                --availability-zone nova \
                admin_vm01
    +--------------------------------------+---------------------------------------------------+
    | Property                             | Value                                             |
    +--------------------------------------+---------------------------------------------------+
    | OS-DCF:diskConfig                    | MANUAL                                            |
    | OS-EXT-AZ:availability_zone          | nova                                              |
    | OS-EXT-SRV-ATTR:host                 | -                                                 |
    | OS-EXT-SRV-ATTR:hypervisor_hostname  | -                                                 |
    | OS-EXT-SRV-ATTR:instance_name        | instance-0000001a                                 |
    | OS-EXT-STS:power_state               | 0                                                 |
    | OS-EXT-STS:task_state                | scheduling                                        |
    | OS-EXT-STS:vm_state                  | building                                          |
    | OS-SRV-USG:launched_at               | -                                                 |
    | OS-SRV-USG:terminated_at             | -                                                 |
    | accessIPv4                           |                                                   |
    | accessIPv6                           |                                                   |
    | adminPass                            | zv6GonRfMVfr                                      |
    | config_drive                         |                                                   |
    | created                              | 2015-02-10T07:19:04Z                              |
    | flavor                               | m1.tiny (1)                                       |
    | hostId                               |                                                   |
    | id                                   | 8c27d436-2049-4f4b-8c23-28dc453e3678              |
    | image                                | admin_vm01 (6e6eac4e-b151-4ce2-9a8b-970f9ea7962c) |
    | key_name                             | -                                                 |
    | metadata                             | {}                                                |
    | name                                 | admin_vm01                                        |
    | os-extended-volumes:volumes_attached | []                                                |
    | progress                             | 0                                                 |
    | security_groups                      | default                                           |
    | status                               | BUILD                                             |
    | tenant_id                            | 103cfcfb3a094c3382441d21ccff32b3                  |
    | updated                              | 2015-02-10T07:19:04Z                              |
    | user_id                              | 451fd821ff05490984234a72b585a7d9                  |
    +--------------------------------------+---------------------------------------------------+

#### Check

    $ nova list
    +--------------------------------------+------------+--------+------------+-------------+-------------------------+
    | ID                                   | Name       | Status | Task State | Power State | Networks                |
    +--------------------------------------+------------+--------+------------+-------------+-------------------------+
    | 8c27d436-2049-4f4b-8c23-28dc453e3678 | admin_vm01 | ACTIVE | -          | Running     | external=10.10.10.10    |
    +--------------------------------------+------------+--------+------------+-------------+-------------------------+

    $ nova show admin_vm01 | egrep "Property|hypervisor| id |image"
    | Property                             | Value                                                    |
    | OS-EXT-SRV-ATTR:hypervisor_hostname  | node-99                                                  |
    | id                                   | 8c27d436-2049-4f4b-8c23-28dc453e3678                     |
    | image                                | admin_vm01 (6e6eac4e-b151-4ce2-9a8b-970f9ea7962c)        |

## Environment

* Openstack : Juno
* Ceph : Firefly

## Reference

[Nova Migration (non live migration) to Different Hypervisor][link-01]
[Nova Migration (non live migration) to Different Hypervisor between AZ][link-02]
[Nova Migration (true live migration) to Different Hypervisor][link-03]
[Nova Migration (true live migration) to Different Hypervisor between AZ][link-04]
[Nova Migration (Manually) between AZ][link-05]
[Nova Migration (Manually) between Region][link-06]
[Nova Migration (true live migration) to Different Hypervisor - Volume-backend live migration (instance)][link-07]
[Nova Migration (true live migration) to Different Hypervisor - Volume-backend live migration (instance) between AZ][link-08]

[link-01]:http://qiita.com/idzzy/items/a3032dce3110f959e11b
[link-02]:http://qiita.com/idzzy/items/3d67b3cedd42d39a8e2a
[link-03]:http://qiita.com/idzzy/items/a03b19e0c0289a63e491
[link-04]:http://qiita.com/idzzy/items/ed45aaa3cc6ecc144f90
[link-05]:http://qiita.com/idzzy/items/98967887a0d3771a7795
[link-06]:http://qiita.com/idzzy/items/01b32f52e7cf0e4c5f55
[link-07]:http://qiita.com/idzzy/items/515776f1461bb5c96eea
[link-08]:http://qiita.com/idzzy/items/5c54443c0d36f0a14e72