vRO How to get information from Plugins

When I first started with vRO I struggled with how to use elements that the plugins discover.   It was really a struggle because I was used to PowerShell elements.   The real challenge was figuring out how to use the elements provided by the plugins.   The easiest way to explain how to mine this information is an example.  For example, I want to generate some basic information on all my datastores from all my connected vCenters.  We want to gather capacity, free space, percent free space and name.

 

We start by creating a basic workflow with and drag over a scriptable task:

script

Edit the scriptable task and you will be presented with:

Capture

This allows you to review the elements provided by the plugins to vRO.    Let’s do a quick search for datastores using the magnifying glass.  We locate a number of methods, attributes and scripting classes.

Capture

Inside here it’s important to understand the difference between Method, attribute, scripting class

  • Method – output’s an object of attributes
  • Attribute – specific data element
  • Scripting Class – Collections of objects and their available methods

For this section we are going to choose vcplugin.getAllDatastores() and choose to go to selection which will change our top pane to:

Capture

 

This tells us that this method will return an array of the object VcDatastore.   To see the individual elements in VcDatastore click on the blue VcDatastore

Capture

Each of the individual key value’s are listed you can click them for additional information.  Let’s create a array of object VcDatastore

Now let’s identify the values I want

  • Name
  • Capacity
  • Free Space
  • Percent free

Browsing the available values in the list I locate name which is the datastore name.   Let’s loop through the object’s and write all the names out to log.

Output on my home lab looks like this:

Capture

It worked.  Now we have to locate capacity of drive.   As you browse the available fields you will notice that some fields like info and summary return objects with additional fields.  You can click the blue link to learn more about available information for example summary returns object VcDatastoreSummary which if clicked has a ton of values:

Capture

Including two fields I want capacity and freespace.  Lets make sure they are correct with some easy code inserted inside our loop:

The output from the whole thing combined looks like this:

Capture

As you can see I have my required information.  The data is really not human readable so I want to create a function at the top to convert the data into GB’s.  Like this:

And let’s add it to our output inline:

Now my output is a lot more readable:

Capture

But wait I hate all that decimal point mess lets just round it up

Now the output looks much better:

Capture

Now we just need a percent of free space.  This one is not built in but it’s easy math.  (freespace / capacity *100 = percent free)  let’s do it inline:

The output has everything we need.

CaptureNow I understand that outputting this to log does not help you at all.  But from here you can feed this information into arrays or objects to be passed to additional workflow items.  I hope it helps you understand how to work with the methods provided.  If you want the whole script download it here: datastore

© 2016, Joseph Griffiths. All rights reserved.

2 thoughts on “vRO How to get information from Plugins

  1. Hi , Thanks for good article.
    Have you used “listDatastores” which requires host name?
    When I give host as string, it gives me error. I think it requires input as type VC:hostname and I don’t know how to send this from vRA property.

    Thank you
    Srini

Leave a Reply