Created
September 13, 2019 00:39
-
-
Save trisharia/d2c087a3fe5a3d616859d61b79b35db9 to your computer and use it in GitHub Desktop.
Create vRA/vRA Cloud Project
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 | |
// | |
// Create a vRA/vRA Cloud project | |
// Assumes the presence of action System.getModule("com.vmware.pso.rest").executeTransientRESTOperation | |
// Obtain the action here: https://gist.github.com/trisharia/7b62fcdf12600511b3d7e9b635981b2c | |
// Hint: to understand the format for the JSON input parameters, do a GET on existing projects | |
// shown here: https://gist.github.com/trisharia/a7345c779601fdd380b99acc764fb666 | |
// | |
// 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 | |
// name - string - Name of the project | |
// description - string - Description of the project | |
// administrators - Array/Any - JSON object of administrators | |
// members - Array/Any - JSON object of members | |
// zoneAssignmentConfigurations - Array/Any - JSON object of zone assignment configurations | |
// operationTimeout - number - Project operation timeout | |
// | |
// Return type: string - ID of the new project | |
const opMethod = "POST"; | |
const opUrl = "/iaas/projects"; | |
const contentType = "application/json"; | |
var headers = new Properties(); | |
headers.put("Authorization", "Bearer " + cspAuthToken); | |
var contentJson = { | |
"name" : name, | |
"description" : description, | |
"administrators" : administrators, | |
"members" : members, | |
"zoneAssignmentConfigurations" : zoneAssignmentConfigurations, | |
//"properties" : {"key1":"val1", "keyn":"valn"}, // not yet available in iaas api | |
"operationTimeout" : operationTimeout | |
} | |
var content = JSON.stringify(contentJson); | |
var createOpResponse = System.getModule("com.vmware.pso.rest").executeTransientRESTOperation( | |
cspBaseUrl,null,null,opMethod,opUrl,null,headers,contentType,content); | |
if (createOpResponse.statusCode >= 400) { | |
throw "Failed to create project (" + createOpResponse.statusCode + " Error). Details: " + createOpResponse.responseString; | |
} | |
var responseJson = JSON.parse(createOpResponse.responseString); | |
projectId = responseJson.id; | |
System.log("Project created with ID " + projectId); | |
return projectId; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment