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.
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 |
/scale/cores
: Allows you to set a specific number of CPU cores for a container. This is useful for adjusting resources based on the time of day or anticipated workload./scale/ram
: Lets you set the amount of RAM for a container. This can be used to allocate more memory during peak usage or reduce it during off-hours to save resources./scale/storage/increase
: Increases the storage size of the container’s root filesystem. This endpoint is particularly useful when a container’s storage requirements grow over time./snapshot/create
: Creates a snapshot of a container. Snapshots are essential for backup and recovery, allowing you to restore a container to a previous state if needed./snapshot/list
: Lists all snapshots for a given container. This endpoint helps you manage and review the available snapshots./snapshot/rollback
: Rolls back a container to a specific snapshot. Use this endpoint to revert changes made during the day or after testing new configurations./clone/create
: Clones a container, creating an exact copy under a new VM ID. This is ideal for testing or duplicating environments without affecting the original container./clone/delete
: Deletes a cloned container. This endpoint helps keep your environment clean by removing containers that are no longer needed./resource/vm/status
: Retrieves the current resource allocation and usage for a specific container, helping you monitor its performance./resource/node/status
: Provides an overview of the resource usage on a specific Proxmox node, allowing you to manage and optimize node performance./health/check
: Performs a health check on the API server to ensure it’s running correctly. This is useful for automated monitoring and alerting systems./routes
: Lists all available API routes, providing an overview of the endpoints you can interact with.These routes offer a wide range of functionality, enabling comprehensive management of your LXC containers via simple HTTP requests.
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.
/var/log/autoscaleapi.log
: The main log file for the API, containing detailed information about API requests, responses, and any internal processing./var/log/autoscaleapi_access.log
: Logs all incoming requests to the API, including timestamps, request methods, endpoints accessed, and the source IP addresses. This log is essential for monitoring API usage and identifying potential security issues./var/log/autoscaleapi_error.log
: Captures errors encountered by the API service. Reviewing this log can help diagnose issues and ensure that the API runs smoothly.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.
Given that the API allows direct control over LXC containers, it’s crucial to secure it properly. Consider the following measures:
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.
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.
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.
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.