You can create various types of policies, list all policies on a vCenter Server instance, list and filter tags used by policies.

Procedure

  1. Create an anti_affinity_with_vcls policy.
    POST https://<vcenter_ip_address_or_fqdn>/api/vcenter/compute/policies

    The following example create_spec specifies the policy details.

    {
      "spec": {
        "@class":"com.vmware.vcenter.compute.policies.capabilities.anti_affinity_with_vcls.create_spec",
        "name":"az_policy",
        "host_tag":"urn:vmomi:InventoryServiceTag:adf08d0c-a4e4-4c15-8798-c9a4d6873820:GLOBAL",
        "description":"az_policy description",
        "vm_tag":"urn:vmomi:InventoryServiceTag:adf08d0c-a4e4-4c15-8798-c9a4d6873820:GLOBAL"
      }
    }

    The following is an example response that contains the policy ID.

    {
        "value": "178aaf62-06e7-4958-bff9-841674633a3f"
    }
  2. List all policies on a vCenter Server instance.
    GET https://<vcenter_ip_address_or_fqdn>/api/vcenter/compute/policies

    The following is an example response that contains the available policies.

    {
        "value": [
            {
                "capability": "com.vmware.vcenter.compute.policies.capabilities.anti_affinity_with_vcls",
                "name": "az_policy",
                "description": "az_policy description",
                "policy": "178aaf62-06e7-4958-bff9-841674633a3f"
            }
        ]
    }
  3. List tags used by one or all policies defined on a vCenter Server instance.
    GET https://<vcenter_ip_address_or_fqdn>/api/vcenter/compute/policies/tag-usage

    The following is an example response that contains the available tags.

    {
        "value": [
            {
                "category_name": "AZ_vms",
                "tag_type": "com.vmware.cis.tagging.Tag:VirtualMachine",
                "tag_name": "vm_us_west_a",
                "tag": "urn:vmomi:InventoryServiceTag:eefb3b11-afa2-4b44-a389-e94065004548:GLOBAL",
                "policy": "178aaf62-06e7-4958-bff9-841674633a3f"
            },
            {
                "category_name": "AZ_hosts",
                "tag_type": "com.vmware.cis.tagging.Tag:HostSystem",
                "tag_name": "host_us_west_b",
                "tag": "urn:vmomi:InventoryServiceTag:5b3564f4-a762-4480-9145-0f87d28aea78:GLOBAL",
                "policy": "178aaf62-06e7-4958-bff9-841674633a3f"
            }
        ]
    }
  4. Filter tags used by one or all policies defined on a vCenter Server instance by policy ID, tag UUID, and tag type.
    GET https://<vcenter_ip_address_or_fqdn>/api/vcenter/compute/policies/tag-usage?filter.policies=178aaf62-06e7-4958-bff9-841674633a3f&filter.tags=urn:vmomi:InventoryServiceTag:5b3564f4-a762-4480-9145-0f87d28aea78:GLOBAL&filter.tag_types=com.vmware.cis.tagging.Tag:HostSystem

    The following is an example response that contains the filtered tag.

    {
        "value": [
            {
                "category_name": VMC_AZ_hosts",
                "tag_type": "com.vmware.cis.tagging.Tag:HostSystem",
                "tag_name": "host_us_west_a",
                "tag": "urn:vmomi:InventoryServiceTag:5b3564f4-a762-4480-9145-0f87d28aea78:GLOBAL",
                "policy": "178aaf62-06e7-4958-bff9-841674633a3f"
            }
        ]
    }