libomni/types/db/v1/
worker.rs

1use serde::{Deserialize, Serialize};
2use chrono::{DateTime, Utc};
3
4#[derive(Debug, Clone, Serialize, Deserialize, sqlx::Type)]
5#[sqlx(type_name = "ENUM", rename_all = "snake_case")]
6pub enum WorkerStatus {
7    Active,
8    Provisioning,
9    Maintenance,
10    PoweredOff,
11    Unreachable,
12    Degraded,
13    Decommissioning,
14}
15
16// Default implementation for WorkerStatus
17impl Default for WorkerStatus {
18    fn default() -> Self {
19        WorkerStatus::Active
20    }
21}
22
23// Function to provide default status for serde
24pub fn default_status() -> WorkerStatus {
25    WorkerStatus::Active
26}
27
28// Function to provide default SSH port
29pub fn default_ssh_port() -> i32 {
30    22
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
34pub struct Worker {
35    pub id: Option<i64>,
36    pub region_id: i64,
37    pub name: String,
38    pub provider_id: Option<String>,
39    pub instance_type: Option<String>,
40    pub status: String,
41    pub cpu_total: f64,
42    pub cpu_available: f64,
43    #[serde(default)]
44    pub cpu_reserved: f64,
45    pub memory_total: f64,     // in MB
46    pub memory_available: f64, // in MB
47    #[serde(default)]
48    pub memory_reserved: f64,  // in MB
49    pub disk_total: f64,       // in MB
50    pub disk_available: f64,   // in MB
51    #[serde(default)]
52    pub disk_reserved: f64,    // in MB
53    pub network_in_capacity: Option<f64>,  // in Mbps
54    pub network_out_capacity: Option<f64>, // in Mbps
55    pub docker_version: Option<String>,
56    pub ssh_address: Option<String>,
57    #[serde(default = "default_ssh_port")]
58    pub ssh_port: i32,
59    pub ssh_user: Option<String>,
60    pub ssh_key: Option<String>,
61    pub labels: Option<serde_json::Value>,
62    pub taints: Option<serde_json::Value>,
63    pub annotations: Option<serde_json::Value>,
64    pub last_heartbeat: Option<DateTime<Utc>>,
65    pub created_at: Option<DateTime<Utc>>,
66    pub updated_at: Option<DateTime<Utc>>,
67}