Struct ovsdb::client::Client

source ·
pub struct Client { /* private fields */ }
Expand description

An OVSDB client, used to interact with an OVSDB database server.

The client is a thin wrapper around the various methods available in the OVSDB protocol. Instantiating a client is done through one of the connect_ methods.

§Examples

use std::path::Path;

use ovsdb::Client;

let client = Client::connect_unix(Path::new("/var/run/openvswitch/db.sock"))
    .await
    .unwrap();

Implementations§

source§

impl Client

source

pub async fn connect_tcp<T>(server_addr: T) -> Result<Self, ClientError>
where T: AsRef<str> + ToSocketAddrs,

Connect to an OVSDB server via TCP socket.

§Examples
use ovsdb::client::Client;

let client = Client::connect_tcp("127.0.0.1:6641")
    .await
    .unwrap();
source

pub async fn connect_unix(socket: &Path) -> Result<Self, ClientError>

Connect to an OVSDB server via UNIX domain socket.

§Examples
use std::path::Path;

use ovsdb::client::Client;

let client = Client::connect_unix(Path::new("/var/run/openvswitch/db.sock"))
    .await
    .unwrap();
source

pub async fn stop(self) -> Result<(), ClientError>

Disconnect from the OVSDB server and stop processing messages.

§Examples
use std::path::Path;

use ovsdb::Client;

let client = Client::connect_unix(Path::new("/var/run/openvswitch/db.sock"))
    .await
    .unwrap();

// Perform OVSDB operations

client.stop().await.unwrap();
source

pub async fn execute<T>( &self, request: Request ) -> Result<Option<T>, ClientError>

Execute a raw OVSDB request, receiving a raw response.

Under normal circumstances, this method should only be called internally, with clients preferring one of the purpose-built methods (ie. Client::echo). However, if for some reason those methods are insufficient, raw requests can be made to the database.

use std::path::Path;

use serde::Serialize;

use ovsdb::client::Client;
use ovsdb::protocol::{Request, method::Params, method::Method};

#[derive(Debug, Serialize)]
struct MyParams {
  values: Vec<i32>,
}

impl Params for MyParams {}

let params = MyParams { values: vec![1, 2, 3] };
let request = Request::new(Method::Echo, Some(Box::new(params)));

let client = Client::connect_unix(Path::new("/var/run/openvswitch/db.sock"))
    .await
    .unwrap();

let result: Option<Vec<i32>> = client.execute(request).await.unwrap();
if let Some(r) = result {
  assert_eq!(r, vec![1, 2, 3]);
}
source

pub async fn echo<T, I>(&self, args: T) -> Result<EchoResult, ClientError>
where T: IntoIterator<Item = I> + Send, I: Into<String> + Debug,

Issues an echo request to the OVSDB server.

On success, the arguments to the request are returned as the result.

use std::path::Path;

use ovsdb::client::Client;

let client = Client::connect_unix(Path::new("/var/run/openvswitch/db.sock"))
    .await
    .unwrap();

let args = vec!["Hello", "OVSDB"];
let result = client.echo(args.clone()).await.unwrap();
assert_eq!(*result, args);
source

pub async fn list_databases(&self) -> Result<ListDbsResult, ClientError>

Issues a list_dbs request to the OVSDB server.

On success, a list of databases supported by the server are returned.

use std::path::Path;

use ovsdb::Client;

let client = Client::connect_unix(Path::new("/var/run/openvswitch/db.sock"))
    .await
    .unwrap();

let dbs = client.list_databases().await.unwrap();
println!("available databases: {:#?}", dbs);
source

pub async fn get_schema<S>(&self, database: S) -> Result<Schema, ClientError>
where S: Into<String>,

Issues a get_schema request to the OVSDB server.

On success, a Schema instance is returned matching the OVSDB schema for the specified database.

use std::path::Path;

use ovsdb::Client;

let client = Client::connect_unix(Path::new("/var/run/openvswitch/db.sock"))
    .await
    .unwrap();

let schema = client.get_schema("Open_vSwitch").await.unwrap();
println!("Open_vSwitch schema: {:#?}", schema);
source

pub async fn transact<S, T>( &self, database: S, operations: Vec<Operation> ) -> Result<T, ClientError>

Issues a transact request to the OVSDB server.

TODO

Trait Implementations§

source§

impl Debug for Client

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more