1use 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, pub memory_used: u64, pub memory_total: u64, pub disk_used: u64, pub disk_total: u64, }
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 async fn find_available_id(&self, range_start: u32, range_end: u32) -> Result<u32>;
35
36 async fn create_container(&self, config: &ContainerConfig) -> Result<String>; async fn start_container(&self, id: u32) -> Result<()>;
41
42 async fn stop_container(&self, id: u32) -> Result<()>;
44
45 async fn delete_container(&self, id: u32) -> Result<()>;
47
48 async fn get_node_status(&self) -> Result<NodeStatus>;
50
51 async fn get_container_ip(&self, id: u32) -> Result<Option<String>>;
53}