Create vraGetVcenter.js

This commit is contained in:
John Bowdre 2022-06-14 08:54:09 -05:00 committed by GitHub
parent db9c410571
commit cc25bed063
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -0,0 +1,20 @@
/* JavaScript: vraGetVcenter action
Returns the vCenter hostname associated with a given site.
Inputs: zoneName (string)
Return type: string
*/
var cloudAccountId = null;
var token = System.getModule("com.virtuallypotato.utility").vraLogin();
var zones = JSON.parse(System.getModule("com.virtuallypotato.utility").vraExecute(token, "GET", "/iaas/api/zones", null)).content;
System.debug("Zones: " + JSON.stringify(zones));
for each (zone in zones) {
if (zone.name === zoneName) {
cloudAccountId = (zone._links["cloud-account"].href).split('/').pop();
}
if (cloudAccountId != null) { break; };
}
System.debug("Cloud Account ID: " + cloudAccountId);
var vCenterName = JSON.parse(System.getModule("com.virtuallypotato.utility").vraExecute(token, "GET", "/iaas/api/cloud-accounts-vsphere/" + cloudAccountId, null)).hostName.split('.')[0];
System.getModule("com.virtuallypotato.utility").vraLogout(token);
return vCenterName;