Add shim client example
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
parent
68a651b0e4
commit
baf8effb21
|
|
@ -9,7 +9,9 @@ description = "TTRPC bindings for containerd shim interfaces"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
protobuf = "2.23.0"
|
protobuf = "2.23.0"
|
||||||
ttrpc = "0.5.1"
|
# Needs `Client::connect` to be published on crates.io
|
||||||
|
# PR: https://github.com/containerd/ttrpc-rust/pull/93
|
||||||
|
ttrpc = { git = "https://github.com/containerd/ttrpc-rust.git", rev = "da67137a8b89d6b796cb7e826ba2f6db2eed8f9e" }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
ttrpc-codegen = "0.2"
|
ttrpc-codegen = "0.2"
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,30 @@
|
||||||
# Shim protos
|
# Shim protos
|
||||||
|
|
||||||
TTRPC bindings for containerd's shim events and interfaces.
|
TTRPC bindings for containerd's shim events and interfaces.
|
||||||
|
|
||||||
|
## Look and feel
|
||||||
|
|
||||||
|
Basic client code looks as follows:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
let client = client::Client::connect(socket_path)?;
|
||||||
|
let task_client = client::TaskClient::new(client);
|
||||||
|
|
||||||
|
let context = client::ttrpc::context::with_timeout(0);
|
||||||
|
|
||||||
|
let req = client::api::ConnectRequest {
|
||||||
|
id: pid,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let resp = task_client.connect(context, &req)?;
|
||||||
|
```
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
Have a look on example [here](./examples/connect.rs).
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo build --example connect
|
||||||
|
$ sudo ./connect unix:///containerd-shim/shim_socket_path.sock
|
||||||
|
```
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
use std::env;
|
||||||
|
|
||||||
|
use containerd_shim_protos as client;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let args: Vec<String> = env::args().collect();
|
||||||
|
|
||||||
|
let socket_path = args
|
||||||
|
.get(1)
|
||||||
|
.ok_or_else(|| "First argument must be shim socket path")
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let pid = args
|
||||||
|
.get(2)
|
||||||
|
.and_then(|str| Some(str.to_owned()))
|
||||||
|
.unwrap_or(String::new());
|
||||||
|
|
||||||
|
let client = client::Client::connect(socket_path).expect("Failed to connect to shim");
|
||||||
|
|
||||||
|
let task_client = client::TaskClient::new(client);
|
||||||
|
|
||||||
|
let context = client::ttrpc::context::with_timeout(0);
|
||||||
|
|
||||||
|
let req = client::api::ConnectRequest {
|
||||||
|
id: pid,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let resp = task_client
|
||||||
|
.connect(context, &req)
|
||||||
|
.expect("Connect request failed");
|
||||||
|
|
||||||
|
println!("Resp: {:?}", resp);
|
||||||
|
}
|
||||||
|
|
@ -8,3 +8,7 @@ pub use ttrpc;
|
||||||
pub mod events;
|
pub mod events;
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
pub mod shim;
|
pub mod shim;
|
||||||
|
|
||||||
|
pub use shim::shim as api;
|
||||||
|
pub use shim::shim_ttrpc::{Task, TaskClient};
|
||||||
|
pub use ttrpc::Client;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue