VirtuX Pro provides robust automation capabilities through its REST API and Command Line Interface (CLI), allowing users to efficiently deploy, configure, and manage virtual machines (VMs). This guide details how to automate VM deployments using these tools.
To interact with VirtuX Pro's API, you need to authenticate using an API token.
- Obtain an API token from the VirtuX Pro web interface.
- Use the token in the authorization header for API requests.
Example:
curl -X GET "https://api.virtuxpro.com/v1/vms" \
-H "Authorization: Bearer YOUR_API_TOKEN"You can deploy a VM using the following API request:
curl -X POST "https://api.virtuxpro.com/v1/vms" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "MyVM",
"cpu": 4,
"memory": 8192,
"disk": 50,
"os": "Ubuntu 22.04"
}'- Start VM:
curl -X POST "https://api.virtuxpro.com/v1/vms/{vm_id}/start" \ -H "Authorization: Bearer YOUR_API_TOKEN"
- Stop VM:
curl -X POST "https://api.virtuxpro.com/v1/vms/{vm_id}/stop" \ -H "Authorization: Bearer YOUR_API_TOKEN"
- Delete VM:
curl -X DELETE "https://api.virtuxpro.com/v1/vms/{vm_id}" \ -H "Authorization: Bearer YOUR_API_TOKEN"
VirtuX Pro provides a CLI for quick and scriptable interactions.
Install the VirtuX CLI using:
pip install virtux-cliAuthenticate using your API token:
virtux login --token YOUR_API_TOKENvirtux vm create --name MyVM --cpu 4 --memory 8192 --disk 50 --os "Ubuntu 22.04"- List VMs:
virtux vm list
- Start a VM:
virtux vm start --id vm_id
- Stop a VM:
virtux vm stop --id vm_id
- Delete a VM:
virtux vm delete --id vm_id
You can use shell scripts to automate bulk deployments. Example:
#!/bin/bash
for i in {1..5}
do
virtux vm create --name "VM-$i" --cpu 2 --memory 4096 --disk 20 --os "Ubuntu 22.04"
doneSave this as deploy_vms.sh and run:
chmod +x deploy_vms.sh
./deploy_vms.shVirtuX Pro supports integration with Terraform and Ansible.
Example Terraform script:
provider "virtux" {
token = "YOUR_API_TOKEN"
}
resource "virtux_vm" "example" {
name = "MyTerraformVM"
cpu = 2
memory = 4096
disk = 30
os = "Ubuntu 22.04"
}Run:
terraform init
terraform applyWith VirtuX Pro's REST API and CLI, users can efficiently automate VM management, integrate with DevOps tools, and optimize their cloud infrastructure. For further details, refer to the official VirtuX Pro API Documentation.