eos-eapi

Crates.ioeos-eapi
lib.rseos-eapi
version0.2.0
sourcesrc
created_at2022-08-09 17:45:12.16267
updated_at2022-11-09 17:29:40.692982
descriptionArista EOS eAPI client library
homepage
repositoryhttps://github.com/aristanetworks/eos-eapi-rust
max_upload_size
id641944
size106,718
Vlad Hanciuta (wladh)

documentation

README

EOS eAPI

This crate allows execution of CLI commands on Arista EOS switches from Rust programs. It supports both blocking and async APIs.


[dependencies]
eos-eapi = "0.2"

Example

API usage example via Unix domain sockets:

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:#?}"),
};

API usage example via HTTP:

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:#?}"),
};

Switch configuration

If you're using HTTPS to connect to eAPI, depending on your EOS version, the default HTTPS server configuration might have outdated settings and the client won't be able to connect.

You need to create a set of keys and certificate:

security pki key generate rsa 4096 capikey.pem
security pki certificate generate self-signed capi.pem key capikey.pem validity 3650 parameters common-name HOSTNAME subject-alternative-name dns HOSTNAME

And then create an SSL profile with them:

config
management security
   ssl profile p01
      tls versions 1.2
      cipher-list ECDHE-RSA-AES256-GCM-SHA384
      certificate capi.pem key capikey.pem
      trust certificate ARISTA_SIGNING_CA.crt
      trust certificate ARISTA_ROOT_CA.crt

Apply the profile:

management http-server
   protocol http
   protocol https ssl profile p01
Commit count: 12

cargo fmt