A VM-VM affinity rule applies to two or more virtual machines and specifies whether they should be deployed on the same host or on separate hosts. VM-VM affinity rules are properties of an organization VDC, and apply to virtual machines deployed on the hosts that back that VDC.
- A rule with a Polarity value of Affinity specifies two or more virtual machines that the system should deploy on the same host. This kind of rule is commonly applied in cases where virtual machines can realize performance benefits from being placed on a single host and are running workloads where failure of that host can be tolerated.
- A rule with a Polarity value of Anti-Affinity specifies two or more virtual machines that the system should deploy on separate hosts. This kind of rule is commonly applied in cases where virtual machines are intended to support redundancy, availability, and similar uses that must not be affected by the failure of one host.
- A virtual machine can be referenced in no more than one VMware Cloud Director affinity rule.
- A virtual machine can be referenced in no more than one VMware Cloud Director anti-affinity rule.
Prerequisites
-
This operation requires the rights included in the predefined vApp Author role or an equivalent set of rights.Verify that you are logged in to the vCloud Air Compute Service as an End User.
-
To create an affinity rule, you must be the owner of all virtual machines specified in the rule.
Procedure
Example: Create a VM-VM Affinity Rule
This request creates an affinity rule for two virtual machines.
POST https://vcloud.example.com/api/vdc/44/vmAffinityRules Content-Type: application/vnd.vmware.vcloud.vmaffinityrule+xml ... <?xml version="1.0" encoding="UTF-8"?> <VmAffinityRule xmlns="http://www.vmware.com/vcloud/v1.5"> <Name>example-affinity-rule</Name> <IsEnabled>true</IsEnabled> <IsMandatory>false</IsMandatory> <Polarity>Affinity</Polarity> <Scope>Host</Scope> <VmReferences> <VmReference href="https://vcloud.example.com/api/vApp/vm-44" /> <VmReference href="https://vcloud.example.com/api/vApp/vm-200" /> </VmReferences> </VmAffinityRule>If either of the referenced virtual machines is already the subject of an affinity rule, the request fails with an error message indicating the reason for the failure.
The response is a Task. Note the href of the Owner element in the returned Task. This is the ID of the rule. You must use it when you delete or update the rule.
<?xml version="1.0" encoding="UTF-8"?> <Task ... operationName="affinityRuleCreate" ... > <Owner href="https://vcloud.example.com/api/vmAffinityRule/edf7c456-a69c-48b1-89a8-4e9674448e01" name="example_name" type="application/vnd.vmware.vcloud.vmaffinityrule+xml" /> ... </Task>
When you create or update an anti-affinity rule, the system might need to create a place-holder virtual machine to satisfy the vCenter requirement that such rules include at least two virtual machines. This place-holder is visible to vCenter administrators, but is not visible in VMware Cloud Director. It is never powered on.