This Python-based CLI tool provides a way to manage VMware Workstation VMs via VMware's REST API. You can interact with VMware to manage virtual machines (VMs), view network configurations, and start/stop the VMware REST server easily.
The tool works both in menu-driven mode and through command-line arguments. It simplifies interacting with the VMware Workstation REST API and allows automation of common VM management tasks.
- View all VMs and their power states.
- View the power state of a specific VM using its VM ID.
- Power on or off VMs by providing the VM ID.
- View all network configurations from the VMware REST API.
- Start the VMware Workstation REST server (
vmrest
). - Stop the VMware Workstation REST server (
vmrest
). - Configure your
vmworkstation.ini
file interactively. - Argument-based flags to run tasks automatically without interactive prompts.
- Python 3.x
- VMware Workstation Pro installed with the REST API feature (
vmrest
). - vmworkstation.ini file for configuring API connection details (base URL, username, password, and executable path for
vmrest
).
-
Clone this repository to your local machine.
git clone <your-repository-url>
-
Make sure VMware Workstation Pro is installed and its REST API (
vmrest
) is enabled. -
Install required Python packages if needed:
pip install requests
-
Configure your
vmworkstation.ini
file.Run the configuration tool for the first setup:
python3 vmrest.py --configure
This will prompt you to set up:
- The base URL (default:
http://127.0.0.1:8697/api
) - Your VMware username
- Your VMware password
- The path to the
vmrest
executable (default:/mnt/c/Program Files (x86)/VMware/VMware Workstation/vmrest.exe
)
- The base URL (default:
You can either run the tool as an interactive CLI menu or provide arguments at the command line to immediately trigger specific actions.
-
Show all VMs:
python3 vmrest.py --show-vms
-
Show all VM IDs:
python3 vmrest.py --show-vm-ids
-
Show Power State of a Specific VM (by VM ID):
python3 vmrest.py --show-power-state <VM_ID>
-
Power On a VM (by VM ID):
python3 vmrest.py --power-on <VM_ID>
-
Power Off a VM (by VM ID):
python3 vmrest.py --power-off <VM_ID>
-
Show all Networks:
python3 vmrest.py --show-net
-
Start VMware Workstation REST API Server: If you need to start the
vmrest
server manually:python3 vmrest.py --start-server
-
Stop VMware Workstation REST API Server: If you need to stop the
vmrest
server:python3 vmrest.py --stop-server
-
Configure vmworkstation.ini:
python3 vmrest.py --configure
If you run the script without an argument, it will launch an interactive menu where you can perform tasks manually.
python3 vmrest.py
The menu provides options such as:
- Show all VMs.
- Show all VM IDs.
- Show power state of a specific VM.
- Power on/off a VM.
- Start the VMware REST server.
- Stop the VMware REST server.
- Quit
To simplify running the script, a shell script (run_vmrest.sh
) is provided. It ensures that the Python script is run using the correct environment.
./run_vmrest.sh --show-vms
This command runs the Python script with the --show-vms
argument using the shell script.
-
Rest API Connection Errors:
Make sure that the REST API (vmrest
) server is running on the given base URL and port (e.g.,http://127.0.0.1:8697/api
). -
Invalid
vmrest
Path:
If you get an error indicating thatvmrest
cannot be found, reconfigure the.ini
file using the--configure
flag to set the correct executable path. -
Invalid Credentials:
Ensure that the correct username and password are provided, and these values match those required by the VMware Workstation REST API.