I’m a long-time user of Workstation Pro. My main purpose is for labs as I prefer to host them within software than expensive hardware.
Hardware is great but there are too many limitations (Initial cost, power, cooling, maintenance, space, patching) and for me, Workstation Pro works perfectly provided that my machine has enough memory.
As I use Workstation all the time, I frequently find myself wanting to automate VM provisioning and management, however, the only way I could do this in the past was by installing my VMs inside an ESXi host which was running inside Workstation. While this does work for me I have to have a few layers of virtualisation and this can cause headaches and unnecessary compute and storage utilization.
The other week I heard that Workstation 15 Pro was being shipped with a REST API, this was something I had to look into further.
Watch my video or follow the instructions below to get started:
Setting up the API
First, you need to be running Workstation 15 Pro. I’m running it on Windows but the API also works in Linux.
- Once you have installed or upgraded Workstation Pro, open a command prompt
- CD to your installation folder:
cd "C:\Program Files (x86)\VMware\VMware Workstation"
- Run the vmrest configuration
- Specify a new username and password
- Once complete, you can open %USERPROFILE%\vmrest.cfg to view the configuration that you just created
- Now run vmrest to launch the API service
Using the API
- Launch the API Browser in a web browser
- Authenticate to the system with the “Authorization” button
- Enter the previously created credentials
- Now you can browse the API Explorer
- Locate an API call that you are interested in. For example, expand the GET /vms API call
- Scroll down and select “Try It Out”
- This will run the call against your live Workstation instance and return the result which will be a list of all your VMs running in Workstation Pro with their IDs and VMX paths
- Copy the Curl command and paste it into Command Prompt to get a feel for the API outside of the API explorer (In Windows you may need to replace the single quotes with double quotes
curl "http://127.0.0.1:8697/api/vms" -X GET --header "Accept: application/vnd.vmware.vmw.rest-v1+json" --header "Authorization: Basic cmVzdF91c2VyOlZNd2FyZTEh"
And that’s it. You can use the API calls from a scripting or programming language of your choice.