mirror of
https://github.com/jbowdre/vRealize.git
synced 2024-12-12 08:52:20 +00:00
Create vcGetCustomizationSpecs
This commit is contained in:
parent
95b755e8ed
commit
46a6cf1cd9
1 changed files with 48 additions and 0 deletions
|
@ -0,0 +1,48 @@
|
||||||
|
/* JavaScript: vcGetCustomizationSpecs
|
||||||
|
Retrieves a list of customization specs available for a given zone and image.
|
||||||
|
Inputs: imageName (string), zoneName (string)
|
||||||
|
Return type: array/string
|
||||||
|
*/
|
||||||
|
if (!(imageName == "" || imageName == null)) {
|
||||||
|
var cloudAccountId = null;
|
||||||
|
var vraToken = System.getModule("com.virtuallypotato.utility").vraLogin();
|
||||||
|
var zones = JSON.parse(System.getModule("com.virtuallypotato.utility").vraExecute(vraToken, "GET", "/iaas/api/zones", null)).content;
|
||||||
|
System.debug("Zones: " + JSON.stringify(zones));
|
||||||
|
for each (zone in zones) {
|
||||||
|
System.debug("Found zone: " + zone.name);
|
||||||
|
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(vraToken, "GET", "/iaas/api/cloud-accounts-vsphere/" + cloudAccountId, null)).hostName.split(".")[0];
|
||||||
|
System.debug("vCenterName is: " + vCenterName);
|
||||||
|
var imageFamily = null;
|
||||||
|
var images = JSON.parse(System.getModule("com.virtuallypotato.utility").vraExecute(vraToken, "GET", "/iaas/api/images", null)).content;
|
||||||
|
System.debug("Images: " + JSON.stringify(images));
|
||||||
|
for each (image in images) {
|
||||||
|
for (var i in image.mapping) {
|
||||||
|
if (i === imageName) {
|
||||||
|
imageFamily = image.mapping[i].osFamily;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (imageFamily != null) { break; };
|
||||||
|
}
|
||||||
|
System.debug("Image family: " + imageFamily);
|
||||||
|
|
||||||
|
var vcToken = System.getModule("com.virtuallypotato.utility").vcLogin(vCenterName);
|
||||||
|
var specs = JSON.parse(System.getModule("com.virtuallypotato.utility").vcExecute(vcToken, "GET", "/api/vcenter/guest/customization-specs?os_type=" + imageFamily, null, vCenterName));
|
||||||
|
System.debug("Customization specs: " + JSON.stringify(specs));
|
||||||
|
customSpecs = new Array();
|
||||||
|
for each (spec in specs) {
|
||||||
|
customSpecs.push(spec.name);
|
||||||
|
}
|
||||||
|
System.getModule("com.virtuallypotato.utility").vcLogout(vcToken, vCenterName);
|
||||||
|
|
||||||
|
customSpecs.sort();
|
||||||
|
return customSpecs;
|
||||||
|
} else {
|
||||||
|
return [""];
|
||||||
|
}
|
Loading…
Reference in a new issue