Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Input Parameters
- var BaseUrl = "https://atlas.budcca-demo.lab";
- var User = "budcca\jelarabi";
- var Password = "Constell@tion";
- /**
- * Configure first API call to find sessionID
- * SessionId is our credential for other Api call
- * POST request
- */
- var operationUrl = baseUrl + "/rest/com/vmware/cis/session";
- var req = restHost.createRequest("POST", operationUrl, "");
- var resp;
- if (User == null || User == "" || Password == null || Password == "") {
- console.log("User or Password is empty");
- exit()
- }
- resp = req.executeWithCredentials(User, Password);
- statusCode = resp.statusCode;
- if (statusCode == 401) {
- console.log("Bad credential");
- exit();
- } else if (statusCode != 200) {
- console.log("Error");
- exit();
- }
- // Take json body in response parse it to get this sessionId
- var sessionid = JSON.parse(resp.contentAsString).value;
- /**
- * Second Api call to get all folder in vCenter
- * Put the sessionId in header
- * GET request
- */
- var operationUrl = baseUrl + "/rest/vcenter/folder";
- var request = restHost.createRequest("GET", operationUrl, "");
- request.setHeader("Accept", "application/json");
- request.setHeader("Content-Type", "application/json");
- request.setHeader("vmware-api-session-id", sessionid);
- resp = request.execute();
- statusCode = resp.statusCode;
- if (statusCode == 401) {
- console.log("Bad sessionId");
- exit();
- } else if (statusCode != 200) {
- console.log("Error");
- exit();
- }
- // Parse Json Body to find all folder in one json object and stock them in folder array variable
- var jsonBody = JSON.parse(resp.contentAsString).value;
- var availableValues = [];
- for (var i in jsonBody) {
- var testVal = jsonBody[i].name;
- availableValues.push({'value': testVal, 'displayName': testVal, 'description': ''});
- }
- // Display all folder
- //console.log(folder);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement