Python actions and environments
JavaScript is Orchestrator’s native language, but it isn’t the only one. An action or a scriptable task can also run Python, Node.js, PowerShell, or PowerCLI. Each runs outside the Rhino engine, in its own container, and can use the libraries of that language. That’s the reason to choose one: a Python package that parses certificates, talks to a vendor’s API, or reads a spreadsheet saves you writing the same thing in ES5.
In this recipe you write a small Python action with no extra packages, then build an environment that adds the cryptography package, and use it in an action that reports when a server’s TLS certificate expires. Last, you call that Python action from JavaScript.
Getting ready
- The action module
com.vcfguide.chapter4from recipe 4.1. - Access from the Orchestrator appliance to a Python package repository. That’s PyPI on the internet, or an internal mirror that offers the same “simple” index, such as a Nexus or Artifactory proxy.
- An administrator login, for the repository setting in step 4.
- A TLS server to test against. The examples use
vc01.vmw.labon port 443.
How to do it
Write a first Python action
- In Library > Actions, create the action
splitHostNamein the modulecom.vcfguide.chapter4. - On the Script tab, set the Runtime Environment to Python 3.14. Add one input,
fqdn, of typestring, and set the Return type toProperties. Leave Memory limit and Timeout at their defaults. - Replace the sample code with this script and click Save:
def handler(context, inputs): """Splits a fully qualified host name into the host and the domain.""" fqdn = inputs["fqdn"].strip().lower() host, _, domain = fqdn.partition(".") print("Run " + str(context.get("executionId")) + ": " + host + " in " + domain) return {"host": host, "domain": domain}- Run it with
fqdn=vc01.vmw.lab. The result ishost=vc01anddomain=vmw.lab, and the log shows the line printed byprint. The first run takes a few seconds longer than a JavaScript action, while Orchestrator starts the Python runtime.

context (the 9.x docs name vroURL and executionId; executionId works, as the script above shows).Allow a package repository
- As an administrator, open System Settings > Performance and Features > Environment Repositories.
- Choose where packages come from:
- To use PyPI (and npm, for Node.js), switch on Enable Default Public Repository for Environments under Default Public Repository. The switch carries the note I acknowledge the security implications of enabling the Default Public Repository. A second switch, Suppress the warning when selecting the Default Public Repository, stops the client from warning each time you pick it.
- To use an internal mirror, switch on Enable Additional Repositories for Environments, add the mirror, and pick it later for each dependency.
- Click Save. Saving this page restarts the Orchestrator server: a banner says Configuration Changes detected. The Orchestrator server is expected to restart in … seconds.

Build an environment
- Go to Assets > Environments and click New Environment.
- On the General tab, enter the name
vcfguide_python_cryptoand the descriptionPython 3.14 with cryptography, for the VCF Orchestrator Guide. - On the Definition tab, set the Runtime to Python 3.14. Under Dependencies, click Add and enter:
- Name:
cryptography - Version:
43.0.3 - Repository: the default, or your mirror
- Click Create. Orchestrator downloads the package and builds the environment. Open the Download Logs tab and check that
cryptographyand the packages it needs were installed. The log ends with Successfully installed and [Completed downloading dependencies], and the status next to the name reads Up To Date. Expect a few lines marked ERROR along the way: the log files everything pip writes to its error stream under that level, including harmless warnings. Judge the build by the last lines and the status, not by the colour.

Use the environment from an action
- Create the action
getCertificateExpiryincom.vcfguide.chapter4. On the Script tab, set the Runtime Environment to the environmentvcfguide_python_cryptoinstead of plain Python 3.14. - Add the inputs
hostNameof typestringandportof typenumber, and set the Return type toProperties. Enter this script:
import socketimport sslfrom datetime import datetime, timezone
from cryptography import x509
def handler(context, inputs): """Returns when the TLS certificate of hostName:port expires. Reads only.""" host = inputs["hostName"] port = int(inputs.get("port") or 443)
# Read the certificate whoever signed it: we only want its dates tls = ssl.create_default_context() tls.check_hostname = False tls.verify_mode = ssl.CERT_NONE with socket.create_connection((host, port), timeout=10) as sock: with tls.wrap_socket(sock, server_hostname=host) as conn: der = conn.getpeercert(binary_form=True)
cert = x509.load_der_x509_certificate(der) not_after = cert.not_valid_after_utc days_left = (not_after - datetime.now(timezone.utc)).days print(f"{host}:{port} certificate expires {not_after:%Y-%m-%d} ({days_left} days)") return { "host": host, "subject": cert.subject.rfc4514_string(), "notAfter": not_after.isoformat(), "daysLeft": days_left, }- Run it with
hostName=vc01.vmw.labandport=443. The result shows the certificate’s subject, its expiry date, and the days left.

Call it from JavaScript
- Python actions are called like any other. In a JavaScript action or scriptable task:
var expiry = System.getModule("com.vcfguide.chapter4").getCertificateExpiry("vc01.vmw.lab", 443);System.log(expiry.get("host") + " certificate expires in " + expiry.get("daysLeft") + " days");if (expiry.get("daysLeft") < 30) { System.warn("Renew the certificate of " + expiry.get("host") + " soon");}System.getModule, that the returned dictionary arrives as Properties, and whether daysLeft arrives as a number. Also confirm that the Python container can reach vc01.vmw.lab on port 443 (it runs on the appliance, so it should resolve lab names).How it works
A JavaScript action runs inside the Orchestrator server. A Python action doesn’t. When it’s called, Orchestrator turns the inputs into JSON, starts the chosen runtime in a separate container on the appliance, and calls your function handler(context, inputs). When the function returns, Orchestrator turns its return value back from JSON into the action’s return type. That’s why the action needs a typed return value, and why a Python function returns a plain dict where JavaScript returns Properties.
The JSON trip decides what you can pass:
- Inputs and return values can be
string,number,boolean,Date,Properties, composite types, and arrays of these. Adictmaps toProperties, and alistto an array. - Plug-in objects don’t cross. A Python action can’t take a
VC:VirtualMachineand call its methods, because the object lives in the Java process and the script doesn’t. Pass the VM’s name or ID as a string, and do the vSphere work in JavaScript or through the vCenter API from Python. contextcarries details of the call. The 9.x documentation namesvroURL, the address of the Orchestrator server, andexecutionId, the ID of the run.
Each runtime has limits per run, shown on the action’s Script tab as Memory limit (MB) and Timeout (seconds). The defaults are 64 MB of memory and 180 seconds for Python and Node.js, and 150 MB and 180 seconds for PowerShell and PowerCLI; on 9.1.1 the server reports the memory defaults through GET /vco/api/server-configuration/polyglot-runtimes. A run that goes over either limit fails. Change them on the action’s Script tab, or for every action that uses an environment, on the environment’s Definition tab.
An environment is a runtime plus the packages and environment variables your scripts need. Orchestrator downloads the packages once, when you create or change the environment, and every action that uses it gets them. Packages come only from the repositories allowed under Environment Repositories: PyPI for Python, npm for Node.js, and the PowerShell Gallery or another NuGet v2 feed for PowerShell. In VCF 9 the public repositories are off until an administrator turns them on.
On the lab’s Orchestrator 9.1.1, GET /vco/api/server-configuration/polyglot-runtimes returns exactly four runtimes: node:24, python:3.14, powershell:7.6 and powercli:9.1.1-powershell-7.6. Broadcom’s 9.1 core concepts page still says Node.js 20; the server is the one to trust. Run the same call on your own server before you pick a runtime.
There's more
9.1.2: type hints for inputs . From 9.1.2, the editor understands Python type hints for input parameters and checks references to them while you type. The release notes don’t show the syntax.
handler signature, or on inputs), how a typo in an input name is reported, and whether the hints change anything at run time.9.1.2: one page for every repository . From 9.1.2, the package repositories of step 5 and the Git repositories of recipe 6.3 are managed together under Administration > Repositories, where an administrator can search, filter, edit and delete them. Broadcom’s point is control: environments can only take packages from repositories an administrator approved. On 9.1.1 and earlier, use System Settings > Performance and Features > Environment Repositories as in step 5.
Keep the loop inside Python. Every call to a Python action starts a runtime, which costs seconds rather than milliseconds. Checking 50 certificates with 50 calls from a JavaScript loop is slow. Pass the list of hosts in one call, as an Array/string input, and loop in Python.
Pin your versions. Give every dependency an exact version, as in step 9. An environment with no version takes whatever is newest the next time it’s rebuilt, and an upgrade of a package you didn’t touch can break your action. Change versions on purpose, then run the actions that use the environment.
Read environment variables with os.environ. Values on the environment’s environment variables list reach the script as ordinary process environment variables, for example os.environ.get("LOG_LEVEL", "INFO"). Don’t keep passwords there: anyone who can open the environment can read them. Pass a secret as an input instead, from a configuration element (recipe 4.7).
Calling Orchestrator back. On 8.x, context also held a function getToken that returns a bearer token, so a Python script can call the Orchestrator REST API at vroURL as the user who started the run. Test it before you rely on it in VCF 9.
context“getToken” exists on 9.1.1 and returns a token that the REST API at context[“vroURL”] accepts.ZIP actions for bundled code. If a package isn’t in any repository you can reach, or your script is several files, set the action’s type to Zip, import a ZIP file, and set the entry handler. The default, handler.handler, means the function handler in the file handler.py at the top of the ZIP. For a function main in check.py, enter check.main. Put packages in the ZIP with pip install --target=. <package> before you zip the folder. An environment is easier to maintain, so prefer one when you can.
Packages that need system libraries. A few Python packages need operating system libraries that the runtime image doesn’t have, or are compiled for a different system. Broadcom’s 9.1 documentation has a page on configuring a Photon OS container for such Python packages. Read it before you fight a failed build in the Download Logs tab.
Debug in your own editor. Python and Node.js scripts can be debugged from an external IDE, which Broadcom’s documentation covers. PowerShell and PowerCLI scripts can’t.
See also
- 4.9 Reading inputs in Python, Node.js and PowerShell, for how each input type arrives in every runtime.
- 4.2 Writing and reusing actions, for action design and versions.
- 2.2 Replacing the appliance certificate, for what to do when
daysLeftgets small on Orchestrator itself. - Broadcom TechDocs (VCF 9.0): Scripting Environments in VCF Operations Orchestrator, Configuring Scripting Environments, and Runtime Limits for Scripts.
- Broadcom TechDocs (VCF 9.1): Scripting Environments in VCF Operations Orchestrator and Core Concepts for Using Python, Node.js, and PowerShell Scripts.
- Broadcom developer documentation (VCF Operations Orchestrator API, latest): Polyglot runtimes.
- The
cryptographypackage: x509 reference. - CloudBlogger, the author’s blog: List of All Available Python Modules in Orchestrator 9.1 and 8.x, How to return variables from a Python Runtime in Orchestrator workflow, Action Environments: Orchestrator Polyglot Script Environments, Comparative Analysis of Orchestrator Polyglot Approaches, Leveraging pyvmomi in VCF Operations Orchestrator.
