Converting vSphere Custom Attributes to Categories and Tags
In vSphere 5.1 “Tags” replace the old custom attributes to provide a way of adding metadata to vSphere objects. The “Tags” are organised into categories to “define how the tags can be applied to inventory objects”. The easiest way to think of the difference is that custom attributes are “free text” and the tags are statically defined properties.
There is a wizard for converting custom attributes to tags, but it can get a bit confusing and is pretty poor – let me explain. We use four custom attributes in my current environment: CreatedBy, CreatedOn, Owner and ServiceType. CreatedBy contains the user ID of the person who created the VM, CreatedOn is the timestamp of when the VM was created, Owner is the Business Unit who own the server and ServiceType is the type of service – e.g. Active Directory, or SQL.
CreatedBy is a fairly limited set of user IDs that don’t change often, which I assumed lends itself quite well to the use of tags. The problem arises when you attempt to convert the attributes to tags. I ran the Wizard, filtered and selected all the CreatedBy Custom Attributes and moved on to the Create Tags page. This lists this Custom Attribute for each machine, and it’s value, so clicked Next. I did this on two occasions and had two results – the first time the Wizard tried to validate the data and threw an error requiring each Tag to be unique, the second time it created two unique Tags and threw an error when it tried to create a new Tag that wasn’t unique.
The problem is that the Wizard does not merge the custom attributes together when creating the tags, it tries to create a unique tag per custom attribute assigned. This is a seriously half-baked implementation! “Owner” and “Service Type” face the same problem as “CreatedBy” – there is no logical merging of attribute values to create Tags. I can create the Tags by carefully selecting one of each value, but I then need to manually assign the new Tags to each VM which would take an untenable amount of manual labour.
It also becomes a problem when you think of the CreatedOn field, which contains as many unique values as we have Virtual Machines. This isn’t manageable as we’d need to create a new Tag every time there was a new timestamp. We decided to abandon this attribute as it’s of limited value and there are other ways to determine when the VM was created (e.g. server commissioning forms).
The solution? At present there is no way to programattically add or remove, or assign tags and categories. This was confirmed to me by Alan Renouf (@alanrenouf) on twitter, and Luc Dekens (@LucD) on the VMware Communities forums. LucD pointed to an article on VirtuallyGhetto regarding the Managed Object Browser (MOB) which allows for the creation of tags, but this doesn’t help me much.
All in all, I love the new feature of Tags, it shows that VMware have thought about even this small portion of functionality (e.g. the cardinality, see below) – I just hope the wizard gets improved (or at least the PowerCLI team can access the APIs!) I also love the new web client, and despite some “we don’t like change” rumblings from people around me, they are all getting used to it and enjoying it.
A small explanation of the Cardinality of tags.
There are some tags which you only need one value assigned to an object, for example if you used “Priority” as a Category and “High”, “Medium” and “Low” as the available tags, you don’t want to be able to tag a VM with both “High” and “Low”. For this I would set the Category Cardinality for “Priority” to “1 tag per object”. Conversely, there are some Categories which it would be great to be able to use multiple, for example my “ServiceType” category. I may have a Domain Controller which is also a DNS, SQL and DHCP server – I can add all those tags if I set the Cardinality to “Many tags per object”.