Skip to content

Instantly share code, notes, and snippets.

@trisharia
Last active March 25, 2017 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trisharia/8786757ad28738a8d445eec0addbb58d to your computer and use it in GitHub Desktop.
Save trisharia/8786757ad28738a8d445eec0addbb58d to your computer and use it in GitHub Desktop.
Create a vCenter tag via VAPI
// VMware vRealize Orchestrator action sample
//
// Create a vCenter tag via VAPI
// If description is empty, sets the description as the Tag name by default.
//
// For vRO/VAPI 7.0+
//
// Action Inputs:
// endpoint - VAPIEndpoint - VAPI Endpoint
// name - string - Name of the Tag
// categoryId - string - ID of the Tag Category
// description - string - Optional description of the Tag
//
// Return type: string - ID of the tag
var tagClient = endpoint.client();
var tagService = new com_vmware_cis_tagging_tag(tagClient);
var tagCreateSpec = createTagSpec(name,categoryId,description);
tagId = tagService.create(tagCreateSpec);
return tagId;
function createTagSpec(name,categoryId,description) {
var spec = new com_vmware_cis_tagging_tag_create__spec() ;
spec.category_id = categoryId;
spec.name = name;
spec.description = (isSet(description)) ? description : name;
return spec;
}
function isSet(s) {
return s != null && s != "";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment