proxmox-lxc-autoscale-ml

LXC AutoScale API Documentation

LXC AutoScale API is a powerful RESTful interface designed to give you programmatic control over LXC containers hosted on a Proxmox server. With this API, you can automate and fine-tune various aspects of container management, including resource allocation, snapshots, and cloning. Whether you’re looking to optimize performance during peak hours or conserve resources at night, the LXC AutoScale API offers the flexibility to tailor container behavior to your specific needs.

Summary

Routes

The LXC AutoScale API provides a range of endpoints that allow you to interact with your Proxmox host programmatically. Below is a comprehensive list of available routes, along with examples of how to use each one.

Endpoint Methods Description Example
/scale/cores POST Set the exact number of CPU cores for an LXC container. curl -X POST http://proxmox:5000/scale/cores -H "Content-Type: application/json" -d '{"vm_id": 104, "cores": 4}'
/scale/ram POST Set the exact amount of RAM for an LXC container. curl -X POST http://proxmox:5000/scale/ram -H "Content-Type: application/json" -d '{"vm_id": 104, "memory": 4096}'
/scale/storage/increase POST Increase the storage size of an LXC container’s root filesystem. curl -X POST http://proxmox:5000/scale/storage/increase -H "Content-Type: application/json" -d '{"vm_id": 104, "disk_size": 2}'
/snapshot/create POST Create a snapshot for an LXC container. curl -X POST http://proxmox:5000/snapshot/create -H "Content-Type: application/json" -d '{"vm_id": 104, "snapshot_name": "my_snapshot"}'
/snapshot/list GET List all snapshots for an LXC container. curl -X GET "http://proxmox:5000/snapshot/list?vm_id=104"
/snapshot/rollback POST Rollback to a specific snapshot. curl -X POST http://proxmox:5000/snapshot/rollback -H "Content-Type: application/json" -d '{"vm_id": 104, "snapshot_name": "my_snapshot"}'
/clone/create POST Clone an LXC container. curl -X POST http://proxmox:5000/clone/create -H "Content-Type: application/json" -d '{"vm_id": 104, "new_vm_id": 105, "new_vm_name": "cloned_container"}'
/clone/delete DELETE Delete a cloned LXC container. curl -X DELETE http://proxmox:5000/clone/delete -H "Content-Type: application/json" -d '{"vm_id": 105}'
/resource/vm/status GET Check the resource allocation and usage for an LXC container. curl -X GET "http://proxmox:5000/resource/vm/status?vm_id=104"
/resource/node/status GET Check the resource usage of a specific node. curl -X GET "http://proxmox:5000/resource/node/status?node_name=proxmox"
/health/check GET Perform a health check on the API server. curl -X GET http://proxmox:5000/health/check
/routes GET List all available routes. curl -X GET http://proxmox:5000/routes

Detailed Descriptions

These routes offer a wide range of functionality, enabling comprehensive management of your LXC containers via simple HTTP requests.


Logs

Logging is a critical component of managing and troubleshooting the LXC AutoScale API. The service generates several log files that provide detailed information about its operations.

Log Files

Log Management

Regularly review these logs to monitor the health and performance of the API service. Consider implementing log rotation to manage disk space, especially in environments with high API traffic. You can use tools like logrotate to automate the rotation, compression, and removal of old log files.

Example logrotate configuration:

/var/log/autoscaleapi*.log {
    daily
    missingok
    rotate 7
    compress
    delaycompress
    notifempty
    create 640 root adm
    sharedscripts
    postrotate
        systemctl reload lxc_autoscale_api.service > /dev/null 2>&1 || true
    endscript
}

This configuration rotates the log files daily, keeps seven days of logs, compresses old logs, and ensures the service continues to operate without interruption.


Best Practices and Tips

1. Secure Your API

Given that the API allows direct control over LXC containers, it’s crucial to secure it properly. Consider the following measures:

2. Monitor API Usage

Regularly monitor the autoscaleapi_access.log file to track API usage. Look for unusual patterns that could indicate unauthorized access or potential misuse of the API.

3. Automate Routine Tasks

Use cron jobs in combination with API requests to automate routine tasks such as scaling resources or creating snapshots. This reduces manual intervention and helps maintain optimal performance.

4. Test Before Production

When implementing new API routes or making changes to existing ones, always test in a non-production environment first. This helps ensure that the commands work as expected without disrupting live services.

5. Document Your API Usage

Maintain documentation of how your environment interacts with the LXC AutoScale API, including the routes used, the purpose of each request, and any scripts or automation tools that rely on the API. This documentation is invaluable for troubleshooting and for onboarding new team members.