1#![warn(missing_docs)]
2
3pub mod errors;
8
9use serde::{Deserialize, Serialize};
10use std::collections::HashMap;
11use std::time::SystemTime;
12
13pub use crate::errors::*;
15
16#[deprecated(note = "请使用 DockerError 替代")]
18pub type RustyDockerError = DockerError;
19
20pub type Result<T> = std::result::Result<T, DockerError>;
22
23#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
25pub enum ContainerStatus {
26 Creating,
28 Running,
30 Stopped,
32 Paused,
34 Error(String),
36}
37
38#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
40pub struct ResourceLimits {
41 pub cpu_limit: f64,
43 pub memory_limit: u32,
45 pub storage_limit: u32,
47 pub network_limit: u32,
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize)]
53pub enum RestartPolicy {
54 None,
56 Always,
58 OnFailure(u32),
60 UnlessStopped,
62}
63
64#[derive(Debug, Clone, Serialize, Deserialize)]
66pub struct HealthCheck {
67 pub test: Vec<String>,
69 pub interval: u32,
71 pub timeout: u32,
73 pub retries: u32,
75 pub start_period: u32,
77}
78
79#[derive(Debug, Clone, Serialize, Deserialize)]
81pub struct DeployConfig {
82 pub replicas: u32,
84 pub resources: ResourceLimits,
86 pub restart_policy: RestartPolicy,
88 pub update_config: Option<UpdateConfig>,
90}
91
92#[derive(Debug, Clone, Serialize, Deserialize)]
94pub struct UpdateConfig {
95 pub parallelism: u32,
97 pub failure_action: String,
99 pub monitor: u32,
101 pub max_failure_ratio: f64,
103 pub order: String,
105}
106
107#[derive(Debug, Clone, Serialize, Deserialize)]
109pub struct ContainerConfig {
110 pub name: String,
112 pub image: String,
114 pub command: Vec<String>,
116 pub environment: HashMap<String, String>,
118 pub ports: HashMap<u16, u16>,
120 pub volumes: Vec<VolumeMount>,
122 pub resources: ResourceLimits,
124 pub network: NetworkConfig,
126 pub restart_policy: Option<RestartPolicy>,
128 pub healthcheck: Option<HealthCheck>,
130 pub deploy: Option<DeployConfig>,
132}
133
134#[derive(Debug, Clone, Serialize, Deserialize)]
136pub enum MountType {
137 Bind,
139 Volume,
141 Tmpfs,
143}
144
145#[derive(Debug, Clone, Serialize, Deserialize)]
147pub enum Consistency {
148 Default,
150 Consistent,
152 Delegated,
154 Cached,
156}
157
158#[derive(Debug, Clone, Serialize, Deserialize)]
160pub struct VolumeMount {
161 pub mount_type: MountType,
163 pub host_path: Option<String>,
165 pub volume_name: Option<String>,
167 pub container_path: String,
169 pub read_only: bool,
171 pub driver: Option<String>,
173 pub labels: Option<std::collections::HashMap<String, String>>,
175 pub consistency: Option<Consistency>,
177 pub tmpfs_size: Option<u64>,
179 pub tmpfs_mode: Option<u32>,
181}
182
183#[derive(Debug, Clone, Serialize, Deserialize)]
185pub struct NetworkConfig {
186 pub network_name: String,
188 pub static_ip: Option<String>,
190 pub hostname: Option<String>,
192 pub aliases: Option<Vec<String>>,
194 pub network_mode: Option<String>,
196 pub enable_ipv6: bool,
198}
199
200#[derive(Debug, Clone, Serialize, Deserialize)]
202pub struct ContainerInfo {
203 pub id: String,
205 pub name: String,
207 pub image: String,
209 pub status: ContainerStatus,
211 pub config: ContainerConfig,
213 pub created_at: SystemTime,
215 pub started_at: Option<SystemTime>,
217 pub stopped_at: Option<SystemTime>,
219 pub pid: Option<u32>,
221 pub network_info: NetworkInfo,
223}
224
225#[derive(Debug, Clone, Serialize, Deserialize)]
227pub struct NetworkInfo {
228 pub ip_address: Option<String>,
230 pub ports: HashMap<u16, u16>,
232 pub network_name: String,
234}
235
236#[derive(Debug, Clone, Serialize, Deserialize)]
238pub struct ImageInfo {
239 pub id: String,
241 pub name: String,
243 pub tags: Vec<String>,
245 pub size: u64,
247 pub created_at: SystemTime,
249 pub architecture: String,
251 pub os: String,
253}
254
255#[derive(Debug, Clone, Serialize, Deserialize)]
257pub struct NetworkConfigInfo {
258 pub name: String,
260 pub network_type: String,
262 pub subnet: String,
264 pub gateway: String,
266 pub containers: Vec<String>,
268}
269
270#[derive(Debug, Clone, Serialize, Deserialize)]
272pub struct DockerConfig {
273 pub data_dir: String,
275 pub image_dir: String,
277 pub container_dir: String,
279 pub network_dir: String,
281 pub default_network: String,
283 pub default_resources: ResourceLimits,
285 pub log_config: LogConfig,
287}
288
289#[derive(Debug, Clone, Serialize, Deserialize)]
291pub struct LogConfig {
292 pub log_level: String,
294 pub log_file: String,
296 pub max_log_size: u32,
298}
299
300#[derive(Debug, Clone, Serialize, Deserialize)]
302pub struct VolumeInfo {
303 pub id: String,
305 pub name: String,
307 pub size: u64,
309 pub created_at: SystemTime,
311 pub mount_point: String,
313 pub driver: String,
315 pub labels: HashMap<String, String>,
317 pub used_by: Vec<String>,
319}
320
321#[derive(Debug, Clone, Serialize, Deserialize)]
323pub struct SystemResourceUsage {
324 pub cpu_usage: f64,
326 pub memory_used: u32,
328 pub memory_total: u32,
330 pub storage_used: u32,
332 pub storage_total: u32,
334 pub network_sent: u32,
336 pub network_received: u32,
338}
339
340#[derive(Debug, Clone, Serialize, Deserialize)]
342pub struct SystemInfo {
343 pub os_type: String,
345 pub os_version: String,
347 pub kernel_version: String,
349 pub architecture: String,
351 pub hostname: String,
353 pub cpu_cores: u32,
355 pub total_memory: u32,
357}
358
359#[derive(Debug, Clone, Serialize, Deserialize)]
361pub enum DockerDaemonStatus {
362 Running,
364 Stopped,
366 Error(String),
368}
369
370#[derive(Debug, Clone, Serialize, Deserialize)]
372pub struct SystemStatus {
373 pub daemon_status: DockerDaemonStatus,
375 pub resource_usage: SystemResourceUsage,
377 pub system_info: SystemInfo,
379 pub container_stats: ContainerStats,
381}
382
383#[derive(Debug, Clone, Serialize, Deserialize)]
385pub struct ContainerStats {
386 pub running: u32,
388 pub stopped: u32,
390 pub total: u32,
392}
393
394#[derive(Debug, Clone, Serialize, Deserialize)]
396pub enum ServiceStatus {
397 Created,
399 Running,
401 Updating,
403 Error(String),
405}
406
407#[derive(Debug, Clone, Serialize, Deserialize)]
409pub struct ServiceInfo {
410 pub id: String,
412 pub name: String,
414 pub status: ServiceStatus,
416 pub image: String,
418 pub replicas: u32,
420 pub ports: HashMap<u16, u16>,
422 pub environment: HashMap<String, String>,
424 pub volumes: Vec<VolumeMount>,
426 pub created_at: SystemTime,
428 pub updated_at: SystemTime,
430}
431
432#[derive(Debug, Clone, Serialize, Deserialize)]
434pub enum NodeRole {
435 Manager,
437 Worker,
439}
440
441#[derive(Debug, Clone, Serialize, Deserialize)]
443pub enum NodeAvailability {
444 Active,
446 Pause,
448 Drain,
450}
451
452#[derive(Debug, Clone, Serialize, Deserialize)]
454pub enum NodeStatus {
455 Ready,
457 Down,
459 Unknown,
461}
462
463#[derive(Debug, Clone, Serialize, Deserialize)]
465pub struct NodeInfo {
466 pub id: String,
468 pub name: String,
470 pub role: NodeRole,
472 pub availability: NodeAvailability,
474 pub status: NodeStatus,
476 pub address: String,
478 pub version: String,
480 pub containers_running: u32,
482 pub labels: HashMap<String, String>,
484}
485
486#[derive(Debug, Clone, Serialize, Deserialize)]
488pub struct SwarmInfo {
489 pub id: String,
491 pub name: Option<String>,
493 pub managers: u32,
495 pub workers: u32,
497 pub services: u32,
499 pub tasks: u32,
501 pub version: String,
503 pub created_at: SystemTime,
505}
506
507#[derive(Debug, Clone, Serialize, Deserialize)]
509pub struct ConfigInfo {
510 pub id: String,
512 pub name: String,
514 pub data: String,
516 pub created_at: SystemTime,
518 pub labels: HashMap<String, String>,
520}
521
522#[derive(Debug, Clone, Serialize, Deserialize)]
524pub struct SecretInfo {
525 pub id: String,
527 pub name: String,
529 pub created_at: SystemTime,
531 pub labels: HashMap<String, String>,
533 pub digest: String,
535}
536
537#[derive(Debug, Clone, Serialize, Deserialize)]
539pub enum EndpointType {
540 Local,
542 Remote,
544 Cloud,
546}
547
548#[derive(Debug, Clone, Serialize, Deserialize)]
550pub enum EndpointStatus {
551 Connected,
553 Connecting,
555 Failed(String),
557 Disconnected,
559}
560
561#[derive(Debug, Clone, Serialize, Deserialize)]
563pub struct EndpointConfig {
564 pub id: String,
566 pub name: String,
568 pub endpoint_type: EndpointType,
570 pub url: String,
572 pub use_tls: bool,
574 pub tls_cert_path: Option<String>,
576 pub tls_key_path: Option<String>,
578 pub tls_ca_path: Option<String>,
580 pub auth_token: Option<String>,
582 pub labels: HashMap<String, String>,
584}
585
586#[derive(Debug, Clone, Serialize, Deserialize)]
588pub struct EndpointInfo {
589 pub config: EndpointConfig,
591 pub status: EndpointStatus,
593 pub created_at: SystemTime,
595 pub last_connected_at: Option<SystemTime>,
597 pub connection_info: Option<SystemInfo>,
599}