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
//! A library for writing CNI plugins in Rust.
//!
//! This crate is the *plugin* side of CNI: the process a container runtime invokes.
//! For the calling side, see `rscni-runtime` (planned).
//!
//! Write a type that implements the `Cni` trait, then pass it to `Plugin::run`.
//! `Plugin::run` reads the `CNI_*` environment variables and stdin, calls the method for
//! the requested operation, and writes the result. Both `Cni` and `Plugin` are in the
//! [`cni`] module. The [`async_cni`] module has async versions of both, behind the
//! `async` feature.
//!
//! The specification types both sides exchange live in
//! [`rscni-types`](https://docs.rs/rscni-types) and are re-exported here, so
//! `rscni_plugin::types::NetConf` and `rscni_types::types::NetConf` are the same type.
//!
//! Complete examples:
//! [rscni-debug](https://github.com/terassyi/rscni/blob/main/examples/rscni_debug.rs) and
//! [async-rscni-debug](https://github.com/terassyi/rscni/blob/main/examples/async_rscni_debug.rs).
//!
//! # Quick start
//!
//! ```rust,no_run
//! # use rscni_plugin::{
//! # cni::{Cni, Plugin},
//! # error::Error,
//! # types::{Args, CNIResult},
//! # };
//! #
//! # struct MyPlugin;
//! #
//! # impl Cni for MyPlugin {
//! # fn add(&self, args: Args) -> Result<CNIResult, Error> {
//! # // Implement network setup logic
//! # Ok(CNIResult::default())
//! # }
//! #
//! # fn del(&self, args: Args) -> Result<(), Error> {
//! # // Implement network teardown logic
//! # Ok(())
//! # }
//! #
//! # fn check(&self, args: Args) -> Result<(), Error> {
//! # // Implement network check logic
//! # Ok(())
//! # }
//! #
//! # fn status(&self, _args: Args) -> Result<(), Error> {
//! # // Implement plugin readiness check
//! # Ok(())
//! # }
//! #
//! # fn gc(&self, _args: Args) -> Result<(), Error> {
//! # // Implement garbage collection logic
//! # Ok(())
//! # }
//! # }
//! #
//! let my_plugin = MyPlugin;
//! let plugin = Plugin::default();
//! plugin.run(&my_plugin).expect("Failed to run CNI plugin");
//! ```
/// The error type returned by every CNI operation.
///
/// Re-exported from [`rscni_types::error`].
/// CNI specification types, plus the plugin-side invocation input.
///
/// The specification types are re-exported from [`rscni_types::types`];
/// [`Args`](crate::types::Args) is defined by this crate.
/// Plugin version reporting and negotiation.
///
/// Re-exported from [`rscni_types::version`].