To update or remove an affinity rule, use the edit and remove links in the rule.

Prerequisites

  • This operation requires the rights included in the predefined vApp Author role or an equivalent set of rights.

  • To update or delete an affinity rule, you must be the owner of all virtual machines specified in the rule.

  • To update or remove the rule, you must know the href value of the rule. This value is returned when you create the rule (see Create a VM-VM Affinity Rule). You can retrieve a list of all your affinity rules from a VDC by making a GET request to this link in the VDC.
    <Link rel="down" href="https://vcloud.example.com/api/vdc/44/vmAffinityRules/"
        type="application/vnd.vmware.vcloud.vmaffinityrules+xml"/>

Procedure

  1. Retrieve the XML representation of the rule.
    Use a request like this one.
    GET https://vcloud.example.com/api/vmAffinityRule/edf7c...
  2. Examine the response to locate the Link elements that contain the URLs for modifying or deleting the rule.
    <VmAffinityRule ...>
       ...
       <Link
          rel="edit"
          href="https://vcloud.example.com/api/vmAffinityRule/edf7c..."
          type="application/vnd.vmware.vcloud.vmaffinityrule+xml" />
       <Link
          rel="remove"
          href="https://vcloud.example.com/api/vmAffinityRule/edf7c..." />
       ...
    </VmAffinityRule>
  3. Use one of these links to update or delete the rule.
    Option Description
    To update the rule: Make a PUT request to the rule's edit URL and supply a VmAffinityRule as the body. See Update a VM-VM Affinity Rule.
    To delete the rule: Make a DELETE request to the rule's remove URL.

Example: Update a VM-VM Affinity Rule

This request updates the an affinity rule created in Create a VM-VM Affinity Rule to add a third virtual machine.

Request:
PUT https://vcloud.example.com/api/vmAffinityRule/edf7c...
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>
   <Polarity>Affinity</Polarity>
   <VmReferences>
      <VmReference href="https://vcloud.example.com/api/vApp/vm-44" />
      <VmReference href="https://vcloud.example.com/api/vApp/vm-200" />
 <VmReference href="https://vcloud.example.com/api/vApp/vm-133" />
   </VmReferences>
</VmAffinityRule>

The response is a Task.

Response:
<?xml version="1.0" encoding="UTF-8"?>
<Task
   ...
   operationName="affinityRuleUPdate"
   ... >
   <Owner  
      href="https://vcloud.example.com/api/vmAffinityRule/edf7c456-a69c-48b1-89a8-4e9674448e01"  
      name="example_name"  
      type="application/vnd.vmware.vcloud.vmaffinityrule+xml" />
   ...    
</Task>