Created
March 8, 2017 06:10
-
-
Save dlinsley/e1bfc8c131473a2399daf5d451286dd5 to your computer and use it in GitHub Desktop.
vRealize Orchestrator Sample - Add Replace ResourceElement
This file contains hidden or 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
// Copyright 2017, VMware, Inc., All Rights Reserved | |
// | |
// VMware vRealize Orchestrator action sample | |
// | |
// Adds or replaces a ResourceElement in a ResourceElementCategory. | |
// Assumes conrent type is text/plain | |
// For vRO 7.0+ | |
// | |
// Action Inputs: | |
// name - string Name of the ResourceElement | |
// path - string Path of the ResourceElementCategory | |
// content - string New Content of the ResourceElement | |
// | |
// Return type: ResourceElement - The new or updated ResourceElement. | |
var mime = new MimeAttachment(); | |
mime.name = name; | |
mime.mimeType = "text/plain"; | |
mime.content = content; | |
var resourceCat = Server.getResourceElementCategoryWithPath(path); | |
var resources = resourceCat.resourceElements; | |
var found = false; | |
var toReturn; | |
for(var i in resources) { | |
if (resources[i].name === name) { | |
System.debug("resources[i].name: "+resources[i].name); | |
found = true; | |
System.log("Replacing exising element "+name+" in "+path); | |
resources[i].setContentFromMimeAttachment(mime); | |
toReturn = resources[i]; | |
break; | |
} | |
} | |
System.log("Found ResourceElement: "+found.toString()); | |
if (!found) { | |
System.log("Writing \""+name+"\" to Resource Element Category: "+resourceCat.path); | |
toReturn = Server.createResourceElement(path,name,mime); | |
} | |
return toReturn; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment