Create vcExecute.js

This commit is contained in:
John Bowdre 2022-06-14 09:07:04 -05:00 committed by GitHub
parent 970154e24d
commit 95b755e8ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,22 @@
/* JavaScript: vcExecute action
Executes an action against a vCenter REST endpoint.
Inputs: token (string), method (string), uri (string), content (string), vCenterName (string)
Return Type: string
*/
var host = System.getModule("com.virtuallypotato.utility").getConfigValue("vPotato", "Endpoints", vCenterName).host;
if (content) {
var request = host.createRequest(method, uri, content);
} else {
var request = host.createRequest(method, uri);
}
request.setHeader("Content-Type", "application/json");
request.setHeader("vmware-api-session-id", token);
var response = request.execute();
var statusCode = response.statusCode;
var responseContent = response.contentAsString;
if (statusCode > 399) {
System.error(responseContent);
throw "vcExecute action failed, status code: " + statusCode;
}
return responseContent;