Quantcast
Channel: VMware – The Practical Administrator
Viewing all articles
Browse latest Browse all 12

Populate vRO workflow inputs from WFA 3.0 using REST

$
0
0

One of the challenges when using the NetApp vRO Package for WFA has been making the inputs dynamically populate with the correct information from WFA. If you add a new volume, aggregate, SVM, or other entity to your NetApp, you want it to show up in your workflows to be able to take advantage of it. There are workarounds, such as using the database or creating a filter/finder to retrieve the information, but each of those was flawed, primarily because they would not be updated to use new query parameters automatically if the WFA admin updated the workflow. Fortunately, WFA 3.0 has fixed this by adding a new REST method to the workflows namespace which will return the valid values back for you.

New WFA REST method for retrieving workflow input values

To take advantage of this we need a helper action to retrieve the values from WFA, and another helper to provide the dependent inputs and extract the information we want from the response and put it into the correct format for a vRO input.

Querying WFA User Input Values Using REST

The first thing we need to do is create a helper action to abstract the query action. This simply removes the complexity of making the REST call to a single action with a single set of inputs, making it easier to execute without having to recreate the wheel each time. If you are using the NetApp vRO Package for WFA version 3.0 or above, this action should already be available to you. If not, I recommend that you download the package now!

There are three major sections to the action:

  • Accept dependent inputs and make them ready for the GET operation
  • Query WFA for the valid values
  • Parse the result and put it into a more usable format

If you’re interested in the code, be sure to download the NetApp vRO Package for WFA and look at the action at com.netapp.oncommand.wfa -> getUserInputValues.

Integrating the values with your workflows

Now that we have the ability to easily query for valid values, let’s see how we put it to work. This will be similar to the previous post where we used a finder to populate the values in a workflow.

A workflow input, for WFA or vRO, can have zero or more input values which contribute to determining the valid values. For example, you can’t get a list of NetApp volumes without first knowing the cluster and storage virtual machine at a minimum, and sometimes you want/need the aggregate as well. This can be highly dependent on the WFA workflow as well, sometimes you’ll need all three of those, sometimes only one or two. To make things even more complicated, WFA is case sensitive, which means that the workflow name, input name, and contributing values all must match cases exactly.

Creating an Action to query WFA
Let’s use our trusty Create a Clustered Data ONTAP Volume workflow from before. Recall that it has four inputs:

  • ClusterName
  • VserverName
  • VolumeName
  • VolumeSizeInGB

We need to create a custom vRO action for each of the vRO inputs we want populated with values from WFA. We need to create these to account for the variances in the names of the input values as well as the return data we want to retrieve. Here is the code of the action to retrieve the ClusterName. Note that this action has a single input “workflowName”, which is the same as is used by the parent vRO workflow, and is not shown here.

# this is the name of the WFA input we are querying for
var inputName = "ClusterName";
 
# if there are any dependent parameters, they would be provided here
var dependentParameters = new Properties;
 
# execute the action referenced above, which abstracts querying WFA
# for the valid input values
var query = System.getModule("com.netapp.oncommand.wfa").getUserInputValues(workflowName, inputName, dependentParameters);
 
# a new variable to store the values returned by the action
var ret = new Array();
 
# iterate over the returned values, looking for the column name we
# want.  when found, add it to the array of return values
for(var i = 0 ; i < query.length ; i++) {
    # this value, "Name", is determined by the WFA SQL query
    ret[i] = query[i].get("Name");
}
 
# exit the action, returning the values
return ret;

The name of the column in the return data that’s used for populating the array values is determined by the SQL query in WFA. If that sounds confusing, well, it is. To determine what you should use here you can either use the WFA GUI or use the REST interface manually.

To use the GUI, edit the workflow, then click the “Setup” button in the upper left corner.

View WFA workflow setup

Once the setup details popup opens, browse to the “User Inputs” tab, then double click the input you’re interested in.

Edit WFA user input

In the new popup, there will be a link in the middle which will read “View or edit the SQL query executed at run time”. Click this link.

View query input SQL

This will open a new window with some SQL in it. You’ll notice in this example that Name is being used to refer to the name of the cluster.

WFA query input SQL

Populating vRO workflow inputs

Now that we have created an action which queries WFA for our values and returns an array of strings (which is used to populate a dropdown in a vRO workflow), we need to integrate it with the workflow’s inputs.

Start by editing the workflow, and browsing to the “Presentation” tab. Select the input, then, in the bottom pane, select the “Properties” tab.

Editing vRO workflow inputs

Edit the value by clicking the purple puzzle piece. Note that if your input doesn’t look like the above screen shot, you will need to change it to an OGNL input (change the box with a line on the left side to the two ended arrow). Search for the name of the action you created, mine is named WFAGetCluster. Select it, then edit the value for the needed input by clicking the pencil icon.

Edit vRO input values

If you followed from the original workflow creation, then you will have a workflow attribute named wfaWorkflowName. Select this as the value. Alternatively, you can use a text input and simply type the name of the source workflow (remember it’s case sensitive!).

At this point, click the OK button, then switch to the “Schema” view in the main workflow edit screen. Click the debug button and bask in your awesomeness!

showing a dynamically populated input

Taking it further

You can follow these same basic steps for any of the query inputs from your WFA workflow. If there are other inputs which the one you are querying for depends on, then you simply need to add them to the action’s inputs and populate the dependent inputs properties array. I have attached an example workflow and the dependent actions here as a reference.

If you have any questions, please don’t hesitate to reach out to me using the comments below, the NetApp Community private message system (my username is asulliva), or using email (my communities username at netapp.com).

The post Populate vRO workflow inputs from WFA 3.0 using REST appeared first on The Practical Administrator.


Viewing all articles
Browse latest Browse all 12

Trending Articles