draymond10
Enthusiast
Enthusiast

Reconfigure Storage vRA API

Looking to add a disk via REST API. 

So we're doing a GET on https://$host/catalog-service/api/consumer/resources/$resourceid/actions/$resourceActionId/requests/...

Then POST on https://$host/catalog-service/api/consumer/resources/$resourceid/actions/$resourceActionId/requests

Anyone know what the exact content we are using?  Do you have to take the entire template with current default values + inject your new storage variables (which should only be $size per the GUI mandatory fields) ?

Or

just submit your new storage variables into the Content of the request

0 Kudos
1 Reply
stevevm101
VMware Employee
VMware Employee

here is a bit example.

template["data"]["customProperties"] = propArray;

//System.log(JSON.stringify(template));

for each (var item in propertyBag.keys) {

// if (item.indexOf("Disk") == -1) {

if (changeType == "resetVM") {

System.log("API resetVM");

//template["description"] = "Reset VM";

template[item] = propertyBag[item];

} else if (changeType == "changeCpuMemory" || changeType =="updateDescription") {

System.log("Update CPU/Memory - description");

//cpu/memory

template["data"][item] = propertyBag[item];

} else {

var selDisk = null;

var delta = 0;

for each(var disk in template["data"]["disks"]) {

for each (var cp in disk["data"]["customProperties"]) {

if (cp["data"]["id"] == "Name" && cp["data"]["value"] == propertyBag[item]["Name"]) {

selDisk = disk;

break;

}

}

}

if (selDisk && changeType == "resizeDisk") {

System.log("Update Disk");

delta = propertyBag[item]["size"] - selDisk["data"]["size"] ;

if (selDisk["data"]["size"] < propertyBag[item]["size"]) {

selDisk["data"]["size"] = propertyBag[item]["size"];

} else {

delta = 0;

throw Error("New disk size smaller than original");

}

}

if (changeType == "newDisk") {

System.log("Add Disk");

var tmpStr = JSON.stringify(template["data"]["disks"][0]);

var tmp = JSON.parse(tmpStr);

for each (var diskProp in propertyBag[item].keys) {

if (diskProp.indexOf("Name") == -1) {

tmp["data"][diskProp] = propertyBag[item][diskProp];

}

else {

for each(var prop in tmp["data"]["customProperties"]) {

if (prop["data"]["id"] == "Name") {

prop["data"]["value"] = propertyBag[item][diskProp];

}

}

}

}

template["data"]["disks"][template["data"]["disks"].length] = tmp;

}

template["data"]["storage"] = template["data"]["storage"] + delta;

}

0 Kudos