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

  • Verify that you are logged in as a system administrator.

  • 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.
    Important: You must set vcloud:IsMandatory to true for affinity and anti-affinity rules.

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>