Have you ever tried to automate a specific vSphere operation but were sure which vSphere API to use or if known, how to actually use it? This is something I frequently see and get asked about quite often!
Did you know about this hidden little gem that has been available since vSphere 6.7, built right into the vSphere UI that can help with these questions!?
It is called vSphere Code Capture or what I typically refer to as your ChatGPT for vSphere Automation, but without the hallucinations 😀
Even as someone who is intimately familiar with the vSphere API, vSphere Code Capture is a tool I used on a pretty regular basis whether that is helping a customer with a question or writing a quick script.
vSphere Code Capture is super easy to use, simply navigate to Developer Center->Code Capture and then enable the feature if you have not already and begin recording. It will start capturing all UI operations performed in that session using the vSphere UI. Once you have finished and stopped the recording, you be able to see which vSphere APIs were used but also how they were used along with specific arguments to each API.
The output for vSphere Code Capture includes the following vSphere SDKs: PowerCLI, Aria Orchestrator, Pyvmomi (vSphere SDK for Python) and Govmomi (vSphere SDK for Go), which you can simply toggle via a dropdown to see the output.
While the output can be pretty verbose as it is using the vSphere APIs directly, you can determine the specific vSphere API method being used by looking at the annotated comments. In the example above, I have captured a typical VM reconfiguration workflow which includes changing the CPU, Memory, resizing an existing disk and adding a new disk ... all of which uses the the same vSphere VM API called ReconfigureVM_Task().
Once you know the specific vSphere API methods that are used, then you can search for them by using the vSphere Web Services API Reference documentation to better understand the required parameters and their meaning. Along with the working example provided by vSphere Code Capture, you now have all the information to either create your own script or application for your desired vSphere Automation.
There are some limitations to be aware of when using vSphere Code Capture, such as not being able to capture operations pertaining to vSphere Roles, Privileges, Tags, Content Libraries, and VM Storage Policies which is also mentioned in the vSphere Code Capture documentation. Additionally, not all vSphere functionality is consumable from within the vSphere UI, so those operations would also not be captured. Lastly, any functionality that is exposed via the vSphere Automation (REST) API is currently NOT recorded as part of vSphere Code Capture.
vSphere Code Capture is extremely powerful and can help both new and existing users to quickly ramp up on using the vSphere APIs. I am hopeful that in the future we will also be able to include functionality from the vSphere Automation API, so that this tool can be the go to solution for when users have questions on which or how to automate a specific vSphere operation.