omni_orchestrator/network/
discovery.rs

1// network/discovery.rs
2//
3// Discovers OmniCloud environment nodes
4
5use std::fmt;
6use serde::{Serialize, Deserialize};
7use uuid::Uuid;
8
9/// Types of nodes in an OmniCloud environment
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
11pub enum NodeType {
12    /// Master control node that manages system-wide operations
13    Master,
14    
15    /// Director node that manages virtualization and resources
16    Director,
17    
18    /// Orchestrator node that handles application scheduling
19    Orchestrator,
20    
21    /// Network controller node that manages connectivity
22    NetworkController,
23    
24    /// Application catalog node that stores application definitions
25    ApplicationCatalog,
26    
27    /// Storage node that provides persistent storage for volumes
28    Storage,
29    
30    /// Compute node that runs application workloads
31    Compute,
32    
33    /// Edge node that handles edge computing workloads
34    Edge,
35    
36    /// Gateway node that handles external connectivity
37    Gateway,
38    
39    /// Unknown node type
40    Unknown,
41}
42
43impl fmt::Display for NodeType {
44    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
45        match self {
46            NodeType::Master => write!(f, "Master"),
47            NodeType::Director => write!(f, "Director"),
48            NodeType::Orchestrator => write!(f, "Orchestrator"),
49            NodeType::NetworkController => write!(f, "NetworkController"),
50            NodeType::ApplicationCatalog => write!(f, "ApplicationCatalog"),
51            NodeType::Storage => write!(f, "Storage"),
52            NodeType::Compute => write!(f, "Compute"),
53            NodeType::Edge => write!(f, "Edge"),
54            NodeType::Gateway => write!(f, "Gateway"),
55            NodeType::Unknown => write!(f, "Unknown"),
56        }
57    }
58}
59
60/// Represents a node in an OmniCloud environment
61#[derive(Debug, Clone, Serialize, Deserialize)]
62pub struct EnvironmentNode {
63    /// Unique identifier for the node
64    pub id: String,
65    
66    /// Human-readable name of the node
67    pub name: String,
68    
69    /// Type of node
70    pub node_type: NodeType,
71    
72    /// IP address of the node
73    pub ip_address: String,
74    
75    /// Hostname of the node
76    pub hostname: String,
77    
78    /// Status of the node (e.g., "online", "offline", "maintenance")
79    pub status: String,
80    
81    /// Additional metadata about the node
82    pub metadata: Option<serde_json::Value>,
83}
84
85impl EnvironmentNode {
86    /// Create a new EnvironmentNode with default values
87    pub fn new(node_type: NodeType) -> Self {
88        Self {
89            id: Uuid::new_v4().to_string(),
90            name: format!("{}-{}", node_type, Uuid::new_v4().to_string().split('-').next().unwrap_or("node")),
91            node_type,
92            ip_address: "127.0.0.1".to_string(),
93            hostname: "localhost".to_string(),
94            status: "online".to_string(),
95            metadata: None,
96        }
97    }
98    
99    /// Create a new EnvironmentNode with specified values
100    pub fn with_details(
101        name: impl Into<String>,
102        node_type: NodeType,
103        ip_address: impl Into<String>,
104        hostname: impl Into<String>,
105        status: impl Into<String>,
106    ) -> Self {
107        Self {
108            id: Uuid::new_v4().to_string(),
109            name: name.into(),
110            node_type,
111            ip_address: ip_address.into(),
112            hostname: hostname.into(),
113            status: status.into(),
114            metadata: None,
115        }
116    }
117    
118    /// Check if the node is online
119    pub fn is_online(&self) -> bool {
120        self.status == "online"
121    }
122    
123    /// Convert the node into a JSON value
124    pub fn to_json(&self) -> serde_json::Value {
125        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
126    }
127}