A VM-Host affinity rule specifies a relationship between a host group and a VM group in the same resource pool. A system administrator can create, enable, disable or delete a VM-Host affinity rule.

After you create a VM-Host affinity rule, you can update it in the following ways:
  • Enable the rule.
  • Disable the rule.
  • Delete the rule.

To make any other change (for example, to change the VM Group or Host Group), you must create a new rule.

vSphere VM-Host affinity rules that are created in resource pools that are mapped to a Provider VDC appear in each pool shown in the Resource Pools list under vSphere Properties. vSphere VM-Host affinity rules that are created in a resource pool that is mapped to a Provider VDC are listed in the VMWVmHostAffinityRules element of the VMWProviderVdc response. For more information about host DRS VM-Host affinity, see the VMware vSphere ESXi and vCenter Server Documentation.

Prerequisites

  • This operation is restricted to system administrators.

  • You cannot create VM-Host affinity rule in a resource pool that does not contain at least one host group and one VM group.

Procedure

  1. Choose a resource pool to contain the rule.
    Select a resource pool from the Resource Pools list under vSphere Properties. VM-Host affinity rules in the resource pool are listed on its Affinity Rules tab.
    Each VMWProviderVdcResourcePool element in a VMWProviderVdcResourcePoolSet response contains a link that you can use to retrieve or update the set of VM-Host affinity rules in the resource pool.
    <?xml version="1.0" encoding="UTF-8"?>
    <vmext:VMWProviderVdcResourcePoolSet
       xmlns:vmext="http://www.vmware.com/vcloud/extension/v1.5"
       xmlns:vcloud="http://www.vmware.com/vcloud/v1.5">
       ...
       <vmext:VMWProviderVdcResourcePool
          primary="true">
          ...
          <vcloud:Link
             rel="down"
             href="https://vcloud.example.com/api/admin/extension/resourcePool/6/hostGroups"
             type="application/vnd.vmware.admin.vmwHostGroupsType+xml" />
          <vcloud:Link
             rel="down"
             href="https://vcloud.example.com/api/admin/extension/resourcePool/6/vmGroups"
             type="application/vnd.vmware.admin.vmwVmGroupType+xml" />
          <vcloud:Link
             rel="add"
             href="https://vcloud.example.com/api/admin/extension/resourcePool/6/vmGroups"
             type="application/vnd.vmware.admin.vmwVmGroupType+xml" />
          <vcloud:Link
             rel="add"
             href="https://vcloud.example.com/api/admin/extension/resourcePool/6/rules"
             type="application/vnd.vmware.admin.vmwVmHostAffinityRules+xml" />
          <vcloud:Link
             rel="down"
             href="https://vcloud.example.com/api/admin/extension/resourcePool/6/rules"
             type="application/vnd.vmware.admin.vmwVmHostAffinityRules+xml" />
          ...
       </vmext:VMWProviderVdcResourcePool>
       ...
    </vmext:VMWProviderVdcResourcePoolSet>
    To retrieve the list of VM-Host affinity rules in a resource pool, use a request like the one shown in Create a VM-Host Affinity Rule
  2. Create a VMWVmHostAffinityRule element and POST it to the add link for rules in the resource pool.
  3. To create a VM-Host affinity rule in the resource pool, click the plus sign icon on the Affinity Rules tab to open the New VM-Host Affinity Rule window.
    You must specify a name, VM Group, and Host Group for the rule.
    1. Type a name for the rule in the Rule Name field.
    2. Select a VM Group and a Host Group to which the rule applies.
      Use the drop-down menus to list all VM groups and host groups in the selected resource pool. If the resource pool does not contain at least one VM group and one host group, you cannot create a rule.
    3. Specify the polarity of the rule. Click Must run on hosts to create an affinity rule. Click Must not run on hosts to create an anti-affinity rule.
    4. Enable or disable the rule.
    5. Specify whether or not the rule is mandatory.
      Mandatory rules are more likely to cause conflicts that can affect system behavior, especially where a VM is the subject of multiple mandatory rules. See Affinity Rule Interactions and Conflicts.
  4. To enable, disable, or remove an existing VM-Host affinity rule, right-click the rule name on the Affinity Rules tab and select one of the available actions.

Example: Create a VM-Host Affinity Rule

This example creates and enables a rule that binds the Host Group shown in Host Groups in a Resource Pool to the VM Group created in Create a VM Group.

Request:
POST https://vcloud.example.com/api/admin/extension/resourcePool/6/rules
...
<?xml version="1.0" encoding="UTF-8"?>
<vmext:VMWVmHostAffinityRule
   xmlns:vmext="http://www.vmware.com/vcloud/extension/v1.5"
   xmlns:vcloud="http://www.vmware.com/vcloud/v1.5"
   type="application/vnd.vmware.admin.vmwVmHostAffinityRule+xml">
   <vcloud:Name>MSSQL-VMs</vcloud:Name>
   <vcloud:IsEnabled>true</vcloud:IsEnabled>
   <vcloud:IsMandatory>true</vcloud:IsMandatory>
   <vcloud:Polarity>Affinity</vcloud:Polarity>
   <vmext:HostGroupName>HostGroup-MSSQL</vmext:HostGroupName>
   <vmext:VmGroupName>ExampleGroup</vmext:VmGroupName>
</vmext:VMWVmHostAffinityRule>
The response is a Task. When the task completes, you can make a request like this one to see the new rule and others in this resource pool. Each rule contains links you can use to enable, disable, or delete the rule.
GET https://vcloud.example.com/api/admin/extension/resourcePool/6/rules
...
<vmext:VMWVmHostAffinityRules ...>
   <vcloud:Link
      rel="add"
      href="https://vcloud.example.com/api/admin/extension/resourcePool/6/rules"
      type="application/vnd.vmware.admin.vmwVmHostAffinityRule+xml" />
   <vmext:VmHostAffinityRule
      id="85"
      href="https://vcloud.example.com/api/admin/extension/rule/85"
      type="application/vnd.vmware.admin.vmwVmHostAffinityRule+xml">
      <vcloud:Link
         rel="down"
         href="https://vcloud.example.com/api/admin/extension/hostGroup/5"
         type="application/vnd.vmware.admin.vmwHostGroupType+xml" />
      <vcloud:Link
         rel="down"
         href="https://vcloud.example.com/api/admin/extension/vmGroup/34"
         type="application/vnd.vmware.admin.vmwVmGroupType+xml" />
      <vcloud:Link
         rel="disable"
         href="https://vcloud.example.com/api/admin/extension/rule/85/action/disable" />
      <vcloud:Link
         rel="remove"
         href="https://vcloud.example.com/api/admin/extension/rule/85" />
      vcloud:Name>MSSQL-VMs</vcloud:Name>
      <vcloud:IsEnabled>true</vcloud:IsEnabled>
      <vcloud:IsMandatory>true</vcloud:IsMandatory>
      <vcloud:Polarity>Affinity</vcloud:Polarity>
      <vmext:HostGroupName>HostGroup-MSSQL</vmext:HostGroupName>
      <vmext:VmGroupName>ExampleGroup</vmext:VmGroupName>
   </vmext:VmHostAffinityRule>
      ...
   <vmext:VmHostAffinityRule>
   </vmext:VmHostAffinityRule>
      ...
   <vmext:VmHostAffinityRule>
</vmext:VMWVmHostAffinityRules>