Understanding Affinity and Anti-Affinity

asked 2016-04-26 18:11:17 -0500

RedCricket gravatar image

updated 2016-04-26 18:11:50 -0500

Hi,

I am new to OpenStack and virtualization in general. I believe that if 2 VMs have "affinity" they will reside on the same compute node/hypervisor and if they have "anti-affinity" they will reside on different compute nodes. With that in mind I did these test with some cirros images.

    [root@os-mgmt-001 ~]# nova server-group-create gr-anti anti-affinity
    +--------------------------------------+---------+--------------------+---------+----------+
    | Id                                   | Name    | Policies           | Members | Metadata |
    +--------------------------------------+---------+--------------------+---------+----------+
    | cec8e205-1a70-4a80-b28e-0b643c0d824b | gr-anti | [u'anti-affinity'] | []      | {}       |
    +--------------------------------------+---------+--------------------+---------+----------+
    [root@os-mgmt-001 ~]# nova server-group-list
    +--------------------------------------+---------+--------------------+---------+----------+
    | Id                                   | Name    | Policies           | Members | Metadata |
    +--------------------------------------+---------+--------------------+---------+----------+
    | cec8e205-1a70-4a80-b28e-0b643c0d824b | gr-anti | [u'anti-affinity'] | []      | {}       |
    +--------------------------------------+---------+--------------------+---------+----------+
    [root@os-mgmt-001 ~]# nova server-group-get cec8e205-1a70-4a80-b28e-0b643c0d824b
    +--------------------------------------+---------+--------------------+---------+----------+
    | Id                                   | Name    | Policies           | Members | Metadata |
    +--------------------------------------+---------+--------------------+---------+----------+
    | cec8e205-1a70-4a80-b28e-0b643c0d824b | gr-anti | [u'anti-affinity'] | []      | {}       |
    +--------------------------------------+---------+--------------------+---------+----------+

Then I booted a couple of cirros images like so:

nova boot --hint group=cec8e205-1a70-4a80-b28e-0b643c0d824b --nic net-id=$net_id --image $image --flavor 2 test-005

nova boot --hint group=cec8e205-1a70-4a80-b28e-0b643c0d824b --nic net-id=$net_id --image $image --flavor 2 test-500

They end up in the group as I can demonstrate:

[root@ost-mgmt-001 ~]# nova server-group-get cec8e205-1a70-4a80-b28e-0b643c0d824b
+--------------------------------------+---------+--------------------+------------------------------------------------------------------------------------+----------+
| Id                                   | Name    | Policies           | Members                                                                            | Metadata |
+--------------------------------------+---------+--------------------+------------------------------------------------------------------------------------+----------+
| cec8e205-1a70-4a80-b28e-0b643c0d824b | gr-anti | [u'anti-affinity'] | [u'6ab61386-658e-4bad-9b81-a595e0aeef47', u'0fa01909-77ab-4d9f-b675-3511c5449dad'] | {}       |
+--------------------------------------+---------+--------------------+------------------------------------------------------------------------------------+----------+

Then I live migrate the cirros instances to the same compute node like so:

  nova live-migration test-005 ost-neut-002
  nova live-migration test-500 ost-neut-002

And both the nodes stay on the same compute node ...

[root@ost-mgmt-001 ~]# nova show test-005 | grep 002
| OS-EXT-SRV-ATTR:host                           | ost-neut-002                             |
| OS-EXT-SRV-ATTR:hypervisor_hostname  | ost-neut-002.example.com             |
[root@ost-mgmt-001 ~]# nova show test-500 | grep 002
| OS-EXT-SRV-ATTR:host                           | ost-neut-002                             |
| OS-EXT-SRV-ATTR:hypervisor_hostname  | ost-neut-002.example.com             |

... I was expecting one of the cirros instances would have to move off of ost-neut-002?

edit retag flag offensive close merge delete