Okay, it appears your method is what I was trying but I still receive the errors originally mentioned. I will try it as an action but I would be surprised that those options are only available there.
Here is my code, I wrote it as a workflow and use a variable "endpoint" to a VAPI:VAPIEndpoint.
This code has extra logging to try and get some data out to see where my issue what but as I said, all of those new com_vmaware* calls are giving "not defined" errors.
var getAllSystemNames = function() {
systemNames = [];
var allVcenters = VcPlugin.getAllVimHosts();
for (var i = 0; i < allVcenters.length; i++) {
var vc = allVcenters[i];
System.log("Processing " + vc.name);
var datacenters = vc.getAllDatacenters();
for (var j = 0; j < datacenters.length; j++) {
var clusters = datacenters[j].hostFolder.childEntity;
for (var k = 0; k < clusters.length; k++) {
if ('host' in clusters[k]) {
var hosts = clusters[k].host;
for (var l = 0; l < hosts.length; l++) {
var host = hosts[l];
System.log('Checking vHost '+host.name);
var systems = host.vm;
for (var m = 0; m < systems.length; m++) {
System.log('Checking host '+systems[m].name + ' with ID :'+systems[m].id);
try {
if (checkHostForTag(systems[m], "monitor", "true")) {
systemNames.push(systems[m].name);
System.log('Adding ' + systems[m].name + ' from host ' + host.name);
}
} catch (e) {
System.error("Error processing host " + systems[m].name + ": " + e.toString());
}
}
}
}
}
}
}
return systemNames;
};
function checkHostForTag(host, expectedTagName, expectedValue) {
System.log('checkHostForTag:'+host.name)
// var endpoints = VAPIManager.getAllEndpoints();
// var endpointTest = endpoints[0];
if (endpoint) {
var client = endpoint.client();
if (client) {
var objId = new com_vmware_vapi_std_dynamic__ID();
objId.id = host.id;
objId.type = host.vimType;
var tagging = new com_vmware_cis_tagging_tag__association(client);
var tagMgr = new com_vmware_cis_tagging_tag(client);
var catMgr = new com_vmware_cis_tagging_category(client);
var tagList = tagging.list_attached_tags(objId);
for (var i = 0; i < tagList.length; i++) {
var theTag = tagMgr.get(tagList[i]);
System.log("Tag details="+JSON.stringify(theTag));
System.log("Checking tag on " + host.name + ": " + theTag.name);
if (theTag.name.toLowerCase() === expectedTagName.toLowerCase() && theTag.description === expectedValue) {
return true;
}
}
} else {
System.warn('No client object for host.')
}
} else {
System.warn('No endpoint defined.')
}
return false;
}
getAllSystemNames();