Cni

Enum Cni 

Source
pub enum Cni {
    Add {
        container_id: String,
        ifname: String,
        netns: PathBuf,
        path: Vec<PathBuf>,
        config: NetworkConfig,
    },
    Del {
        container_id: String,
        ifname: String,
        netns: Option<PathBuf>,
        path: Vec<PathBuf>,
        config: NetworkConfig,
    },
    Check {
        container_id: String,
        ifname: String,
        netns: PathBuf,
        path: Vec<PathBuf>,
        config: NetworkConfig,
    },
    Version(Version),
}
Expand description

The main entrypoint to this plugin and the enum which contains plugin input.

See the field definitions on Inputs for more details on the command subfields.

Variants§

§

Add

The ADD command: add namespace to network, or apply modifications.

A CNI plugin, upon receiving an ADD command, should either:

  • create the interface defined by ifname inside the namespace at the netns path, or
  • adjust the configuration of the interface defined by ifname inside the namespace at the netns path.

More details in the spec.

Fields

§container_id: String

The container ID, as provided by the runtime.

§ifname: String

The name of the interface inside the container.

§netns: PathBuf

The container’s “isolation domain” or namespace path.

§path: Vec<PathBuf>

List of paths to search for CNI plugin executables.

§config: NetworkConfig

The input network configuration.

§

Del

The DEL command: remove namespace from network, or un-apply modifications.

A CNI plugin, upon receiving a DEL command, should either:

  • delete the interface defined by ifname inside the namespace at the netns path, or
  • undo any modifications applied in the plugin’s ADD functionality.

More details in the spec.

Fields

§container_id: String

The container ID, as provided by the runtime.

§ifname: String

The name of the interface inside the container.

§netns: Option<PathBuf>

The container’s “isolation domain” or namespace path.

May not be provided for DEL commands.

§path: Vec<PathBuf>

List of paths to search for CNI plugin executables.

§config: NetworkConfig

The input network configuration.

§

Check

The CHECK command: check that a namespace’s networking is as expected.

This was introduced in CNI spec v1.0.0.

More details in the spec.

Fields

§container_id: String

The container ID, as provided by the runtime.

§ifname: String

The name of the interface inside the container.

§netns: PathBuf

The container’s “isolation domain” or namespace path.

§path: Vec<PathBuf>

List of paths to search for CNI plugin executables.

§config: NetworkConfig

The input network configuration.

§

Version(Version)

The VERSION command: used to probe plugin version support.

The plugin should reply with a VersionReply.

Note that when using Cni::load(), this command is already handled, and you should mark this unreachable!().

Implementations§

Source§

impl Cni

Source

pub fn from_env() -> Result<Self, CniError>

Reads the plugin inputs from the environment and STDIN.

This reads and validates the required CNI_* environment variables, and the STDIN for a JSON-encoded input object, but it does not output anything to STDOUT nor exits the process, nor does it panic.

Note that as per convention, the CNI_ARGS variable is deprecated, and this library deliberately chooses to ignore it. You may of course read and parse it yourself.

A number of things are logged in here. If you have used [install_logger][crate::install_logger], this may result in output being sent to STDERR (and/or to file).

In general you should prefer Cni::load().

Source

pub fn load() -> Self

Reads the plugin inputs from the environment and STDIN and reacts to errors and the VERSION command.

This does the same thing as Cni::from_env() but it also immediately replies to the VERSION command, and also immediately replies if errors result from reading the inputs, both of which write to STDOUT and exit.

This version also logs a debug message with the name and version of this library crate.

Source§

impl Cni

Source

pub fn into_inputs(self) -> Option<Inputs>

Converts this enum into an alternate representation which holds the Command separately from the inputs.

This is useful to deduplicate prep work between command implementations.

Trait Implementations§

Source§

impl Clone for Cni

Source§

fn clone(&self) -> Cni

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Cni

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Cni

§

impl RefUnwindSafe for Cni

§

impl Send for Cni

§

impl Sync for Cni

§

impl Unpin for Cni

§

impl UnwindSafe for Cni

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.