vRA – Get Reservation Policy ID from vRO

Introduction

I’ve been dealing with Reservations & Reservation Policies on vRA and found out that instead of using a SQL query, it was able to use vRO to pull Reservation Policy ID information out. In this blog post, I will go through both ways and explain the difference.

If you aren’t familiar with Reservation Policy ID, read the excellent blog by Kushmaro.

SQL Query

The following is the SQL query you could use in order to pull Reservation Policy ID out:

SELECT [id],[name] FROM [vCAC].[dbo].[HostReservationPolicy]

Login to SQL Management Studio and run the query above. If you don’t have access, ask database administrator to run it and get the output for you.

The attached screenshot below is a sample output:

5

It was quite easy, wasn’t it? Let’s take a look at vRO query.

vRO Query

It’s fairly simple to use vRO to query Reservation Policy ID. First of all, create a workflow and attach two attributes as the following:

6

For Reservation values, expand Reservations folder and add Reservations you would like to:

1

For vCACHost, select the vRA server.

Now, click on the Schema tab and drag and drop a scriptable task between start and end:

7

Edit the scriptable task and finish the Visual Binding like the below:

8

Navigate to Scripting tab and paste the script:

for each (var r in Reservation) {
  var reservationPolicyId = r.getEntity().getLink(vCACHost, "HostReservationPolicy");
  for each (var p in reservationPolicyId) {
    System.log("***********************************************");
    System.log("Reservation Policy Name is: ");
    System.log(p.getProperty('name'));
    System.log("Reservation Policy ID is: ");
    System.log(p.getProperty('id'));
    System.log("***********************************************");
  }
}

Run the workflow and a sample output is shown below:

4

Comparing both outputs from SQL and vRO, it seems different. There are 5 Reservation Policies from SQL whereas 3 from vRO. Why is this?

Difference

Let us first take a look at how many Reservation & Reservation Policies are there in the vRA environment I am connected to:

10

9

Even though there are 5 Reservation Policies, it does not mean that Reservations use all of them. In this case there are 3 Reservations and they are using only 2 Reservation Policies.

In summary, if you do a SQL query, it will show you Reservation Policy IDs across all Reservation Policies whereas vRO will only return you the ones being used by Reservations.

Hope this was useful and feel free to leave a comment for any clarifications.

Advertisements