This evening I was reading a new blog post Tagging: An Invisible Feature in vSphere by Steve Jin in which he describes a hidden vSphere feature for tagging particular managed entities in your vSphere environment. The main consumer of this hidden feature is primarily VMware and it provides a level of meta data tagging to denote the importance of an entity. These tags are used in workflows in various vSphere products such as vCenter Server, vCenter Update Manager and View to just name a few.
Here is a screenshot of a VM entity using the vSphere MOB and as you can see from the tags, VMware can identify that this particular VM is running both vCenter Server and vCenter Update Manager.
If you have a VM that is a View Replica/Linked Clone, you may see these tags associated with the VM:
SYSTEM/COM.VMWARE.SIM.SVIMANAGEDOBJECT
SYSTEM/COM.VMWARE.VIM.SVIMANAGEDOBJECT
This feature can be really useful to allow users to tag particular objects in their environment of importance and easily correlate/integrate with a provisioning system and/or CMDB without having to resort to a separate database to store the meta data. You might say that custom fields exists today that can provide the same level of functionality, but they are actually pretty limited in scope. It only allows you to create custom attributes at a global vCenter level, host and virtual machine but not all managed objects such as Datastore, Networks, Resource Pool, etc.
So what if you wanted to create your own custom tags? Since these are hidden methods from VMware and they are not exposed through the public vSphere API, how might we access it? I spent a few minutes of digging and I was able to identify the two methods that pertained to tag management in the vSphere API:
addTag - Adds a tag to a managed entity
removeTag - Removes a tag to a managed entity
You can access both of these methods using the vSphere MOB as none of the official vSphere SDKs have these methods implemented. These methods are only supported when connecting to vCenter Server and are not exposed at an ESX(i) level.
In this example, I will create a custom tag at the Datacenter level called "WWW.VIRTUALLYGHETTO.COM"
Here is the path to a Datacenter object using the vSphere MOB:
If we scroll down on the page, you will notice a property called "tag" and as you can see in the screenshot below, no tags have been defined:
I will now craft the URL to the "addTag" method using the Datacenter as a point of reference:
https://reflex.primp-industries.com/mob/?moid=datacenter-1246&method=addTag
As you can see the method accepts an array of tags which can be defined within the section. All tags MUST begin with "SYSTEM/" and then a unique string following, in our example I used "SYSTEM/WWW.VIRTUALLYGHETTO.COM". Once you have created your tag, you will then click on the "Invoke Method" to add the tag. Since this method does not return anything, the return result is void.
Now if we go back to the Datacenter page and refresh the page, you should see the new tag that was just created:
To delete a tag, you will generate the same URL but replace "add" with "remove":
https://reflex.primp-industries.com/mob/?moid=datacenter-1246&method=removeTag
You will again fill in the tags to be removed and then click on "Invoke Method":
As you can see, you now have the power to create your own tags on various managed entities in your vSphere environment. If you want to automate this through a script or command line, you can create simple HTTP POST operations to the vSphere MOB or create the appropriate interface methods to the SDK bindings to support these hidden methods. I'll leave the latter as an exercise for the readers.
Gaurav says
Is it also possible to get tags on vSphere 5.x using vSphere APIs ?
William Lam says
No, currently there are no vSphere APIs for Tags. You can use PowerCLI, but its limited to read-only operations. Take a look at this blog post for some more details http://www.virtuallyghetto.com/2015/01/custom-attributes-vsphere-tags.html
Derick Winkworth (@cloudtoad) says
Where did you find these hidden methods? In a schema file or something?
William Lam says
Just poking around various places, no specific area to find these things.
David Homer says
Hey William, great post
We were looking to document tags as part of our VMware inventory tool
http://www.centrel-solutions.com/XIAConfiguration/Capabilities.aspx?capability=VMwareSystem
I noticed that in vSphere 6 the Tags property in the MOB always seems empty - have VMware dropped this support now?
Dave
William Lam says
The "Tag" feature noted in this blog is NOT the same as the new vSphere Tagging feature which was first introduced in vSphere 5.1. In vSphere 5.5, we have PowerCLI cmdlets to interact with vSphere Tags (https://blogs.vmware.com/PowerCLI/2014/03/using-vsphere-tags-powercli.html) and in vSphere 6.0, we now also have APIs which are part of the vCloud Suite SDK (https://developercenter.vmware.com/sdks) that allow you to interact with them.