posted

4 Comments

In this blog we will talk about a feature in vSphere, that can make a vSphere administrator’s life quite easy in terms of managing, sorting and arranging vSphere objects.

I am referring to the “Tags and Custom Attributes” feature which can be accessed from the vSphere Client.

Searching and sorting objects in a large vSphere environment could get a bit tricky. This situation can be easily mitigated by associating metadata to the vSphere objects by using tags and custom attributes.

 

So, what exactly are tags?

A tag is sort of a label which can be applied to an object in the vSphere inventory. A tag basically represents metadata of that object. After creating a tag, it is assigned to a category.

The category is a broader construct and is basically a collection of related tags.

A Category can be defined so that it can accommodate more than one tag. After creating a category, it can be associated to a corresponding vSphere inventory object viz. “Folder”, “Host”, “Virtual Machines” etc.

Let us take an example to understand tags and categories.

Consider a large-scale vSphere environment with multiple VMs running different operating systems like Linux, Windows etc. In-order to tag VMs by operating system, we will first create a category called “operating system” and will associate this category to “Virtual Machine” inventory object type. Post this we will create tags like “Windows”, “Linux” and will associate them to the “operating system” category.

Custom attributes

vSphere administrators can associate custom attributes (user defined) in a custom “keys” and “value” format to a variety of vSphere objects using the custom attributes option.

This feature comes in handy if there is a need to group objects based on attributes.

For example, consider a large group of database server VMs which is owned by 2 database administrators John and Larry. In this scenario custom attribute “owner” can be created which will either have John or Larry as its value to identify the ownership.

The fundamental difference between tags and custom attributes is that tags allow one to logically classify and arrange vSphere objects, however when using custom attributes vSphere object metadata can be stored right with the object itself in vCenter.

Apart from logical arrangement, searching tags and custom attributes can also be used for

  • Granting Permissions to vSphere objects
  • Configuration Management Database (CMDB)

 

 

vSphere APIs for Tags and Categories

APIs for tags and categories can be found under the vCenter server cis API endpoint. Please refer the following table to understand the API schema and how they can be used. For more details on API usage please refer to this link.

Category

Operation Method API
list GET

https://{server}/rest/com/vmware/cis/tagging/category

get GET

https://{server}/rest/com/vmware/cis/tagging/category/id:{category_id}

create POST

https://{server}/rest/com/vmware/cis/tagging/category

delete DELETE

https://{server}/rest/com/vmware/cis/tagging/category/id:{category_id}

 

list_used_categories POST

https://{server}/rest/com/vmware/cis/tagging/category?~action=list-used-categories

 

add_to_used_by POST

https://{server}/rest/com/vmware/cis/tagging/category/id:{category_id}?~action=add-to-used-by

 

remove_from_used_by POST

https://{server}/rest/com/vmware/cis/tagging/category/id:{category_id}?~action=remove-from-used-by

 

update PATCH

https://{server}/rest/com/vmware/cis/tagging/category/id:{category_id}

 

revoke_propagating_permissions POST

https://{server}/rest/com/vmware/cis/tagging/category/id:{category_id}?~action=revoke-propagating-permissions

 

Tags

Operation Method API
list GET https://{server}/rest/com/vmware/cis/tagging/tag

 

get GET

https://{server}/rest/com/vmware/cis/tagging/tag/id:{tag_id}

 

create POST

https://{server}/rest/com/vmware/cis/tagging/tag

delete DELETE

https://{server}/rest/com/vmware/cis/tagging/tag/id:{tag_id}

list_used_tags POST

https://{server}/rest/com/vmware/cis/tagging/tag?~action=list-used-tags

 

add_to_used_by POST

https://{server}/rest/com/vmware/cis/tagging/tag/id:{tag_id}?~action=add-to-used-by

remove_from_used_by POST

https://{server}/rest/com/vmware/cis/tagging/tag/id:{tag_id}?~action=remove-from-used-by

update PATCH

https://{server}/rest/com/vmware/cis/tagging/tag/id:{tag_id}

revoke_propagating_permissions POST

https://{server}/rest/com/vmware/cis/tagging/tag/id:{tag_id}?~action=revoke-propagating-permissions

 

To Conclude

Using tags and custom attributes, a vSphere admin can ensure that vSphere objects are organized and logically arranged. Tags and categories let vSphere administrators organize different vSphere objects like datastores, virtual machines, hosts, and so on. This makes it easier to sort and search for objects that share a tag, among other things.

This feature become even more handy in automation and CMDB use cases.