A lightweight C++ utility designed to automate the lifecycle of Proxmox VE Virtual Machines and LXC Containers. This tool interacts directly with the Proxmox REST API to start, stop, or shutdown instances, making it ideal for managing development environments that do not need to run 24/7.
- Direct API Integration: Uses
libcurlto communicate with the Proxmoxapi2/jsonendpoints. - Secure Authentication: Supports Proxmox API Tokens (PVEAPIToken), avoiding the need to store user passwords in plain text.
- Resource Optimization: Can be coupled with Cron jobs to automatically shut down high-resource development servers (e.g., Odoo Dev) at night and wake them in the morning.
- Container & VM Support: Easily configurable for both QEMU VMs and LXC Containers.
- OS: Ubuntu/Debian (or any Linux distro)
- Libraries:
libcurlsudo apt update sudo apt install libcurl4-openssl-dev
- Proxmox: Access to a Proxmox VE server (Version 6.0+).
To use this tool securely, generate an API Token in your Proxmox GUI:
- Go to Datacenter > Permissions > API Tokens.
- Click Add.
- User:
root@pam(or your preferred user). - Token ID:
coqui_automation(or similar). - Important: Uncheck "Privilege Separation" if running as root, or assign specific permissions.
- Copy the Secret immediately (you won't see it again).
Edit the vm_scheduler.cpp file with your specific infrastructure details:
'cpp const std::string PROXMOX_HOST = "https://192.168.1.50:8006"; const std::string NODE_NAME = "pve"; const std::string API_USER = "root@pam!user_automation"; const std::string API_TOKEN = "YOUR_UUID_SECRET_KEY"; const std::string TARGET_VM_ID = "105"; // The ID of the VM to control
Note: If controlling a VM (QEMU) instead of a Container (LXC), change /lxc/ to /qemu/ in the url string construction in the source code.
Bash
g++ -std=c++17 vm_scheduler.cpp -o vm_sched -lcurl
Bash
./vm_sched start
Bash
./vm_sched shutdown
Bash
./vm_sched stop
Automation Example (Cron)
- To save electricity and server resources, add this to your crontab (crontab -e) to shut down the server every night at 8 PM: Bash
0 20 * * * /path/to/vm_sched shutdown >> /var/log/vm_sched.log 2>&1