Request catalog item with provisioning request
var myProvisioningRequest = vCACCAFERequestsHelper.getProvisioningRequestForCatalogItem(attCatalogItem) // attCatalogItem is of type vCACCAFE:CatalogItem
If you were to do a System.log(myProvisioningRequest); now, you’d see a block of unformatted JSON data (amongst other things in a dynamic wrapper), containing all of the data relevant to the catalog request for the catalog item specified.
With the provisioning request now contained within the myProvisioningRequest object, we can set properties such as the description and the request reason using built-in methods, just like we would in the vRA request portal.
myProvisioningRequest.setDescription(“Some description”); myProvisioningRequest.setReason(“Some reason”);
Setting other properties before requesting the catalog item
In order to set properties such as CPU, memory, or any other custom properties we’ve defined on the virtual machine within the blueprint, we can get the provisioning request data from our myProvisioningRequest object and change the data. To do this, we call the getProvisioningRequestData method and pass in our myProvisioningRequest object as a parameter.
var getProvisioningRequestData = vCACCAFERequestsHelper.getProvisioningRequestData(myProvisioningRequest);
var setRequestData = JSON.parse(getProvisioningRequestData);
Dumping the contents of setProvisioningRequestData, you’ll see the properties that can be set. To set them simply do:
setRequestData.<blueprintComponentName>.data.property = value;
setRequestData.vSphere_Machine_1.data.cpu = 2;
So this is all easy, and makes sense right? Yes, until when it doesn’t… What if you have a custom property defined like this:
or a built in one like this:
In this case, you’d think you can just specify them and get away with it, but no, you can’t just do this:
setRequestData.vSphere_Machine_1.data.VirtualMachine.Software0.Name = “MySoftware” //Wrong
If you specify the property like I’ve done above you’ll get the following error:
“TypeError: Cannot read property “VirtualMachine” from undefined”
setRequestData.vSphere_Machine_1.data[“VirtualMachine.Software0.Name”] = “MySoftware”; //Correct
So after the custom properties are set in our JSON object, we need to set the request data back on the provisioning request object:
Now with the provisioning request updated, we can go ahead and make the provisioning request to vRA: