Skip to content

Instantly share code, notes, and snippets.

@trisharia
Last active October 4, 2019 21:30
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/4528b0cbdafb25cbe7d926b105d92b01 to your computer and use it in GitHub Desktop.
Save trisharia/4528b0cbdafb25cbe7d926b105d92b01 to your computer and use it in GitHub Desktop.
Get all vRA/vRA Cloud Networks
// VMware vRealize Orchestrator action sample
//
// Get an array of all vRA/vRA Cloud network details 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
//
// Return type: Array/Any - all vRA/vRA Cloud network details in JSON format
const opMethod = "GET";
const top = 1000;
var allNetworks = [];
var opUrl = "/iaas/fabric-networks";
var opResponse;
var responseJson;
var content;
var count;
var headers = new Properties();
headers.put("Authorization", "Bearer " + cspAuthToken);
do {
opResponse = System.getModule("com.vmware.pso.rest").executeTransientRESTOperation(
cspBaseUrl,null,null,opMethod,opUrl,null,headers,null,null);
if (opResponse.statusCode >= 400) {
throw "Failed to get fabric networks (" + opResponse.statusCode + " Error). Details: " + opResponse.responseString;
}
responseJson = JSON.parse(opResponse.responseString);
count = responseJson.numberOfElements;
content = responseJson.content;
allNetworks = allNetworks.concat(content);
opUrl = "/iaas/fabric-networks?$top=" + top + "&$skip=" + allNetworks.length;
//System.debug("Count so far: " + allNetworks.length);
} while (count !== 0)
//System.debug(allNetworks.length);
return allNetworks;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment