1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
use crate::api::{Labels, ObjectVersion, TlsInfo}; use serde::{Deserialize, Serialize}; #[cfg(feature = "chrono")] use chrono::{DateTime, Utc}; #[derive(Serialize, Debug)] pub enum Membership { Accepted, Pending, } impl AsRef<str> for Membership { fn as_ref(&self) -> &str { match &self { Membership::Accepted => "accepted", Membership::Pending => "pending", } } } #[derive(Serialize, Debug)] pub enum Availability { Active, Pause, Drain, } impl AsRef<str> for Availability { fn as_ref(&self) -> &str { match &self { Availability::Active => "active", Availability::Pause => "pause", Availability::Drain => "drain", } } } #[derive(Clone, Serialize, Deserialize, Debug)] #[serde(rename_all = "lowercase")] pub enum NodeRole { Manager, Worker, } impl AsRef<str> for NodeRole { fn as_ref(&self) -> &str { match &self { NodeRole::Manager => "manager", NodeRole::Worker => "worker", } } } #[derive(Clone, Serialize, Deserialize, Debug)] #[serde(rename_all = "lowercase")] pub enum NodeReachability { Unknown, Unreachable, Reachable, } #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "PascalCase")] pub struct NodeInfo { #[serde(rename = "ID")] pub id: String, pub version: ObjectVersion, #[cfg(feature = "chrono")] pub created_at: DateTime<Utc>, #[cfg(not(feature = "chrono"))] pub created_at: String, #[cfg(feature = "chrono")] pub updated_at: DateTime<Utc>, #[cfg(not(feature = "chrono"))] pub updated_at: String, pub spec: Option<NodeSpec>, pub description: Option<NodeDescription>, pub status: Option<NodeStatus>, pub manager_status: Option<ManagerStatus>, } #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] pub enum NodeState { Unknown, Down, Ready, Disconnected, } #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] pub enum NodeAvailability { Active, Pause, Drain, } #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "PascalCase")] pub struct NodeStatus { pub state: Option<NodeState>, pub message: Option<String>, pub addr: Option<String>, } #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "PascalCase")] pub struct NodeSpec { pub name: Option<String>, pub labels: Labels, pub role: Option<NodeRole>, pub availability: Option<NodeAvailability>, } #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "PascalCase")] pub struct NodeDescription { pub hostname: Option<String>, pub platform: Option<Platform>, pub resources: Option<ResourceObject>, pub engine: Option<EngineDescription>, #[serde(rename = "TLSInfo")] pub tls_info: Option<TlsInfo>, } #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "PascalCase")] pub struct EngineDescription { pub engine_version: Option<String>, pub labels: Option<Labels>, pub plugins: Option<Vec<serde_json::Value>>, } #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "PascalCase")] pub struct ResourceObject { #[serde(rename = "NanoCPUs")] pub nano_cpus: i64, pub memory_bytes: i64, pub generic_resources: Vec<serde_json::Value>, } #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "PascalCase")] pub struct Platform { pub architecture: Option<String>, pub os: Option<String>, } #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "PascalCase")] pub struct ManagerStatus { pub leader: Option<bool>, pub reachability: Option<NodeReachability>, pub addr: Option<String>, }