Skip to content

RamonRiosJr/proxmox-vm-scheduler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Proxmox VM Scheduler

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.

Features

  • Direct API Integration: Uses libcurl to communicate with the Proxmox api2/json endpoints.
  • 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.

Prerequisites

  • OS: Ubuntu/Debian (or any Linux distro)
  • Libraries: libcurl
    sudo apt update
    sudo apt install libcurl4-openssl-dev
  • Proxmox: Access to a Proxmox VE server (Version 6.0+).

API Token Setup

To use this tool securely, generate an API Token in your Proxmox GUI:

  1. Go to Datacenter > Permissions > API Tokens.
  2. Click Add.
  3. User: root@pam (or your preferred user).
  4. Token ID: coqui_automation (or similar).
  5. Important: Uncheck "Privilege Separation" if running as root, or assign specific permissions.
  6. Copy the Secret immediately (you won't see it again).

Configuration

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.

Compilation

Bash

g++ -std=c++17 vm_scheduler.cpp -o vm_sched -lcurl

Usage

Start the Server:

Bash

./vm_sched start

Graceful Shutdown:

Bash

./vm_sched shutdown

Force Stop (Kill):

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

Maintained By

Coqui Cloud - IT Solutions & Custom Software

About

A background service that interacts with the Proxmox API (via libcurl) to automatically start up or shut down specific development containers based on a schedule (e.g., "Sleep Mode" for dev servers at night to save power/resources).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages