Skip to main content

paygress/
compute.rs

1// Compute Backend Trait
2//
3// Abstracts the underlying container/VM platform (Proxmox vs LXD)
4
5use async_trait::async_trait;
6use anyhow::Result;
7use serde::{Deserialize, Serialize};
8
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct NodeStatus {
11    pub cpu_usage: f64,    // 0.0 to 1.0
12    pub memory_used: u64,  // bytes
13    pub memory_total: u64, // bytes
14    pub disk_used: u64,    // bytes
15    pub disk_total: u64,   // bytes
16}
17
18#[derive(Debug, Clone)]
19pub struct ContainerConfig {
20    pub id: u32,
21    pub name: String,
22    pub image: String,
23    pub cpu_cores: u32,
24    pub memory_mb: u32,
25    pub storage_gb: u32,
26    pub password: String,
27    pub ssh_key: Option<String>,
28    pub host_port: Option<u16>,
29}
30
31#[async_trait]
32pub trait ComputeBackend: Send + Sync {
33    /// Find an available ID in the given range
34    async fn find_available_id(&self, range_start: u32, range_end: u32) -> Result<u32>;
35    
36    /// Create a new container
37    async fn create_container(&self, config: &ContainerConfig) -> Result<String>; // Returns container ID/Name
38    
39    /// Start a container
40    async fn start_container(&self, id: u32) -> Result<()>;
41    
42    /// Stop a container
43    async fn stop_container(&self, id: u32) -> Result<()>;
44    
45    /// Delete a container
46    async fn delete_container(&self, id: u32) -> Result<()>;
47    
48    /// Get node resource usage
49    async fn get_node_status(&self) -> Result<NodeStatus>;
50    
51    /// Get public IP of the container/VM
52    async fn get_container_ip(&self, id: u32) -> Result<Option<String>>;
53}