vRA Developer: Part 7 – Working with vCAC Reservation Entities


Reservations are created in vRA to allocate memory, storage and network resources to a business group. Business groups can consume these resources by provisioning virtual machines.

In this post I am going to cover the vCAC Reservation Entities and provide some workflows and actions that can be used to get information about reservations programmatically. This can be useful to gather information about the reservations if you are using custom XaaS processes that would not trigger the standard built-in reservation checks.

All code that I have provided or talked about in this post can be downloaded as a vRO package for your consumption here.

I have also included a number of workflows in the package, which provide examples of these actions being used.

You can find these under ‘Simplygeek -> Library -> Common Workflows -> vRealize Automation -> Examples -> Reservations

Get a List of Available Reservations or Get a Specific Reservation

The following code can be used to get a list of all reservations that are available for the specified tenant or retrieve a specific reservation based on its name or unique id.

This is specifically the reservation that I will be working with and will appear in the log outputs.

Get List of Available Reservations For a Tenant

The following code will accept a tenant Id and a toggle for retrieving only enabled reservations. A list of reservation string names will be returned. This isn’t as straight forward as you would hope (at least from an entities point of view), because there is no property for the tenant id on the reservation. Instead, I had to inspect the business group that the reservation is assigned to, which does have a tenant id property (it’s quite possible this is how the gui does it too).

Log output:

Find Reservation Entity By Name

The following code accepts the tenant id and the reservation name and will return the vcac reservation entity object. I decided to get the reservation for a specific tenant, although i’m, not sure if a name collision can occur with reservations. Either way, I prefer to narrow the search field but this can be removed if required (but I can’t see any reason to do that).

Log output:

Find Reservation Entity By ID

The following code accepts the tenant id and the reservation id and will return the vcac reservation entity object. Also see my other comments for ‘Get Reservation Entity By Name’.

Log output

Get Reservation Property Values

The reservation entity object has a method ‘.getProperty(“key_string”)‘ that can be used to retrieve a value for a specified property key. When I need to retrieve a value for a property on a reservation, I use a helper Action that calls this method and does the main part of the work. I then wrap other Actions around this for the specific property that I need the value for. This can seem a little repetitive but with all the Actions in place, I simply drop them onto my workflows without any thought.

I have created Actions that can retrieve the value for the following reservation properties, where the correct data type is returned (note this is not the complete set of properties available but the only ones you are ever going to need).

Property Data Type Description
HostReservationID string The reservation entity id
HostReservationName string The reservation name
Enabled boolean A flag to indicate whether the reservation is enabled or not
ReservationMemorySizeMB number The total memory that has been allocated to the reservation
ReservationStorageSizeGB number The total storage that has been allocated to the reservation. Note this includes all storage reserved across all datastores
ReservationPriority number The reservation priority

I will provide example code for getting one of these properties, but the package link at the beginning of this post will provide Actions for all the above properties.

The following code is the main helper action that retrieves the property value (you will have seen this same code in my previous posts as it’s common code).

This is an example of one of the Actions which acts as a wrapper for the above, that is used to get the reservation priority.

Log output:

Get Reservation Custom Properties

Just like virtual machines, custom properties can also be created on reservations (see my previous post: vRA Developer: Part 6 – Working with vCAC Virtual Machine Custom Properties. Although these are generally not used extensively, they can be useful for storing meta data on the reservation that is then inherited by the virtual machine. One use case I have seen is assigning a site specific ID as a custom property on the reservation, which is then assigned to the virtual machines using the reservation.

I added some custom properties to the reservation for the purpose of running this code:

Get Reservation Custom Properties Set

The following code will accept a reservation entity and will return a Properties object that contains all the key/value pairs of the custom properties. In my example, I have created 2 custom properties on the reservation which you can see are being returned in the log output:

Log output:

Get a Specific Custom Property Value from the Set

If you would like to get a specific custom property from the reservation, then please see my previous post: vRA Developer: Part 6 – Working with vCAC Virtual Machine Custom Properties  in the section ‘Get a Specific Custom Property Value from the Set‘, that provides code examples of how this can be achieved.

Get Reservation Linked Entities and Associated Properties

There are additional properties that can be retrieved which are part of other entities that the reservation has a relationship with. Here are some examples of information that can be retrieved through linked entities (the code for all of these examples is included in the package link provided at the beginning of this post).

  • Tenant Id
  • Business Group Name
  • Compute Cluster Name
  • Resource Pool Name
  • Reserved Storage Paths
  • Reserved Networks Paths
  • Reservation Policy Name
  • Virtual Machines using the reservation

The reservation entity object has a method ‘.getLink(vcacHost, “linkKey_string”)‘ that can be used to get the linked entity objects. The ‘.getProperty(“key_string”)‘ can then be used on these entities to get a specific property value, such as the business group.

Get Tenant Id

This one was interesting. The usual usage of .getLink failed to return any of the ProvisioningGroups (business groups) for the reservation (I need to do this because the tenant Id is a property of the business group). Even though when using system queries against this data, it works. No matter what I tried, the set would always return empty. I had to take a sub optimal, long winded approach and get all the provisioning groups, and then work backwards to the reservation. In the process I created a helper to get the business group entity and then create wrappers around this:

Then the actual wrapper action that gets the tenant id:

Log output:

Get Business Group Name

For this I took the same approach as getting the tenant id and created a wrapper around the business group helper action to get the name.

Log output:

Get Compute Cluster Name

The following code can be used to get the compute cluster name that the reservation is assigned to.

Log output:

Get Resource Pool Name

The following code can be used to get the resource pool name that the reservation is assigned to.

Log output:

Get Reserved Storage Paths

The following code will get a list of storage paths that have been configured on the reservation.

Log output:

Get Reserved Networks Paths

The following code will get a list of network paths that have been configured on the reservation.

Log Output:

Get Reservation Policy Name

The following code gets the reservation policy name that has been assigned to the reservation.

Log output:

Get A list of Virtual Machines using the Reservation

The following code will get a list of virtual machines that have been provisioned using this reservation. Unlike my other actions, this will not output the name of each virtual machine to the console. The list will only be returned as an array, which can be output with a follow on script, if required. The list could be large and I didn’t want to flood the console too much.

Log output:

I still want to cover more ground on reserved storage for a reservation, but as that content was ever growing, I decided to split them over 2 posts. So I’ll conclude this and provide a follow on post, which will exclusively cover reservation storage.

I hope this has been useful. If you discover bugs with any of my code, require some help or simply need an ad-hoc solution, then please drop me a message via the Drift app.

Please rate this post!

Average rating / 5. Vote count:

Leave a Reply

avatar
  Subscribe  
Notify of