Hello
I searched quite a lot, but didn't find a solution:
I would like to find all VM tags (from a specific category) which have 0 assignments - I mean tags who are not or no more used at all?
So I can delete them in in this way "clean up" a little the vCenter database.
There are some VAPI objects in the API Explorer, starting with "com_vmware_cis_tagging_tag__association...", where I'm quite sure to be on the right way, but I can't go any further from here.
Maybe anybody has an idea or hints?
Kind regards
Roman
Hi
I've never really used the VAPI plugin much but have done some stuff on vCenter Tagging via the REST API. Making the assumption that VAPI just offloads to that API in the background & looking at the latest API docs, you can make this call
So, I'd be guessing that VAPI provides this somehow as part of the Metamodel?
It's sort of annoying that you only get the VAPI content in the vRO API explorer AFTER you create a VAPI endpoint so I can't look to see if a function/method exists here
-HTH
The following code should work:
function getCategoryByName(vapi_client, categoryName) {
var tagging_category = new com_vmware_cis_tagging_category(vapi_client);
var result = tagging_category.list();
var category = null;
for each(var c in result) {
var cat = tagging_category.get(c);
if (cat.name == categoryName) {
category = cat;
break;
}
}
if (category==null) throw "Category doesn't exists";
return category;
}
var vapi_client = endpoint.client();
var categoryNameForCleanUp = "MyCategory";
var tagging_tag = new com_vmware_cis_tagging_tag(vapi_client);
var tagging_tag_associations = new com_vmware_cis_tagging_tag__association(vapi_client);
var category = getCategoryByName(vapi_client, categoryNameForCleanUp);
var unused_tags = [];
for each(var t in tagging_tag.list_tags_for_category(category.id)) {
var tag = tagging_tag.get(t);
var objects = tagging_tag_associations.list_attached_objects(tag.id);
System.log(tag.name + ". Objects: " + objects.length);
if (objects.length == 0) {
unused_tags.push(tag);
}
}
// Do something with the array 'unused_tags'
vapi_client.close();
Hope it helps
@bdamian Great! Thank you very much!