Red Hat Training

A Red Hat training course is available for Red Hat Virtualization

6.11. Affinity Groups

Virtual machine affinity allows you to define sets of rules that specify whether certain virtual machines run together on the same host or run separately on different hosts. This allows you to create advanced workload scenarios for addressing challenges such as strict licensing requirements and workloads demanding high availability.
Virtual machine affinity is applied to virtual machines by adding virtual machines to one or more affinity groups. An affinity group is a group of two or more virtual machines for which a set of identical parameters and conditions apply. These parameters include positive (run together) affinity that ensures the virtual machines in an affinity group run on the same host, and negative (run independently) affinity that ensures the virtual machines in an affinity group run on different hosts.
A further set of conditions can then be applied to these parameters. For example, you can apply hard enforcement, which is a condition that ensures the virtual machines in the affinity group run on the same host or different hosts regardless of external conditions, or soft enforcement, which is a condition that indicates a preference for virtual machines in an affinity group to run on the same host or different hosts when possible.
The combination of an affinity group, its parameters, and its conditions is known as an affinity policy. Affinity policies are applied to running virtual machines immediately, without having to restart.

Note

Affinity groups are applied to virtual machines on the cluster level. When a virtual machine is moved from one cluster to another, that virtual machine is removed from all affinity groups in the source cluster.

Important

Affinity groups will only take effect when the VmAffinityGroups filter module or weights module is enabled in the scheduling policy applied to clusters in which affinity groups are defined. The VmAffinityGroups filter module is used to implement hard enforcement, and the VmAffinityGroups weights module is used to implement soft enforcement.

6.11.1. Creating an Affinity Group

You can create new affinity groups in the Administration Portal.

Procedure 6.18. Creating Affinity Groups

  1. Click the Virtual Machines tab and select a virtual machine.
  2. Click the Affinity Groups tab in the details pane.
  3. Click New.
  4. Enter a Name and Description for the affinity group.
  5. Select the Positive check box to apply positive affinity, or ensure this check box is cleared to apply negative affinity.
  6. Select the Enforcing check box to apply hard enforcement, or ensure this check box is cleared to apply soft enforcement.
  7. Use the drop-down list to select the virtual machines to be added to the affinity group. Use the + and - buttons to add or remove additional virtual machines.
  8. Click OK.

6.11.2. Editing an Affinity Group

Procedure 6.19. Editing Affinity Groups

  1. Click the Virtual Machines tab and select a virtual machine.
  2. Click the Affinity Groups tab in the details pane.
  3. Click Edit.
  4. Change the Positive and Enforcing check boxes to the preferred values and use the + and - buttons to add or remove virtual machines to or from the affinity group.
  5. Click OK.

6.11.3. Removing an Affinity Group

Procedure 6.20. Removing Affinity Groups

  1. Click the Virtual Machines tab and select a virtual machine.
  2. Click the Affinity Groups tab in the details pane.
  3. Click Remove.
  4. Click OK.
The affinity policy that applied to the virtual machines that were members of that affinity group no longer applies.