Manage Learn to apply best practices and optimize your operations.

Scripting workflows with the VMware vRealize Orchestrator

Understanding the essential elements of how vRealize Orchestrator workflows work is just the first step to increasing functionality, simplicity and compartmentalization.

In the previous installment of our series on VMware vRealize Orchestrator, we looked at the components of vRealize...

Orchestrator workflows. The drag and drop interface we used is a front-end graphical user interface design tool that uses JavaScript to call the application programming interfaces VMware vRealize Orchestrator exposes.

If you browse through some of the more complex workflows in the design layout, you will see that they consist of several action items and decisions based on inputs from previous workflow items. Underlying all these workflows is JavaScript code. As with most Orchestrator platforms, there are several ways to create the same preferred output. If so desired, a developer can add a great deal of functionality to a single scriptable element rather than using several workflow items; doing so can aid simplicity and compartmentalization. Conversely, spaghetti code should be avoided with huge chunks of code. It is left to the customer’s best judgment to decide what fits best and when.

In order to look at all of the machines within the VirtualCenter (VC), start by creating a new workflow and a folder if you haven’t already. Drag a "scriptable task" element between the start and finish posts. Next, click on the scripting window and paste the following code directly into the window:

var vCenterServers = VcPlugin.allSdkConnections;

var poweredOnVMs = new Array();

var count;

var allVMs = vCenterServers[0].getAllVirtualMachines(null, null);

System.log("Num VMs = " + allVMs.length);

for (count = 0; count < allVMs.length; count++) {

    if (allVMs[count].runtime.powerState.value === "poweredOn") {

        System.log(allVMs[count].name + "\t" + allVMs[count].runtime.powerState.value + "\t" + (allVMs[count].summary.storage.committed/1024/1024/1024).toFixed(2) + " GB");

    }

}

This allows us to identify machines that are powered on, and shows how much storage each VM consumes in gigabytes. While using several workflow items via drag and drop would have been just as useful, using this self-contained code simplifies things by removing the need to sort inputs and outputs from the drag and drop.

Once you have entered the code shown above, complete it by using the close button at the bottom of the window. Click "Save" and "Saved Successfully" should appear in green at the bottom of the screen. This code will need to connect to the VC, so you will have to select the appropriate vCenter on the input.

When you run the code by selecting either "Run" or the play button at the top of the screen, you will see a list of the powered on VMs and the storage used by selecting the "Logs" tab. As shown in Figure A, this will provide details on all the VMs connected to that individual VM.

Figure A: Logs tab
Figure A: Logs tab

As you can see, it uses basic JavaScript for loop to move through all the VMs and, if the VM is turned on, calls for values for the data store usage.

Next, enter the following code to output the results to the log output:

System.log("Num VMs = " + allVMs.length)

Save the workflow and then run it.

By itself, this code fragment does something moderately useful by allowing you to pass data between additional scriptable elements as required. In order to use this functionality, you must "expose" the variables. However, doing so isn’t quite as straightforward as it may seem.

In order to fully appreciate how VMware vRealize Orchestrator works, you must understand that workflow parameters, input and output are all different things. Essentially, workflow parameters are variables available to the entire workflow and are used to transfer data between workflow elements. They could be considered global variables.

Inputs come from the user, an external service or another workflow object. For example, you can pass data from a PowerShell script into the workflow item with an input. This feature makes it easier to deal with multiple data sources. As their name suggests, outputs are used to push and pull data out to other workflow items. With outputs, you can pass any supported variable type or array as needed.

Another vRO feature that we have yet to discuss is change control. When you become familiar with building more advanced vRealize Orchestrator workflows, being able to revert to older versions is very useful. If you do need to review or revert a workflow, this is done by clicking on the "Show Version History" hyperlink on the general page. You are also able to view the difference between the current version and the saved version, should you so desire.

There is much that can be done with VMware vRealize Orchestrator, but first I would recommend looking into learning JavaScript, as just about everything in vRO uses JavaScript. It will take some time to get adjust to developing successful and useful workflows, but once you have mastered vRealize Orchestrator workflows and scripting it will make much of the manual work as simple as click and run.

Next Steps

Enhance your administrative powers with vRO

How do vRA and vRO build VM extensibility?

Increase your IT capability with the VMware vRealize Orchestrator

This was last published in January 2016

Dig Deeper on VMware how-tos

Join the conversation

1 comment

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

Other than JavaScript, what tools have you used to master vRealize Orchestrator?
Cancel

-ADS BY GOOGLE

SearchServerVirtualization

SearchVirtualDesktop

SearchDataCenter

SearchCloudComputing

Close