omni_orchestrator/network/
discovery.rs1use std::fmt;
6use serde::{Serialize, Deserialize};
7use uuid::Uuid;
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
11pub enum NodeType {
12 Master,
14
15 Director,
17
18 Orchestrator,
20
21 NetworkController,
23
24 ApplicationCatalog,
26
27 Storage,
29
30 Compute,
32
33 Edge,
35
36 Gateway,
38
39 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#[derive(Debug, Clone, Serialize, Deserialize)]
62pub struct EnvironmentNode {
63 pub id: String,
65
66 pub name: String,
68
69 pub node_type: NodeType,
71
72 pub ip_address: String,
74
75 pub hostname: String,
77
78 pub status: String,
80
81 pub metadata: Option<serde_json::Value>,
83}
84
85impl EnvironmentNode {
86 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 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 pub fn is_online(&self) -> bool {
120 self.status == "online"
121 }
122
123 pub fn to_json(&self) -> serde_json::Value {
125 serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
126 }
127}