Crate eos_eapi

source ·
Expand description

This crate allows execution of CLI commands on Arista EOS switches.

Features

  • blocking (default) blocking API.
  • async adds async (via tokio runtime) support.

Example using unix sockets

The UDS client is one shot, and run consumes the client.

let result = ClientBuilder::unix_socket()
                .build_blocking()?
                .run(&["show clock", "show aliases"], ResultFormat::Json)?;
match result {
    Response::Result(v) => println!("{v:?}"),
    Response::Error {
        message,
        code,
        errors,
    } => println!("error code: {code}, message: {message}, outputs: {errors:#?}"),
};

Example using HTTP

The HTTP(S) client can be reused to run multiple sets of commands.

let result = ClientBuilder::unix_http("localhost")
                .set_authentication("admin".to_owned(), "pass".to_owned())
                .build_blocking()
                .run(&["show clock", "show aliases"], ResultFormat::Json)?;
match result {
    Response::Result(v) => println!("{v:?}"),
    Response::Error {
        message,
        code,
        errors,
    } => println!("error code: {code}, message: {message}, outputs: {errors:#?}"),
};

Example using HTTPS

let result = ClientBuilder::unix_http("localhost")
                .enable_https()
                .set_authentication("admin".to_owned(), "pass".to_owned())
                .build_blocking()
                .run(&["show clock", "show aliases"], ResultFormat::Json)?;
match result {
    Response::Result(v) => println!("{v:?}"),
    Response::Error {
        message,
        code,
        errors,
    } => println!("error code: {code}, message: {message}, outputs: {errors:#?}"),
};

Structs

Builds a client to connect to eAPI.

Enums

The errors returned by the library.
Commands execution response.
Format of the commands output.

Traits

Commands runner. Clients implement this trait.

Functions

eapi_runDeprecated
Runs commands via eAPI and returns the results.