You must create a category and specify the associable types and cardinality for the tags that make up the category. After you create a category, you can create tags for the category.

Procedure

  1. Create a tagging category.
    POST https://<vcenter_ip_address_or_fqdn>/api/com/vmware/cis/tagging/category

    The following example create_spec specifies the associable types and cardinality for the tags that make up the category.

    {
        "create_spec": {
            "associable_types": [
                "HostSystem"
            ],
            "cardinality": "SINGLE",
            "description": "cat-4-desc",
            "name": "cat-4"
        }
    }

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

    {
        "value": "urn:vmomi:InventoryServiceCategory:ce8902ef-b5e0-4aab-8ffa-ec67b15eb336:GLOBAL"
    }
  2. Create a tag for the tagging category.
    POST https://<vcenter_ip_address_or_fqdn>/api/com/vmware/cis/tagging/tag

    The following example create_spec specifies the ID of the category for which you create the tag.

    {
        "create_spec": {
            "category_id": "urn:vmomi:InventoryServiceCategory:ce8902ef-b5e0-4aab-8ffa-ec67b15eb336:GLOBAL",
            "description": "tag-1-desc",
            "name": "tag-1"
        }
    }

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

    {
        "value": "urn:vmomi:InventoryServiceTag:a8d0d278-edd1-4a79-86ac-fa9384595062:GLOBAL"
    }
  3. List all tags on a vCenter Server instance.
    GET https://<vcenter_ip_address_or_fqdn>/api/com/vmware/cis/tagging/tag

    The following is an example response that contains the ID of the available tag.

    {
        "value": [
            "urn:vmomi:InventoryServiceTag:a8d0d278-edd1-4a79-86ac-fa9384595062:GLOBAL"
        ]
    }
  4. List all virtual machines in the inventory.
    GET https://<vcenter_ip_address_or_fqdn>/api/vcenter/vm

    The following is an example response that contains details about the available virtual machine.

    {
        "value": [
            {
                "memory_size_MiB": 40,
                "vm": "vm-21",
                "name": "a_vm",
                "power_state": "POWERED_OFF",
                "cpu_count": 1
            }
        ]
    }
  5. Attach a tag to a virtual machine.
    POST https://<vcenter_ip_address_or_fqdn>/api/com/vmware/cis/tagging/tag-association/id:<tag-id>?~action=attach

    The following example specifies the details of the virtual machine you want to attach.

    {
        "object_id": {
            "id": "vm-21",
            "type": "VirtualMachine"
        }
    }

    If the response is empty, the operation is successful.

  6. List all tags attached to a virtual machine.
    POST https://<vcenter_ip_address_or_fqdn>/api/com/vmware/cis/tagging/tag-association?~action=list-attached-tags

    The following example specifies the details of the virtual machine for which you want to list the attached tags.

    {
        "object_id": {
            "id": "vm-21",
            "type": "VirtualMachine"
        }
    }

    The following is an example response that contains the ID of the attached tag.

    {
        "value": [
            "urn:vmomi:InventoryServiceTag:a8d0d278-edd1-4a79-86ac-fa9384595062:GLOBAL"
        ]
    }

What to do next

You can create and manage compute policies. See Create, List, and Use Policies.