I've seen and implemented many different methods for creating IaaS reservations for business groups in vRA 7. Most of the methods i used in 6 no longer work so i thought i would share with you my method for creating them in vRA 7.
We'll be working with the vCACCAFE and vCAC plugins and specifically these objects:
- vCACCAFEAlert
- vCACCAFEAlertPolicy
- vCACCAFEHost
- vCACCAFEReservation
- vCACCAFEReservationClient
- vCACCAFEReservationReservationService
First we need to get a a connection to the Reservation Reservation Service to be able to perform CRUD operations against reservations. We accomplish this through the Reservation Client like so:
var reservationService = cafeHost.createReservationClient().getReservationReservationService();
where "cafeHost" is type vCACCAFE:vCACHost
Once we have created our connection to the Reservation Reservation Service we can perform CRUD operations through its methods. I have personally used two methods for creating reservations:
- Copy and update a golden reservation
- Create reservations from scratch
Number 1 is much easier and quicker if you can get away with it. The drawbacks of course are that the reservation isn't very customizable, if the golden image goes away the copy operation obviously stops working, and if the golden reservation gets changed for any reason all your new reservations could be created with the incorrect parameters. However if your willing to forgo those risks copy/updating can be accomplished in a few minutes.
Assuming you already have a manually created reservation, lets find the existing reservations. I have not been able to find an easy way to get all reservations as there is no Type for them in the vRA plugin. This information is not easy to get using the vCACCAFE plugin so instead we're going to grab it from the vCAC plugin. The easiest way is to simply browse the vRO Inventory: vRealize Automation Infrastructure > IaaS Host > Reservations. Select the appropriate reservation to view its properties. These properties are all mirrored between the vCAC and vCACCAFE components (so both have the same ID, Name, etc).
In this example I'm going to show you the clone and update method.
Once you have the host reservation ID of the reservation you want to copy you can fetch it from the vCACCAFE plugin using:
var goldenReservation = reservationService.getReservation('<reservation ID string>');
where <reservation ID string> is the ID we just grabbed. This method will return a vCACCAFEReservation Object.
Once we have our reservation object we can grab its properties:
var tenantId = goldenReservation .getTenantId(); var type = goldenReservation .getReservationTypeId(); var extensionData = goldenReservation .getExtensionData(); var alertPolicy = goldenReservation .getAlertPolicy();
At this point we have all the properties we need from our golden reservation but we need to know which business group we're going to associate it with and more specifically the ID of the group. I usually have the group names so to find it by name you could use:
var subtenants = vCACCAFEEntitiesFinder.getSubtenants(host); var found = false; for each (subtenant in subtenants) { if (subtenant.name.toLowerCase() == groupName.toLowerCase()) { System.log("Found group " + subtenant.name); found = true; break; } } if (!found) { throw "No group found for " + groupName; }
where groupName is an input of type string that is the exact group name (case sensitive) and host is an input of type vCACCAFE Host. THis is an action that returns a vCAC
Now we have everything we need to build our new reservation:
var newRes = new vCACCAFEReservation; newRes.name = resName; newRes.tenantId = tenantId ; newRes.subTenantId = subtenant.id; newRes.reservationTypeId = type ; newRes.extensionData = extensionData; newRes.alertPolicy = alertPolicy; newRes.setEnabled(enabled); newRes.setPriority(priority); var res = cafeHost.createReservationClient().getReservationReservationService().createReservation(newRes);
Inputs:
- resName String
- enabled Boolean
- priority Number
Once we're done we should have a new reservation created in both the vCAC and vCACCAFE.