I've read through all the examples i could find on the forums and on blog sites but nothing seems to work. Not sure if its a bug or me doing something wrong...
I'm attempting to fix some scripts that were broken by the API paging in 7.2. I have something like:
Server.getAllReservations
for each reservation
if reservation.name == name
return reservation
With the paging that breaks so I'm trying to use the find methods with queries but cant get them to work in this instance. I'm trying something like:
vCACCAFEEntitiesFinder.findReservations(host, 'reservationName');
or
vCACCAFEEntitiesFinder.findReservations(host, "xpath:name='reservationName'");
but its throwing the error "java.lang.reflect.InvocationTargetException"
If i leave the query off i get an array of 25 of my 250+ reservations.
Any suggestions on the syntax of the query for finding the reservation by name?
Hi pizzle85, not sure if you figured this out already or not. I ran into a similar problem quite recently where we went over the 100 page limit of the vRA plugin when using vCACCAFEEntitiesFinder to return all the reservations. Here is the code we now use to get the reservations by name where you can set the number of pages and the number of results per page. We run this in a workflow with the following inputs:
cafeHost (vCACCAFE:VCACHOST) //vRA host to search against
resName (string) //name of the reservation
//note that the code really is reservationReservationService, this isn't a typo
//create a new connection to the reservation service
var reservationClient = cafeHost.createReservationClient();
var reservationReservationService = reservationClient.getReservationReservationService();
//set up the filter you want to use for the query i.e. the reservation name
var filter = new Array();
filter[0] = vCACCAFEFilterParam.equal("name",vCACCAFEFilterParam.string(resName));
var query = vCACCAFEOdataQuery.query().addFilter(filter);
//set request parameters as 1 page with 10,000 results and use the filtered query built in the previous steps
var oDataRequest = new vCACCAFEPageOdataRequest(1, 10000, query);
//perform the request
var results = reservationReservationService.getAllReservations(oDataRequest);
//retrieve the results
var reservations = results.getContent();
if(reservations.length == 1){
var reservationName = reservations[0].name;
}
else{
System.log("More than one reservation found by the search");
}
I haven't, i'll give that a try.
That amount of code to find something is ridiculous.
The SDK team is supposedly going to put in a bug request to write up documentation on how to query the VMware provided vRO plugins using the native find methods.
Hi pizzle85,
I found a better way to solve this (not perfect, but works). I haven't found the query for vCACCAFEEntitiesFinder.findReservations, but I found a nice workaround:
1) Find the VcacReservation with this:
var VcacReservations = Server.findAllForType("vCAC:Reservation", "HostReservationName eq '" + reservationName + "'");
2) Get the CafeReservation by ID:
var cafeReservation = vCACCAFEEntitiesFinder.getReservation(cafeHost , VcacReservations[0].hostReservationID);
That's it, only two lines of code.
I hope that this helps you.
D.