omni_orchestrator/schemas/v1/models/
worker.rs

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