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
impl Client
sourcepub async fn connect_tcp<T>(server_addr: T) -> Result<Self, ClientError>
pub async fn connect_tcp<T>(server_addr: T) -> Result<Self, ClientError>
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();
sourcepub async fn connect_unix(socket: &Path) -> Result<Self, ClientError>
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();
sourcepub async fn stop(self) -> Result<(), ClientError>
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();
sourcepub async fn execute<T>(
&self,
request: Request
) -> Result<Option<T>, ClientError>where
T: DeserializeOwned,
pub async fn execute<T>(
&self,
request: Request
) -> Result<Option<T>, ClientError>where
T: DeserializeOwned,
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]);
}
sourcepub async fn echo<T, I>(&self, args: T) -> Result<EchoResult, ClientError>
pub async fn echo<T, I>(&self, args: T) -> Result<EchoResult, ClientError>
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);
sourcepub async fn list_databases(&self) -> Result<ListDbsResult, ClientError>
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);
sourcepub async fn get_schema<S>(&self, database: S) -> Result<Schema, ClientError>
pub async fn get_schema<S>(&self, database: S) -> Result<Schema, ClientError>
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);