Created
September 13, 2019 00:32
-
-
Save trisharia/be7df3a4714af4efc1ad5cf29c936a23 to your computer and use it in GitHub Desktop.
Tag vRA/vRA Cloud Network
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
// VMware vRealize Orchestrator action sample | |
// | |
// Add/update tags on a vRA/vRA Cloud network | |
// Assumes the presence of action System.getModule("com.vmware.pso.rest").executeTransientRESTOperation | |
// Obtain the action here: https://gist.github.com/trisharia/7b62fcdf12600511b3d7e9b635981b2c | |
// | |
// For vRA Cloud 7.0+ and vRA 8.0+ | |
// | |
// Action Inputs: | |
// cspBaseUrl - string - Base URL for connecting to VMware Cloud Services RESTful API | |
// e.g., https://api.mgmt.cloud.vmware.com | |
// cspAuthToken - string - VMware Cloud Services bearer token | |
// Get this token by running the following action first: https://gist.github.com/trisharia/4262427728b9ca2f22f76c39a5521768 | |
// networkId - string - ID of the network | |
// tags - Array - Tag(s) to add/update on the network in JSON string format | |
// e.g., to add 2 tags: | |
// tags = [ { "key":"key1", "value":"value1"}, { "key":"keyn", "value":"valuen"} ] | |
// | |
// Return type: void | |
const opMethod = "PATCH"; | |
const opUrl = "/iaas/api/fabric-networks/{0}"; | |
const contentType = "application/json"; | |
const urlParamValues = [networkId]; | |
var headers = new Properties(); | |
headers.put("Authorization", "Bearer " + authToken); | |
var contentJson = { | |
"tags" : tags | |
} | |
var content = JSON.stringify(contentJson); | |
System.debug("content: " + content) | |
var createOpResponse = System.getModule("com.vmware.pso.rest").executeTransientRESTOperation( | |
cspBaseUrl,null,null,opMethod,opUrl,urlParamValues,headers,contentType,content); | |
if (createOpResponse.statusCode >= 400) { | |
throw "Failed to tag network (" + createOpResponse.statusCode + " Error). Details: " + createOpResponse.responseString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment