Last active
September 22, 2017 16:04
-
-
Save trisharia/2574a307f51bda1898864f257eb588c4 to your computer and use it in GitHub Desktop.
Get the names of all vCenter Tags of a Category given a Category name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// VMware vRealize Orchestrator action sample | |
// | |
// This sample returns the ID of a vCenter Tag Category given its name | |
// | |
// For vRO/VAPI 7.0+ | |
// | |
// Action Inputs: | |
// endpoint - VAPIEndpoint - VAPI Endpoint | |
// categoryName - string - Name of the vCenter Tag Category | |
// | |
// Return type: string | |
var client = endpoint.client(); | |
var catService = new com_vmware_cis_tagging_category(client); | |
var categories = catService.list(); | |
for each (var catId in categories) { | |
if (catService.get(catId).name === categoryName) { | |
System.debug("Found tag category with name '" + categoryName + "' with ID '"+ catId +"'"); | |
return catId; | |
} | |
} | |
System.warn("No tag category found with name '" + categoryName + "'"); | |
return null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// VMware vRealize Orchestrator action sample | |
// | |
// This sample returns the ID of a vCenter Tag Category given its name | |
// Note: Excutes another action defined in getTagCategoryIdByName.js | |
// | |
// For vRO/VAPI 7.0+ | |
// | |
// Action Inputs: | |
// endpoint - VAPIEndpoint - VAPI Endpoint | |
// categoryName - string - Name of the vCenter Tag Category | |
// doSort - boolean - Set to true to return the names in sorted order | |
// | |
// Return type: Array/string | |
var tagNames = []; | |
var vapiClient = getVapiClient(); | |
var categoryId = getTagCategoryIdByName(vapiClient, categoryName); | |
var tagService, tags, tag; | |
if (!categoryId) throw "No category found with name " + categoryName; | |
tagService = new com_vmware_cis_tagging_tag(vapiClient); | |
tags = tagService.list_tags_for_category(categoryId); | |
tagNames = []; | |
for each (var tid in tags) { | |
try { | |
tag = tagService.get(tid); | |
tagNames.push(tag.name) | |
} catch(e) { | |
System.error(e); // There is a bug that throws an exception just because a tag lacks a description | |
} | |
} | |
if (tagNames.length === 0) System.warn("No tags found in category '"+ categoryName +"'"); | |
if (doSort) return tagNames.sort(); | |
return tagNames; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment