VMware Cloud Community
aenagy
Hot Shot
Hot Shot
Jump to solution

How to find backing Compute (vSphere Cluster) resource for a vRA Reservation (vRA + vRO 7.3)

I have a workflow that is able to enumerate all vCACCAFEReservations and pull some basic information (very difficult considering the complexity of the schema, but that's a different story). My problem is identifying the Compute resource, e.g. vSphere Cluster, for a particular Reservation. I searched the API explorer and can't find anything viable. There are no properties of the Reservation that would indicate a Compute resource and there doesn't seem to be a ClassId for "Compute". Neither the vCACCAFEFabricGroup nor vCACCAFEFabricGroupService are of any help. The only idea I have is to back reference either the network or storage vCACCAFEEntityReference data but this would require two hops, e.g. vCACCAFEEntityReference --> vCACCAFENetwork.getNetworkBackings() --> vCACCAFENetworkBacking.getComputResourceName().

I'm hoping there is something I have overlooked. Anyone done something like this before or have a better idea, or am I stuck with the two-hop approach?

0 Kudos
1 Solution

Accepted Solutions
eoinbyrne
Expert
Expert
Jump to solution

You can use the following approach to get the reservations from the CAFE REST API directly - you'll just need to process the JSON result yourself

// assume you can get a vCACCAFE:VCACHost object

var client = cafeHost.createRestClient("com.vmware.vcac.core.cafe.reservation.api");

// returns a vCACCAFEServiceResponse

var allReservationsResponse = client.get("/reservations");

// get as JSON object

var reservationsData = allReservationsResponse.getBodyAsJson();

// you need to pick apart the JSON object here but there will be a computeResource entry

// which has the label of the target host/cluster

Have a look at the API explorer on code.vmware.com for details of other REST calls

-HTH

View solution in original post

0 Kudos
5 Replies
eoinbyrne
Expert
Expert
Jump to solution

You can use the following approach to get the reservations from the CAFE REST API directly - you'll just need to process the JSON result yourself

// assume you can get a vCACCAFE:VCACHost object

var client = cafeHost.createRestClient("com.vmware.vcac.core.cafe.reservation.api");

// returns a vCACCAFEServiceResponse

var allReservationsResponse = client.get("/reservations");

// get as JSON object

var reservationsData = allReservationsResponse.getBodyAsJson();

// you need to pick apart the JSON object here but there will be a computeResource entry

// which has the label of the target host/cluster

Have a look at the API explorer on code.vmware.com for details of other REST calls

-HTH

0 Kudos
aenagy
Hot Shot
Hot Shot
Jump to solution

eoinbyrne​:

That worked. Kinda, in the smaller vRA environment all 12 of the reservations were capture but in the larger environment only 20 of 34 reservations were captured. Is this a paging thing?

BTW, how did you find "com.vmware.vcac.core.cafe.reservation.api"?

Thanks.

0 Kudos
eoinbyrne
Expert
Expert
Jump to solution

Yep, most likely paging in the larger environment. I think the default page count is 20 for most the vRA REST APIs

Here's the Swagger API page for the call you're using

vRealize Automation Reservation Service API - VMware API Explorer - VMware {code}

pastedImage_1.png

It allows for the following parameters to be embedded in the request

pastedImage_2.png

So, your URI for the client.get() line can be modified as follows

"/reservations?page=1&limit=50"

to return the first 50 entries. Note that I've had mixed luck with changing the page size against some of the APIs in vRA so I generally process the metadata on the response if a bigger page size has no effect

pastedImage_10.png

If you use totalPages you can just load back the pages one by one in a loop using "/reservations?page=<pagenumber>". I've not really used the filtering much as simple brute-force tends to suit my regular needs here. I'd suspect filtering would be very useful to understand for APIs or types where you've got lots (000's) of entries (e.g, Resources or Requests)

On the service id, you can get all the available service endpoint IDs using this class from the plugin

pastedImage_3.png

Each Enum entry there corresponds to an API service endpoint in vRA. So technically you could change this line

var client = cafeHost.createRestClient("com.vmware.vcac.core.cafe.reservation.api");

to be

var client = cafeHost.createRestClient(vCACCAFEServicesEnum.RESERVATION_SERVICE);

I just had the code lying around with the String ID for the reservation service in it. Most likely the best practice would be to refer to the enums so that your workflow has a better chance of working against future versions of the plugin (i.e., if the service ID strings change in a future release...)

HTH

0 Kudos
aenagy
Hot Shot
Hot Shot
Jump to solution

eoinbyrne​:

On a guess I made the following change to your code:

var allReservationsResponse = client.get("/reservations?limit=100");

Now it works perfectly. It's going to take a while to make the transition from SOAP to REST.

0 Kudos
aenagy
Hot Shot
Hot Shot
Jump to solution

eoinbyrne​:

Using "vCACCAFEServicesEnum.RESERVATION_SERVICE" is a handy trick I haven't seen before. Kinda makes me wish VMware had an advanced vRO scripting course.

Thanks.

0 Kudos