vSphere Tags were introduced in version 5.1 as a way to organize inventory objects such as VMs, Hosts, Datastores, etc., a much-needed feature for helping search for or group objects within vSphere. A Tag is basically a label that can be applied to vSphere inventory objects. When an administrator creates a tag, it is then assigned to a tag category. Categories allow the grouping of related tags. When a Category is created, you can specify associations of object types (such as; VM or Datastore) as well as whether more than one tag in a category can be applied to an object (ex; One Tag or Many Tags).
Although vSphere documentation has existed for working with tags, there has not been much available in regards to how tagging performance or scale can potentially affect an environment. A white paper on this topic was released near the end of 2019, VMware vSphere 6.7 Tagging Best Practices by Ravi Soundararajan, Principal Engineer in the Performance Engineering group at VMware.
vSphere 6.7 Tags
Ravi covers tagging from top to bottom starting with vSphere 5.1 when tags were introduced, to common terminology used when discussing tags, using tagging APIs whether in Java or PowerShell, Scale and Performance as they relate to tag operations, and also touches on Tags vs. Custom Attributes.
The whitepaper also contains a few bits of both Java & PowerCLI code to help get started right after reading. Examples below:
11.2.9 Example J8: List VMs associated with a tag (pg.27)
// List tags associated with tagId from above
// Assumes tagAssociation object from above
List<DynamicID> retDynamicIds = tagAssociation.listAttachedObjects(tagId);
11.3.2 Example P1: List tags associated with a VM (pg.28)
$allCategoryMethodSVC = Get-CisService com.vmware.cis.tagging.category
$alltagMethodSVC = Get-CisService com.vmware.cis.tagging.tag
$allTagAssociationMethodSVC = Get-CisService com.vmware.cis.tagging.tag_association
# Use first VM from above list
$useThisVMID = $useTheseVMIDs
$tagList = $allTagAssociationMethodSVC.list_attached_tags($useThisVMID)
This resource is quite invaluable to those looking to use vSphere tags efficiently and effectively.
To learn more about vSphere Tags and relevant tooling, please review these resources:
- Writing Performant Tagging Code: Tips and Tricks for PowerCLI (Ravi Soundararajen and Joseph Zuk – 2019, June)
- Tagging Service SDK (PowerCLI)
- PowerCLI SDK
- Package com.vmware.cis.tagging (API Component for Tags)
- VMware vSphere Automation SDK for Java
- vSphere Tags and Attributes (VMware Docs)