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.

Advertisement

4 thoughts on “vRA – Get Reservation Policy ID from vRO

  1. Nice writeup Steve. Really helpful.
    A query here for “var reservationPolicyId = r.getEntity().getLink(vCACHost, “HostReservationPolicy”);”

    How did u get to know that attribute HostReservationPolicy has to be used? I searched through vRO scripting class and looked into vCACReservation , but couldnt find this.

    Did you take reference from database schema ?

    Thanks.

    1. Thanks Saurav.

      I searched for individual links from the getEntity() output. Since I attached Reservation Policy to the Reservations, I knew that vCAC:Reservation must have Reservation Policy information somewhere.

      This might not be a good answer but this is what I did 😦

      Regards.
      Steven.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s