Skip to content

Scripting and environments

Chapter 3 drew workflows. This chapter is about the code inside them. Every scriptable task, action, scripted decision, and form action is a script, and the quality of those scripts decides whether a workflow is easy to trust and change, or a puzzle for whoever opens it next.

Recipe 4.1 starts with the engine that runs your JavaScript, and why this book keeps to plain ES5.1. Recipe 4.2 turns scripts into a library of small actions that other workflows call, and shows how to change them without breaking anything. Recipe 4.3 steps outside JavaScript to Python, and to the environments that give a script its packages. Recipes 4.4 and 4.5 do the same for Node.js, with its callbacks, and for PowerShell and PowerCLI, with their habit of returning more than you meant. The last two recipes are about habits that apply in every language: recipe 4.6 makes scripts leave a useful log behind, and recipe 4.7 moves settings and credentials out of code and into configuration elements. Recipe 4.9 goes back to the three other runtimes side by side, to show how each input type reaches a Python, Node.js or PowerShell script.

Most examples in this chapter are actions, so they go in one module:

Object Name
Action module com.vcfguide.chapter4
Workflow folder, for anything that needs one VCF Orchestrator Guide/Chapter 4
Environments vcfguide_python_crypto, vcfguide_node_semver
Configuration elements, in the folder VCF Orchestrator Guide/Chapter 4 vcfguide-settings, and vc01.vmw.lab in the subfolder vCenters

Like Chapter 3, the examples only read from the lab: the vCenter vc01.vmw.lab, its VMs and snapshots, and the TLS certificate it presents. The PowerCLI examples connect to it with a read-only account, svc-vcfguide-ro@vsphere.local. JavaScript samples, including those for the Node.js runtime, are plain ES5.1, except where recipe 4.9 shows Node.js promises and async on purpose. Python samples are ordinary Python 3.14, and PowerShell samples run in PowerShell 7.6.

Writing JavaScript in Orchestrator has hardly changed. Almost everything around it has.

Back in vRO 5.5–7Write every script in JavaScript, in the Java client's script editor, with the API Explorer in a separate window.
In Orchestrator 9.xWrite scripts in JavaScript, Python, Node.js, PowerShell, or PowerCLI, in the browser client's editor, with autocomplete and the API Explorer in the same client.
Back in vRO 5.5–7Reach for an external library by copying its code into an action, or by running it on another machine over SSH.
In Orchestrator 9.xAdd packages from PyPI, npm, or a NuGet feed to an environment, and choose that environment as the runtime of an action.
Back in vRO 5.5–7Keep track of action changes with a version number you raise by hand.
In Orchestrator 9.xEvery save of an action is kept on its Version History tab, ready to compare and restore.