Created
September 12, 2019 23:41
-
-
Save trisharia/64a3ff443f50b9e597a621031f55237a to your computer and use it in GitHub Desktop.
Get all vRA/vRA Deployment Resources
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 | |
// | |
// Get an array of all vRA/vRA Cloud resources for a given deployment in JSON format | |
// 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 | |
// deploymentId - string - Deployment ID | |
// | |
// Return type: Array/Any - all vRA/vRA Cloud deployment resource details in JSON format | |
const opMethod = "GET"; | |
var allResources = []; | |
var opUrl = "/deployment/api/deployments/{0}/resources"; | |
var opResponse; | |
var responseJson; | |
var content; | |
var isLastPage = false; | |
urlParamValues = [deploymentId]; | |
var headers = new Properties(); | |
headers.put("Authorization", "Bearer " + cspAuthToken); | |
do { | |
opResponse = System.getModule("com.vmware.pso.rest").executeTransientRESTOperation( | |
cspBaseUrl,null,null,opMethod,opUrl,urlParamValues,headers,null,null); | |
if (opResponse.statusCode >= 400) { | |
throw "Failed to get deployment resources (" + opResponse.statusCode + " Error). Details: " + opResponse.responseString; | |
} | |
responseJson = JSON.parse(opResponse.responseString); | |
content = responseJson.content; | |
allResources = allResources.concat(content); | |
isLastPage = responseJson.last; | |
//System.debug("Count so far: " + allResources.length); | |
} while (!isLastPage) | |
System.debug("Deployment resource count: " + allResources.length); | |
return allResources; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment