Openstack - Nova Migration (true live migration) to Different Hypervisor - Volume-backend live migration (instance) between AZ

## 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?

**2-3. Volume-backed live migration** の Nova instance のAZ間の Migration

Nova instance (running 状態) を**別の AZの** Hypervisor (Compute node) へ移動
Nova instance の Boot Volume は Cinder に格納
Cinder は Shared Storage

[Case]

1. Cinder volume を接続していない場合
2. Cinder volume を接続している場合

## [Case1] Migrate Nova instance (w/o Cinder volume)

### Initial state

#### Hypervisor (Compute node)

    # nova hypervisor-list
    +----+-----------------------+
    | ID | Hypervisor hostname   |
    +----+-----------------------+
    | 6  | node-27 |
    | 9  | node-28 |
    | 15 | node-31 |
    +----+-----------------------+

#### AZ

    # nova availability-zone-list | egrep -A 10 "^\| nova"
    | nova                     | available                              |
    | |- node-27               |                                        |
    | | |- nova-compute        | enabled :-) 2015-02-24T08:40:02.000000 |
    | |- node-28               |                                        |
    | | |- nova-compute        | enabled :-) 2015-02-24T08:39:55.000000 |
    | nova2                    | available                              |
    | |- node-31               |                                        |
    | | |- nova-compute        | enabled :-) 2015-02-24T08:40:02.000000 |
    +--------------------------+----------------------------------------+

#### Nova instance is on node-28

    # nova list --field name,status,,OS-EXT-STS:vm_state,OS-EXT-AZ:availability_zone,OS-EXT-SRV-ATTR:hypervisor_hostname
    +--------------------------------------+------------+--------+--+----------------------+------------------------------+--------------------------------------+
    | ID                                   | Name       | Status |  | OS-EXT-STS: Vm State | OS-EXT-AZ: Availability Zone | OS-EXT-SRV-ATTR: Hypervisor Hostname |
    +--------------------------------------+------------+--------+--+----------------------+------------------------------+--------------------------------------+
    | ed831ace-39ef-4960-8bae-a035d292c305 | admin_vm01 | ACTIVE |  | active               | nova                         | node-28                              |
    +--------------------------------------+------------+--------+--+----------------------+------------------------------+--------------------------------------+

Boot volume of Nova instance is in Cinder

    # nova show admin_vm01 | egrep "Property|image|os-extended-volumes:volumes_attached"
    | Property                             | Value                                                    |
    | image                                | Attempt to boot from volume - no image supplied          |
    | os-extended-volumes:volumes_attached | [{"id": "5a272756-ab0c-4311-a1ce-3f1736d167df"}]         |

#### Cinder list

    # cinder list
    +--------------------------------------+-----------+--------------+------+-------------+----------+--------------------------------------+
    |                  ID                  |   Status  | Display Name | Size | Volume Type | Bootable |             Attached to              |
    +--------------------------------------+-----------+--------------+------+-------------+----------+--------------------------------------+
    | 5a272756-ab0c-4311-a1ce-3f1736d167df |   in-use  | admin_vol01  |  1   |     None    |   true   | ed831ace-39ef-4960-8bae-a035d292c305 |
    +--------------------------------------+-----------+--------------+------+-------------+----------+--------------------------------------+


### Migrate Nova instance

#### Migration from node-28 of AZ:nova to node-31 of AZ:nova2

    # nova live-migration admin_vm01 node-31

#### Check the migration result

Nova instance is moved from node-28 of AZ:nova to node-31 of AZ:nova2

    # nova list --field name,status,,OS-EXT-STS:vm_state,OS-EXT-AZ:availability_zone,OS-EXT-SRV-ATTR:hypervisor_hostname
    +--------------------------------------+------------+--------+--+----------------------+------------------------------+--------------------------------------+
    | ID                                   | Name       | Status |  | OS-EXT-STS: Vm State | OS-EXT-AZ: Availability Zone | OS-EXT-SRV-ATTR: Hypervisor Hostname |
    +--------------------------------------+------------+--------+--+----------------------+------------------------------+--------------------------------------+
    | ed831ace-39ef-4960-8bae-a035d292c305 | admin_vm01 | ACTIVE |  | active               | nova2                        | node-31                              |
    +--------------------------------------+------------+--------+--+----------------------+------------------------------+--------------------------------------+

#### Cinder status

    # nova show admin_vm01 | egrep "Property|image|os-extended-volumes:volumes_attached"
    | Property                             | Value                                                    |
    | image                                | Attempt to boot from volume - no image supplied          |
    | os-extended-volumes:volumes_attached | [{"id": "5a272756-ab0c-4311-a1ce-3f1736d167df"}]         |

    # cinder list
    +--------------------------------------+-----------+--------------+------+-------------+----------+--------------------------------------+
    |                  ID                  |   Status  | Display Name | Size | Volume Type | Bootable |             Attached to              |
    +--------------------------------------+-----------+--------------+------+-------------+----------+--------------------------------------+
    | 5a272756-ab0c-4311-a1ce-3f1736d167df |   in-use  | admin_vol01  |  1   |     None    |   true   | ed831ace-39ef-4960-8bae-a035d292c305 |
    +--------------------------------------+-----------+--------------+------+-------------+----------+--------------------------------------+



## [Case2] Migrate Nova instance (w/ Cinder volume)

### Initial State

#### Hypervisor (Compute node)

    # nova hypervisor-list
    +----+-----------------------+
    | ID | Hypervisor hostname   |
    +----+-----------------------+
    | 6  | node-27               |
    | 9  | node-28               |
    | 15 | node-31               |
    +----+-----------------------+

#### AZ

    # nova availability-zone-list | egrep -A 10 "^\| nova"
    | nova                     | available                              |
    | |- node-27               |                                        |
    | | |- nova-compute        | enabled :-) 2015-02-24T08:40:02.000000 |
    | |- node-28               |                                        |
    | | |- nova-compute        | enabled :-) 2015-02-24T08:39:55.000000 |
    | nova2                    | available                              |
    | |- node-31               |                                        |
    | | |- nova-compute        | enabled :-) 2015-02-24T08:40:02.000000 |
    +--------------------------+----------------------------------------+

#### Nova instance is on node-28

    # nova list --field name,status,,OS-EXT-STS:vm_state,OS-EXT-AZ:availability_zone,OS-EXT-SRV-ATTR:hypervisor_hostname
    +--------------------------------------+------------+--------+--+----------------------+------------------------------+--------------------------------------+
    | ID                                   | Name       | Status |  | OS-EXT-STS: Vm State | OS-EXT-AZ: Availability Zone | OS-EXT-SRV-ATTR: Hypervisor Hostname |
    +--------------------------------------+------------+--------+--+----------------------+------------------------------+--------------------------------------+
    | 8e6a33c1-1564-4d63-8964-f10a6d66e2c2 | admin_vm01 | ACTIVE |  | active               | nova                         | node-28                              |
    +--------------------------------------+------------+--------+--+----------------------+------------------------------+--------------------------------------+

Boot volume of Nova instance is in Cinder
Nova instance has one additional Cinder volume

    # nova show admin_vm01 | egrep "Property|image|os-extended-volumes:volumes_attached"
    | Property                             | Value                                                                                            |
    | image                                | Attempt to boot from volume - no image supplied                                                  |
    | os-extended-volumes:volumes_attached | [{"id": "5a272756-ab0c-4311-a1ce-3f1736d167df"}, {"id": "7bf75168-8370-45f8-b1c5-e65926605960"}] |

#### Cinder list

    # cinder list
    +--------------------------------------+-----------+--------------+------+-------------+----------+--------------------------------------+
    |                  ID                  |   Status  | Display Name | Size | Volume Type | Bootable |             Attached to              |
    +--------------------------------------+-----------+--------------+------+-------------+----------+--------------------------------------+
    | 5a272756-ab0c-4311-a1ce-3f1736d167df |   in-use  | admin_vol01  |  1   |     None    |   true   | 8e6a33c1-1564-4d63-8964-f10a6d66e2c2 |
    | 7bf75168-8370-45f8-b1c5-e65926605960 |   in-use  | admin_vol11  |  1   |     None    |  false   | 8e6a33c1-1564-4d63-8964-f10a6d66e2c2 |
    +--------------------------------------+-----------+--------------+------+-------------+----------+--------------------------------------+

#### Instance

    $ ssh cirros@<INSTANCE> lsblk
    NAME   MAJ:MIN RM    SIZE RO TYPE MOUNTPOINT
    vda    253:0    0      1G  0 disk
    `-vda1 253:1    0 1011.9M  0 part /
    vdb    253:16   0      1G  0 disk
    `-vdb1 253:17   0   1023M  0 part /mnt/vol01

    $ ssh cirros@<INSTANCE> df -h /mnt/vol01/
    Filesystem                Size      Used Available Use% Mounted on
    /dev/vdb1              1006.9M     17.3M    938.5M   2% /mnt/vol01


### Migrate Nova instance

#### Migration from node-28 of AZ:nova to node-31 of AZ:nova2

    # nova live-migration admin_vm01 node-31

#### Check the migration result

Nova instance is moved from node-28 of AZ:nova to node-31 of AZ:nova2

    # nova list --field name,status,,OS-EXT-STS:vm_state,OS-EXT-AZ:availability_zone,OS-EXT-SRV-ATTR:hypervisor_hostname
    +--------------------------------------+------------+--------+--+----------------------+------------------------------+--------------------------------------+
    | ID                                   | Name       | Status |  | OS-EXT-STS: Vm State | OS-EXT-AZ: Availability Zone | OS-EXT-SRV-ATTR: Hypervisor Hostname |
    +--------------------------------------+------------+--------+--+----------------------+------------------------------+--------------------------------------+
    | 8e6a33c1-1564-4d63-8964-f10a6d66e2c2 | admin_vm01 | ACTIVE |  | active               | nova2                        | node-31                              |
    +--------------------------------------+------------+--------+--+----------------------+------------------------------+--------------------------------------+

Boot volume of Nova instance is in Cinder
Nova instance has one additional Cinder volume

    # nova show admin_vm01 | egrep "Property|image|os-extended-volumes:volumes_attached"
    | Property                             | Value                                                                                            |
    | image                                | Attempt to boot from volume - no image supplied                                                  |
    | os-extended-volumes:volumes_attached | [{"id": "5a272756-ab0c-4311-a1ce-3f1736d167df"}, {"id": "7bf75168-8370-45f8-b1c5-e65926605960"}] |

#### Instance

    $ ssh cirros@<INSTANCE> lsblk
    NAME   MAJ:MIN RM    SIZE RO TYPE MOUNTPOINT
    vda    253:0    0      1G  0 disk
    `-vda1 253:1    0 1011.9M  0 part /
    vdb    253:16   0      1G  0 disk
    `-vdb1 253:17   0   1023M  0 part /mnt/vol01

    $ ssh cirros@<INSTANCE> df -h /mnt/vol01/
    Filesystem                Size      Used Available Use% Mounted on
    /dev/vdb1              1006.9M     17.3M    938.5M   2% /mnt/vol01

## 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