A Python script for powering on, powering off, rebooting, or checking the power state of a Nutanix VM through Prism Central.
- Finds a VM by name
- Shows the current VM power state
- Powers on a VM
- Powers off a VM
- Reboots a VM by powering it off and then powering it on again
- Waits for Nutanix Prism Central tasks to finish
- Requires
--forcefor power-off and reboot actions - Uses only the Python standard library
- Python 3.8 or newer
- Network access to Nutanix Prism Central
- A valid Nutanix Prism Central API token
- Permission to read and update VMs
No external Python packages are required.
Before running the script, update these values in nutanix_vm_power.py:
NTNX_PRISMCENTRAL_IP = "YOUR_IP:9440"
PC_TOKEN = "YOUR GENERATED TOKEN FROM nutanix_auth.py"Show VM power status:
python nutanix_vm_power.py --vm my-vm01 --action statusPower on a VM:
python nutanix_vm_power.py --vm my-vm01 --action onPower off a VM:
python nutanix_vm_power.py --vm my-vm01 --action off --forceReboot a VM:
python nutanix_vm_power.py --vm my-vm01 --action reboot --forceUse custom task polling settings:
python nutanix_vm_power.py \
--vm my-vm01 \
--action on \
--timeout 600 \
--interval 10| Argument | Required | Description |
|---|---|---|
--vm |
Yes | VM name |
--action |
Yes | status, on, off, or reboot |
--force |
No | Required for off and reboot |
--timeout |
No | Task timeout in seconds, default 300 |
--interval |
No | Task polling interval in seconds, default 5 |
Power-off and reboot actions require --force to reduce the chance of accidental shutdowns.
Do not commit real API tokens, passwords, Prism Central addresses, or internal infrastructure details to a public GitHub repository.
The script currently disables SSL certificate verification by using:
ssl._create_unverified_context()This may be useful in lab environments, but it is not recommended for production. For production use, configure proper certificate validation.
This script is provided as an example. Test it in a safe environment before using it against production Nutanix infrastructure.