How to enable the VMware Fusion REST API
Disclosure. This page contains links to products that may earn us a small commission at no extra cost to you, should you click on them and make a purchase. Read full disclosure.
This post will show you how to enable the VMware Fusion REST API so that you can manage vmnets and virtual machines without using the UI.
VMware Fusion* has a great macOS UI that has a native look and feel, unlike some of the open source alternatives. However, it’s not the only way to manage the VMs, you can also use the
vmrun command or enable the REST API.
Enabling the REST API allows you to write programs that automate tasks. It’s very simple to do and the following steps will show you how.
Step 1: Configure Credentials
Open the macOS Terminal and run the following command:
Enter a username then a password.
Step 2: Launch API
Run the following command to start the VMware Fusion REST API
You can change the listen address and port number with the following options:
vmrest -i 127.0.0.1 -p 8697
Step 3: Test API
Open a browser and navigate to http://localhost:8697/.
As you can see from the screenshot above, a webpage should load that lists the available endpoints and examples of how to consume them.
Let’s Test an Endpoint
Run the following command to list all the virtual machines:
curl 'http://localhost:8697/api/vms' -u 'root:Pa$$w0rd'
You can also base64 encode the username and password and pass it in the Authorization header. Run the following command to encode the username and password:
echo 'root:Pa$$w0rd' | base64 cm9vdDpQYSQkdzByZAo=
Then modify the API call to pass the encoded username and password in the header:
curl 'http://localhost:8697/api/vms' -X GET \ --header 'Authorization: Basic cm9vdDpQYSQkdzByZA=='
In this post we enabled the VMware Fusion* REST API. This opens up a number of automation capabilities that allow you to manage vmnets and virtual machines without using the UI. As an example, you could write an Ansible module that consumes the API.
Get notified when new posts are published to the blog by subscribing to the email list.Join the list