From d2a9bc6674c8c86ddc57138e96659bfd85562cf5 Mon Sep 17 00:00:00 2001 From: Quanwei Zhou Date: Tue, 22 Feb 2022 15:41:10 +0800 Subject: [PATCH] agent: agent-protocol support async 1. support async. 2. update ttrpc and protobuf update ttrpc to 0.6.0 update protobuf to 2.23.0 3. support trans from oci Fixes: #3746 Signed-off-by: Quanwei Zhou --- src/agent/Cargo.lock | 32 +- src/agent/Cargo.toml | 8 +- src/agent/rustjail/Cargo.toml | 4 +- src/agent/src/rpc.rs | 18 +- src/libs/Cargo.lock | 38 +- src/libs/protocols/Cargo.toml | 8 +- src/libs/protocols/build.rs | 47 +- src/libs/protocols/src/agent_ttrpc_async.rs | 816 +++++++++++++ src/libs/protocols/src/health_ttrpc_async.rs | 90 ++ src/libs/protocols/src/lib.rs | 5 + src/libs/protocols/src/trans.rs | 1085 ++++++++++++++++++ src/tools/agent-ctl/Cargo.lock | 93 +- src/tools/agent-ctl/Cargo.toml | 2 +- src/tools/agent-ctl/src/client.rs | 2 +- src/tools/agent-ctl/src/main.rs | 4 +- src/tools/agent-ctl/src/utils.rs | 6 +- 16 files changed, 2092 insertions(+), 166 deletions(-) create mode 100644 src/libs/protocols/src/agent_ttrpc_async.rs create mode 100644 src/libs/protocols/src/health_ttrpc_async.rs create mode 100644 src/libs/protocols/src/trans.rs diff --git a/src/agent/Cargo.lock b/src/agent/Cargo.lock index 096a81a8e5..58bac5207d 100644 --- a/src/agent/Cargo.lock +++ b/src/agent/Cargo.lock @@ -807,19 +807,6 @@ dependencies = [ "void", ] -[[package]] -name = "nix" -version = "0.20.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5e06129fb611568ef4e868c14b326274959aa70ff7776e9d55323531c374945" -dependencies = [ - "bitflags", - "cc", - "cfg-if 1.0.0", - "libc", - "memoffset", -] - [[package]] name = "nix" version = "0.22.2" @@ -1183,9 +1170,9 @@ dependencies = [ [[package]] name = "protobuf" -version = "2.14.0" +version = "2.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e86d370532557ae7573551a1ec8235a0f8d6cb276c7c9e6aa490b511c447485" +checksum = "cf7e6d18738ecd0902d30d1ad232c9125985a3422929b16c65517b38adc14f96" dependencies = [ "serde", "serde_derive", @@ -1193,18 +1180,18 @@ dependencies = [ [[package]] name = "protobuf-codegen" -version = "2.14.0" +version = "2.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de113bba758ccf2c1ef816b127c958001b7831136c9bc3f8e9ec695ac4e82b0c" +checksum = "aec1632b7c8f2e620343439a7dfd1f3c47b18906c4be58982079911482b5d707" dependencies = [ "protobuf", ] [[package]] name = "protobuf-codegen-pure" -version = "2.14.0" +version = "2.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d1a4febc73bf0cada1d77c459a0c8e5973179f1cfd5b0f1ab789d45b17b6440" +checksum = "9f8122fdb18e55190c796b088a16bdb70cd7acdcd48f7a8b796b58c62e532cc6" dependencies = [ "protobuf", "protobuf-codegen", @@ -1215,6 +1202,7 @@ name = "protocols" version = "0.1.0" dependencies = [ "async-trait", + "oci", "protobuf", "ttrpc", "ttrpc-codegen", @@ -1831,16 +1819,16 @@ dependencies = [ [[package]] name = "ttrpc" -version = "0.5.2" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66a973ce6d5eaa20c173635b29ffb660dafbc7ef109172c0015ba44e47a23711" +checksum = "0c7d6c992964a013c17814c08d31708d577b0aae44ebadb58755659dd824c2d1" dependencies = [ "async-trait", "byteorder", "futures", "libc", "log", - "nix 0.20.2", + "nix 0.23.1", "protobuf", "protobuf-codegen-pure", "thiserror", diff --git a/src/agent/Cargo.toml b/src/agent/Cargo.toml index 77ec06d8ac..93ecde93c6 100644 --- a/src/agent/Cargo.toml +++ b/src/agent/Cargo.toml @@ -7,10 +7,10 @@ edition = "2018" [dependencies] oci = { path = "../libs/oci" } rustjail = { path = "rustjail" } -protocols = { path = "../libs/protocols" } +protocols = { path = "../libs/protocols", features = ["async"] } lazy_static = "1.3.0" -ttrpc = { version = "0.5.0", features = ["async", "protobuf-codec"], default-features = false } -protobuf = "=2.14.0" +ttrpc = { version = "0.6.0", features = ["async"], default-features = false } +protobuf = "2.23.0" libc = "0.2.58" nix = "0.23.0" capctl = "0.2.0" @@ -31,7 +31,7 @@ futures = "0.3.17" tokio = { version = "1.14.0", features = ["full"] } tokio-vsock = "0.3.1" -netlink-sys = { version = "0.7.0", features = ["tokio_socket",]} +netlink-sys = { version = "0.7.0", features = ["tokio_socket"]} rtnetlink = "0.8.0" netlink-packet-utils = "0.4.1" ipnetwork = "0.17.0" diff --git a/src/agent/rustjail/Cargo.toml b/src/agent/rustjail/Cargo.toml index 306af2795d..628b0275bd 100644 --- a/src/agent/rustjail/Cargo.toml +++ b/src/agent/rustjail/Cargo.toml @@ -16,7 +16,7 @@ scopeguard = "1.0.0" capctl = "0.2.0" lazy_static = "1.3.0" libc = "0.2.58" -protobuf = "=2.14.0" +protobuf = "2.23.0" slog = "2.5.2" slog-scope = "4.1.2" scan_fmt = "0.2.6" @@ -27,7 +27,7 @@ cgroups = { package = "cgroups-rs", version = "0.2.8" } rlimit = "0.5.3" cfg-if = "0.1.0" -tokio = { version = "1.2.0", features = ["sync", "io-util", "process", "time", "macros"] } +tokio = { version = "1.2.0", features = ["sync", "io-util", "process", "time", "macros", "rt"] } futures = "0.3.17" async-trait = "0.1.31" inotify = "0.9.2" diff --git a/src/agent/src/rpc.rs b/src/agent/src/rpc.rs index bcf2096d2b..6d14da1d98 100644 --- a/src/agent/src/rpc.rs +++ b/src/agent/src/rpc.rs @@ -34,6 +34,7 @@ use protocols::health::{ HealthCheckResponse, HealthCheckResponse_ServingStatus, VersionCheckResponse, }; use protocols::types::Interface; +use protocols::{agent_ttrpc_async as agent_ttrpc, health_ttrpc_async as health_ttrpc}; use rustjail::cgroups::notifier; use rustjail::container::{BaseContainer, Container, LinuxContainer}; use rustjail::process::Process; @@ -650,7 +651,7 @@ impl AgentService { } #[async_trait] -impl protocols::agent_ttrpc::AgentService for AgentService { +impl agent_ttrpc::AgentService for AgentService { async fn create_container( &self, ctx: &TtrpcContext, @@ -1536,7 +1537,7 @@ impl protocols::agent_ttrpc::AgentService for AgentService { struct HealthService; #[async_trait] -impl protocols::health_ttrpc::Health for HealthService { +impl health_ttrpc::Health for HealthService { async fn check( &self, _ctx: &TtrpcContext, @@ -1675,18 +1676,17 @@ async fn read_stream(reader: Arc>>, l: usize) -> Resu } pub fn start(s: Arc>, server_address: &str) -> Result { - let agent_service = Box::new(AgentService { sandbox: s }) - as Box; + let agent_service = + Box::new(AgentService { sandbox: s }) as Box; let agent_worker = Arc::new(agent_service); - let health_service = - Box::new(HealthService {}) as Box; + let health_service = Box::new(HealthService {}) as Box; let health_worker = Arc::new(health_service); - let aservice = protocols::agent_ttrpc::create_agent_service(agent_worker); + let aservice = agent_ttrpc::create_agent_service(agent_worker); - let hservice = protocols::health_ttrpc::create_health(health_worker); + let hservice = health_ttrpc::create_health(health_worker); let server = TtrpcServer::new() .bind(server_address)? @@ -2021,7 +2021,7 @@ fn load_kernel_module(module: &protocols::agent::KernelModule) -> Result<()> { mod tests { use super::*; use crate::{ - assert_result, namespace::Namespace, protocols::agent_ttrpc::AgentService as _, + assert_result, namespace::Namespace, protocols::agent_ttrpc_async::AgentService as _, skip_if_not_root, }; use nix::mount; diff --git a/src/libs/Cargo.lock b/src/libs/Cargo.lock index 31b72fc7cc..0917f9552d 100644 --- a/src/libs/Cargo.lock +++ b/src/libs/Cargo.lock @@ -88,7 +88,7 @@ checksum = "1b827f9d9f6c2fff719d25f5d44cbc8d2ef6df1ef00d055c5c14d5dc25529579" dependencies = [ "libc", "log", - "nix 0.23.1", + "nix", "regex", ] @@ -358,7 +358,7 @@ dependencies = [ "kata-types", "lazy_static", "libc", - "nix 0.23.1", + "nix", "num_cpus", "oci", "once_cell", @@ -475,19 +475,6 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" -[[package]] -name = "nix" -version = "0.20.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5e06129fb611568ef4e868c14b326274959aa70ff7776e9d55323531c374945" -dependencies = [ - "bitflags", - "cc", - "cfg-if", - "libc", - "memoffset", -] - [[package]] name = "nix" version = "0.23.1" @@ -670,9 +657,9 @@ dependencies = [ [[package]] name = "protobuf" -version = "2.14.0" +version = "2.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e86d370532557ae7573551a1ec8235a0f8d6cb276c7c9e6aa490b511c447485" +checksum = "cf7e6d18738ecd0902d30d1ad232c9125985a3422929b16c65517b38adc14f96" dependencies = [ "serde", "serde_derive", @@ -680,18 +667,18 @@ dependencies = [ [[package]] name = "protobuf-codegen" -version = "2.14.0" +version = "2.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de113bba758ccf2c1ef816b127c958001b7831136c9bc3f8e9ec695ac4e82b0c" +checksum = "aec1632b7c8f2e620343439a7dfd1f3c47b18906c4be58982079911482b5d707" dependencies = [ "protobuf", ] [[package]] name = "protobuf-codegen-pure" -version = "2.14.0" +version = "2.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d1a4febc73bf0cada1d77c459a0c8e5973179f1cfd5b0f1ab789d45b17b6440" +checksum = "9f8122fdb18e55190c796b088a16bdb70cd7acdcd48f7a8b796b58c62e532cc6" dependencies = [ "protobuf", "protobuf-codegen", @@ -702,6 +689,7 @@ name = "protocols" version = "0.1.0" dependencies = [ "async-trait", + "oci", "protobuf", "serde", "serde_json", @@ -1050,16 +1038,16 @@ dependencies = [ [[package]] name = "ttrpc" -version = "0.5.2" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66a973ce6d5eaa20c173635b29ffb660dafbc7ef109172c0015ba44e47a23711" +checksum = "2ecfff459a859c6ba6668ff72b34c2f1d94d9d58f7088414c2674ad0f31cc7d8" dependencies = [ "async-trait", "byteorder", "futures", "libc", "log", - "nix 0.20.2", + "nix", "protobuf", "protobuf-codegen-pure", "thiserror", @@ -1113,7 +1101,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e32675ee2b3ce5df274c0ab52d19b28789632406277ca26bffee79a8e27dc133" dependencies = [ "libc", - "nix 0.23.1", + "nix", ] [[package]] diff --git a/src/libs/protocols/Cargo.toml b/src/libs/protocols/Cargo.toml index ae93e7fa19..eda2eeffc7 100644 --- a/src/libs/protocols/Cargo.toml +++ b/src/libs/protocols/Cargo.toml @@ -7,13 +7,15 @@ edition = "2018" [features] default = [] with-serde = [ "serde", "serde_json" ] +async = ["ttrpc/async", "async-trait"] [dependencies] -ttrpc = { version = "0.5.0", features = ["async"] } -async-trait = "0.1.42" -protobuf = { version = "=2.14.0", features = ["with-serde"] } +ttrpc = { version = "0.6.0" } +async-trait = { version = "0.1.42", optional = true } +protobuf = { version = "2.23.0", features = ["with-serde"] } serde = { version = "1.0.130", features = ["derive"], optional = true } serde_json = { version = "1.0.68", optional = true } +oci = { path = "../oci" } [build-dependencies] ttrpc-codegen = "0.2.0" diff --git a/src/libs/protocols/build.rs b/src/libs/protocols/build.rs index 4a43f36777..8a2725ae05 100644 --- a/src/libs/protocols/build.rs +++ b/src/libs/protocols/build.rs @@ -3,7 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 // -use std::fs::File; +use std::fs::{self, File}; use std::io::{BufRead, BufReader, Read, Write}; use std::path::Path; use std::process::exit; @@ -90,17 +90,8 @@ fn handle_file(autogen_comment: &str, rust_filename: &str) -> Result<(), std::io Ok(()) } -fn real_main() -> Result<(), std::io::Error> { - let autogen_comment = format!("\n//! Generated by {:?} ({:?})", file!(), module_path!()); - - let protos = vec![ - "protos/agent.proto", - "protos/csi.proto", - "protos/google/protobuf/empty.proto", - "protos/health.proto", - "protos/oci.proto", - "protos/types.proto", - ]; +fn codegen(path: &str, protos: &[&str], async_all: bool) -> Result<(), std::io::Error> { + fs::create_dir_all(path).unwrap(); // Tell Cargo that if the .proto files changed, to rerun this build script. protos @@ -108,7 +99,7 @@ fn real_main() -> Result<(), std::io::Error> { .for_each(|p| println!("cargo:rerun-if-changed={}", &p)); let ttrpc_options = Customize { - async_server: true, + async_all, ..Default::default() }; @@ -121,13 +112,14 @@ fn real_main() -> Result<(), std::io::Error> { Codegen::new() .out_dir(out_dir) - .inputs(&protos) + .inputs(protos) .include("protos") .customize(ttrpc_options) .rust_protobuf() .rust_protobuf_customize(protobuf_options) .run()?; + let autogen_comment = format!("\n//! Generated by {:?} ({:?})", file!(), module_path!()); for file in protos.iter() { let proto_filename = Path::new(file).file_name().unwrap(); @@ -147,6 +139,31 @@ fn real_main() -> Result<(), std::io::Error> { handle_file(&autogen_comment, out_file_str)?; } + use_serde(protos, out_dir)?; + Ok(()) +} +fn real_main() -> Result<(), std::io::Error> { + codegen( + "src", + &[ + "protos/google/protobuf/empty.proto", + "protos/oci.proto", + "protos/types.proto", + ], + false, + )?; + + // generate async + #[cfg(feature = "async")] + { + codegen("src", &["protos/agent.proto", "protos/health.proto"], true)?; + + fs::rename("src/agent_ttrpc.rs", "src/agent_ttrpc_async.rs")?; + fs::rename("src/health_ttrpc.rs", "src/health_ttrpc_async.rs")?; + } + + codegen("src", &["protos/agent.proto", "protos/health.proto"], false)?; + // There is a message named 'Box' in oci.proto // so there is a struct named 'Box', we should replace Box to ::std::boxed::Box // to avoid the conflict. @@ -156,8 +173,6 @@ fn real_main() -> Result<(), std::io::Error> { "self: ::std::boxed::Box", )?; - use_serde(&protos, out_dir)?; - Ok(()) } diff --git a/src/libs/protocols/src/agent_ttrpc_async.rs b/src/libs/protocols/src/agent_ttrpc_async.rs new file mode 100644 index 0000000000..fd8979907d --- /dev/null +++ b/src/libs/protocols/src/agent_ttrpc_async.rs @@ -0,0 +1,816 @@ +// This file is generated by ttrpc-compiler 0.4.1. Do not edit +// @generated + +// https://github.com/Manishearth/rust-clippy/issues/702 +#![allow(unknown_lints)] +#![allow(clipto_camel_casepy)] + +#![cfg_attr(rustfmt, rustfmt_skip)] + +#![allow(box_pointers)] +#![allow(dead_code)] +#![allow(missing_docs)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] +#![allow(trivial_casts)] +#![allow(unsafe_code)] +#![allow(unused_imports)] +#![allow(unused_results)] +use protobuf::{CodedInputStream, CodedOutputStream, Message}; +use std::collections::HashMap; +use std::sync::Arc; +use async_trait::async_trait; + +#[derive(Clone)] +pub struct AgentServiceClient { + client: ::ttrpc::r#async::Client, +} + +impl AgentServiceClient { + pub fn new(client: ::ttrpc::r#async::Client) -> Self { + AgentServiceClient { + client: client, + } + } + + pub async fn create_container(&mut self, ctx: ttrpc::context::Context, req: &super::agent::CreateContainerRequest) -> ::ttrpc::Result { + let mut cres = super::empty::Empty::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "CreateContainer", cres); + } + + pub async fn start_container(&mut self, ctx: ttrpc::context::Context, req: &super::agent::StartContainerRequest) -> ::ttrpc::Result { + let mut cres = super::empty::Empty::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "StartContainer", cres); + } + + pub async fn remove_container(&mut self, ctx: ttrpc::context::Context, req: &super::agent::RemoveContainerRequest) -> ::ttrpc::Result { + let mut cres = super::empty::Empty::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "RemoveContainer", cres); + } + + pub async fn exec_process(&mut self, ctx: ttrpc::context::Context, req: &super::agent::ExecProcessRequest) -> ::ttrpc::Result { + let mut cres = super::empty::Empty::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "ExecProcess", cres); + } + + pub async fn signal_process(&mut self, ctx: ttrpc::context::Context, req: &super::agent::SignalProcessRequest) -> ::ttrpc::Result { + let mut cres = super::empty::Empty::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "SignalProcess", cres); + } + + pub async fn wait_process(&mut self, ctx: ttrpc::context::Context, req: &super::agent::WaitProcessRequest) -> ::ttrpc::Result { + let mut cres = super::agent::WaitProcessResponse::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "WaitProcess", cres); + } + + pub async fn update_container(&mut self, ctx: ttrpc::context::Context, req: &super::agent::UpdateContainerRequest) -> ::ttrpc::Result { + let mut cres = super::empty::Empty::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "UpdateContainer", cres); + } + + pub async fn stats_container(&mut self, ctx: ttrpc::context::Context, req: &super::agent::StatsContainerRequest) -> ::ttrpc::Result { + let mut cres = super::agent::StatsContainerResponse::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "StatsContainer", cres); + } + + pub async fn pause_container(&mut self, ctx: ttrpc::context::Context, req: &super::agent::PauseContainerRequest) -> ::ttrpc::Result { + let mut cres = super::empty::Empty::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "PauseContainer", cres); + } + + pub async fn resume_container(&mut self, ctx: ttrpc::context::Context, req: &super::agent::ResumeContainerRequest) -> ::ttrpc::Result { + let mut cres = super::empty::Empty::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "ResumeContainer", cres); + } + + pub async fn write_stdin(&mut self, ctx: ttrpc::context::Context, req: &super::agent::WriteStreamRequest) -> ::ttrpc::Result { + let mut cres = super::agent::WriteStreamResponse::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "WriteStdin", cres); + } + + pub async fn read_stdout(&mut self, ctx: ttrpc::context::Context, req: &super::agent::ReadStreamRequest) -> ::ttrpc::Result { + let mut cres = super::agent::ReadStreamResponse::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "ReadStdout", cres); + } + + pub async fn read_stderr(&mut self, ctx: ttrpc::context::Context, req: &super::agent::ReadStreamRequest) -> ::ttrpc::Result { + let mut cres = super::agent::ReadStreamResponse::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "ReadStderr", cres); + } + + pub async fn close_stdin(&mut self, ctx: ttrpc::context::Context, req: &super::agent::CloseStdinRequest) -> ::ttrpc::Result { + let mut cres = super::empty::Empty::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "CloseStdin", cres); + } + + pub async fn tty_win_resize(&mut self, ctx: ttrpc::context::Context, req: &super::agent::TtyWinResizeRequest) -> ::ttrpc::Result { + let mut cres = super::empty::Empty::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "TtyWinResize", cres); + } + + pub async fn update_interface(&mut self, ctx: ttrpc::context::Context, req: &super::agent::UpdateInterfaceRequest) -> ::ttrpc::Result { + let mut cres = super::types::Interface::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "UpdateInterface", cres); + } + + pub async fn update_routes(&mut self, ctx: ttrpc::context::Context, req: &super::agent::UpdateRoutesRequest) -> ::ttrpc::Result { + let mut cres = super::agent::Routes::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "UpdateRoutes", cres); + } + + pub async fn list_interfaces(&mut self, ctx: ttrpc::context::Context, req: &super::agent::ListInterfacesRequest) -> ::ttrpc::Result { + let mut cres = super::agent::Interfaces::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "ListInterfaces", cres); + } + + pub async fn list_routes(&mut self, ctx: ttrpc::context::Context, req: &super::agent::ListRoutesRequest) -> ::ttrpc::Result { + let mut cres = super::agent::Routes::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "ListRoutes", cres); + } + + pub async fn add_arp_neighbors(&mut self, ctx: ttrpc::context::Context, req: &super::agent::AddARPNeighborsRequest) -> ::ttrpc::Result { + let mut cres = super::empty::Empty::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "AddARPNeighbors", cres); + } + + pub async fn get_ip_tables(&mut self, ctx: ttrpc::context::Context, req: &super::agent::GetIPTablesRequest) -> ::ttrpc::Result { + let mut cres = super::agent::GetIPTablesResponse::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "GetIPTables", cres); + } + + pub async fn set_ip_tables(&mut self, ctx: ttrpc::context::Context, req: &super::agent::SetIPTablesRequest) -> ::ttrpc::Result { + let mut cres = super::agent::SetIPTablesResponse::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "SetIPTables", cres); + } + + pub async fn get_metrics(&mut self, ctx: ttrpc::context::Context, req: &super::agent::GetMetricsRequest) -> ::ttrpc::Result { + let mut cres = super::agent::Metrics::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "GetMetrics", cres); + } + + pub async fn create_sandbox(&mut self, ctx: ttrpc::context::Context, req: &super::agent::CreateSandboxRequest) -> ::ttrpc::Result { + let mut cres = super::empty::Empty::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "CreateSandbox", cres); + } + + pub async fn destroy_sandbox(&mut self, ctx: ttrpc::context::Context, req: &super::agent::DestroySandboxRequest) -> ::ttrpc::Result { + let mut cres = super::empty::Empty::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "DestroySandbox", cres); + } + + pub async fn online_cpu_mem(&mut self, ctx: ttrpc::context::Context, req: &super::agent::OnlineCPUMemRequest) -> ::ttrpc::Result { + let mut cres = super::empty::Empty::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "OnlineCPUMem", cres); + } + + pub async fn reseed_random_dev(&mut self, ctx: ttrpc::context::Context, req: &super::agent::ReseedRandomDevRequest) -> ::ttrpc::Result { + let mut cres = super::empty::Empty::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "ReseedRandomDev", cres); + } + + pub async fn get_guest_details(&mut self, ctx: ttrpc::context::Context, req: &super::agent::GuestDetailsRequest) -> ::ttrpc::Result { + let mut cres = super::agent::GuestDetailsResponse::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "GetGuestDetails", cres); + } + + pub async fn mem_hotplug_by_probe(&mut self, ctx: ttrpc::context::Context, req: &super::agent::MemHotplugByProbeRequest) -> ::ttrpc::Result { + let mut cres = super::empty::Empty::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "MemHotplugByProbe", cres); + } + + pub async fn set_guest_date_time(&mut self, ctx: ttrpc::context::Context, req: &super::agent::SetGuestDateTimeRequest) -> ::ttrpc::Result { + let mut cres = super::empty::Empty::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "SetGuestDateTime", cres); + } + + pub async fn copy_file(&mut self, ctx: ttrpc::context::Context, req: &super::agent::CopyFileRequest) -> ::ttrpc::Result { + let mut cres = super::empty::Empty::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "CopyFile", cres); + } + + pub async fn get_oom_event(&mut self, ctx: ttrpc::context::Context, req: &super::agent::GetOOMEventRequest) -> ::ttrpc::Result { + let mut cres = super::agent::OOMEvent::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "GetOOMEvent", cres); + } + + pub async fn add_swap(&mut self, ctx: ttrpc::context::Context, req: &super::agent::AddSwapRequest) -> ::ttrpc::Result { + let mut cres = super::empty::Empty::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "AddSwap", cres); + } + + pub async fn get_volume_stats(&mut self, ctx: ttrpc::context::Context, req: &super::agent::VolumeStatsRequest) -> ::ttrpc::Result { + let mut cres = super::csi::VolumeStatsResponse::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "GetVolumeStats", cres); + } + + pub async fn resize_volume(&mut self, ctx: ttrpc::context::Context, req: &super::agent::ResizeVolumeRequest) -> ::ttrpc::Result { + let mut cres = super::empty::Empty::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.AgentService", "ResizeVolume", cres); + } +} + +struct CreateContainerMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for CreateContainerMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, CreateContainerRequest, create_container); + } +} + +struct StartContainerMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for StartContainerMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, StartContainerRequest, start_container); + } +} + +struct RemoveContainerMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for RemoveContainerMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, RemoveContainerRequest, remove_container); + } +} + +struct ExecProcessMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for ExecProcessMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, ExecProcessRequest, exec_process); + } +} + +struct SignalProcessMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for SignalProcessMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, SignalProcessRequest, signal_process); + } +} + +struct WaitProcessMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for WaitProcessMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, WaitProcessRequest, wait_process); + } +} + +struct UpdateContainerMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for UpdateContainerMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, UpdateContainerRequest, update_container); + } +} + +struct StatsContainerMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for StatsContainerMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, StatsContainerRequest, stats_container); + } +} + +struct PauseContainerMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for PauseContainerMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, PauseContainerRequest, pause_container); + } +} + +struct ResumeContainerMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for ResumeContainerMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, ResumeContainerRequest, resume_container); + } +} + +struct WriteStdinMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for WriteStdinMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, WriteStreamRequest, write_stdin); + } +} + +struct ReadStdoutMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for ReadStdoutMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, ReadStreamRequest, read_stdout); + } +} + +struct ReadStderrMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for ReadStderrMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, ReadStreamRequest, read_stderr); + } +} + +struct CloseStdinMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for CloseStdinMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, CloseStdinRequest, close_stdin); + } +} + +struct TtyWinResizeMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for TtyWinResizeMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, TtyWinResizeRequest, tty_win_resize); + } +} + +struct UpdateInterfaceMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for UpdateInterfaceMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, UpdateInterfaceRequest, update_interface); + } +} + +struct UpdateRoutesMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for UpdateRoutesMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, UpdateRoutesRequest, update_routes); + } +} + +struct ListInterfacesMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for ListInterfacesMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, ListInterfacesRequest, list_interfaces); + } +} + +struct ListRoutesMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for ListRoutesMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, ListRoutesRequest, list_routes); + } +} + +struct AddArpNeighborsMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for AddArpNeighborsMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, AddARPNeighborsRequest, add_arp_neighbors); + } +} + +struct GetIpTablesMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for GetIpTablesMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, GetIPTablesRequest, get_ip_tables); + } +} + +struct SetIpTablesMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for SetIpTablesMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, SetIPTablesRequest, set_ip_tables); + } +} + +struct GetMetricsMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for GetMetricsMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, GetMetricsRequest, get_metrics); + } +} + +struct CreateSandboxMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for CreateSandboxMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, CreateSandboxRequest, create_sandbox); + } +} + +struct DestroySandboxMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for DestroySandboxMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, DestroySandboxRequest, destroy_sandbox); + } +} + +struct OnlineCpuMemMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for OnlineCpuMemMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, OnlineCPUMemRequest, online_cpu_mem); + } +} + +struct ReseedRandomDevMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for ReseedRandomDevMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, ReseedRandomDevRequest, reseed_random_dev); + } +} + +struct GetGuestDetailsMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for GetGuestDetailsMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, GuestDetailsRequest, get_guest_details); + } +} + +struct MemHotplugByProbeMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for MemHotplugByProbeMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, MemHotplugByProbeRequest, mem_hotplug_by_probe); + } +} + +struct SetGuestDateTimeMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for SetGuestDateTimeMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, SetGuestDateTimeRequest, set_guest_date_time); + } +} + +struct CopyFileMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for CopyFileMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, CopyFileRequest, copy_file); + } +} + +struct GetOomEventMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for GetOomEventMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, GetOOMEventRequest, get_oom_event); + } +} + +struct AddSwapMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for AddSwapMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, AddSwapRequest, add_swap); + } +} + +struct GetVolumeStatsMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for GetVolumeStatsMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, VolumeStatsRequest, get_volume_stats); + } +} + +struct ResizeVolumeMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for ResizeVolumeMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, agent, ResizeVolumeRequest, resize_volume); + } +} + +#[async_trait] +pub trait AgentService: Sync { + async fn create_container(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::CreateContainerRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/CreateContainer is not supported".to_string()))) + } + async fn start_container(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::StartContainerRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/StartContainer is not supported".to_string()))) + } + async fn remove_container(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::RemoveContainerRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/RemoveContainer is not supported".to_string()))) + } + async fn exec_process(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::ExecProcessRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/ExecProcess is not supported".to_string()))) + } + async fn signal_process(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::SignalProcessRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/SignalProcess is not supported".to_string()))) + } + async fn wait_process(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::WaitProcessRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/WaitProcess is not supported".to_string()))) + } + async fn update_container(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::UpdateContainerRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/UpdateContainer is not supported".to_string()))) + } + async fn stats_container(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::StatsContainerRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/StatsContainer is not supported".to_string()))) + } + async fn pause_container(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::PauseContainerRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/PauseContainer is not supported".to_string()))) + } + async fn resume_container(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::ResumeContainerRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/ResumeContainer is not supported".to_string()))) + } + async fn write_stdin(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::WriteStreamRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/WriteStdin is not supported".to_string()))) + } + async fn read_stdout(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::ReadStreamRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/ReadStdout is not supported".to_string()))) + } + async fn read_stderr(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::ReadStreamRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/ReadStderr is not supported".to_string()))) + } + async fn close_stdin(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::CloseStdinRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/CloseStdin is not supported".to_string()))) + } + async fn tty_win_resize(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::TtyWinResizeRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/TtyWinResize is not supported".to_string()))) + } + async fn update_interface(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::UpdateInterfaceRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/UpdateInterface is not supported".to_string()))) + } + async fn update_routes(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::UpdateRoutesRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/UpdateRoutes is not supported".to_string()))) + } + async fn list_interfaces(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::ListInterfacesRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/ListInterfaces is not supported".to_string()))) + } + async fn list_routes(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::ListRoutesRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/ListRoutes is not supported".to_string()))) + } + async fn add_arp_neighbors(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::AddARPNeighborsRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/AddARPNeighbors is not supported".to_string()))) + } + async fn get_ip_tables(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::GetIPTablesRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/GetIPTables is not supported".to_string()))) + } + async fn set_ip_tables(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::SetIPTablesRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/SetIPTables is not supported".to_string()))) + } + async fn get_metrics(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::GetMetricsRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/GetMetrics is not supported".to_string()))) + } + async fn create_sandbox(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::CreateSandboxRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/CreateSandbox is not supported".to_string()))) + } + async fn destroy_sandbox(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::DestroySandboxRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/DestroySandbox is not supported".to_string()))) + } + async fn online_cpu_mem(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::OnlineCPUMemRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/OnlineCPUMem is not supported".to_string()))) + } + async fn reseed_random_dev(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::ReseedRandomDevRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/ReseedRandomDev is not supported".to_string()))) + } + async fn get_guest_details(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::GuestDetailsRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/GetGuestDetails is not supported".to_string()))) + } + async fn mem_hotplug_by_probe(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::MemHotplugByProbeRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/MemHotplugByProbe is not supported".to_string()))) + } + async fn set_guest_date_time(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::SetGuestDateTimeRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/SetGuestDateTime is not supported".to_string()))) + } + async fn copy_file(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::CopyFileRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/CopyFile is not supported".to_string()))) + } + async fn get_oom_event(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::GetOOMEventRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/GetOOMEvent is not supported".to_string()))) + } + async fn add_swap(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::AddSwapRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/AddSwap is not supported".to_string()))) + } + async fn get_volume_stats(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::VolumeStatsRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/GetVolumeStats is not supported".to_string()))) + } + async fn resize_volume(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::agent::ResizeVolumeRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.AgentService/ResizeVolume is not supported".to_string()))) + } +} + +pub fn create_agent_service(service: Arc>) -> HashMap > { + let mut methods = HashMap::new(); + + methods.insert("/grpc.AgentService/CreateContainer".to_string(), + std::boxed::Box::new(CreateContainerMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/StartContainer".to_string(), + std::boxed::Box::new(StartContainerMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/RemoveContainer".to_string(), + std::boxed::Box::new(RemoveContainerMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/ExecProcess".to_string(), + std::boxed::Box::new(ExecProcessMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/SignalProcess".to_string(), + std::boxed::Box::new(SignalProcessMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/WaitProcess".to_string(), + std::boxed::Box::new(WaitProcessMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/UpdateContainer".to_string(), + std::boxed::Box::new(UpdateContainerMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/StatsContainer".to_string(), + std::boxed::Box::new(StatsContainerMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/PauseContainer".to_string(), + std::boxed::Box::new(PauseContainerMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/ResumeContainer".to_string(), + std::boxed::Box::new(ResumeContainerMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/WriteStdin".to_string(), + std::boxed::Box::new(WriteStdinMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/ReadStdout".to_string(), + std::boxed::Box::new(ReadStdoutMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/ReadStderr".to_string(), + std::boxed::Box::new(ReadStderrMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/CloseStdin".to_string(), + std::boxed::Box::new(CloseStdinMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/TtyWinResize".to_string(), + std::boxed::Box::new(TtyWinResizeMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/UpdateInterface".to_string(), + std::boxed::Box::new(UpdateInterfaceMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/UpdateRoutes".to_string(), + std::boxed::Box::new(UpdateRoutesMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/ListInterfaces".to_string(), + std::boxed::Box::new(ListInterfacesMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/ListRoutes".to_string(), + std::boxed::Box::new(ListRoutesMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/AddARPNeighbors".to_string(), + std::boxed::Box::new(AddArpNeighborsMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/GetIPTables".to_string(), + std::boxed::Box::new(GetIpTablesMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/SetIPTables".to_string(), + std::boxed::Box::new(SetIpTablesMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/GetMetrics".to_string(), + std::boxed::Box::new(GetMetricsMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/CreateSandbox".to_string(), + std::boxed::Box::new(CreateSandboxMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/DestroySandbox".to_string(), + std::boxed::Box::new(DestroySandboxMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/OnlineCPUMem".to_string(), + std::boxed::Box::new(OnlineCpuMemMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/ReseedRandomDev".to_string(), + std::boxed::Box::new(ReseedRandomDevMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/GetGuestDetails".to_string(), + std::boxed::Box::new(GetGuestDetailsMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/MemHotplugByProbe".to_string(), + std::boxed::Box::new(MemHotplugByProbeMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/SetGuestDateTime".to_string(), + std::boxed::Box::new(SetGuestDateTimeMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/CopyFile".to_string(), + std::boxed::Box::new(CopyFileMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/GetOOMEvent".to_string(), + std::boxed::Box::new(GetOomEventMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/AddSwap".to_string(), + std::boxed::Box::new(AddSwapMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/GetVolumeStats".to_string(), + std::boxed::Box::new(GetVolumeStatsMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.AgentService/ResizeVolume".to_string(), + std::boxed::Box::new(ResizeVolumeMethod{service: service.clone()}) as std::boxed::Box); + + methods +} diff --git a/src/libs/protocols/src/health_ttrpc_async.rs b/src/libs/protocols/src/health_ttrpc_async.rs new file mode 100644 index 0000000000..5f77b30e75 --- /dev/null +++ b/src/libs/protocols/src/health_ttrpc_async.rs @@ -0,0 +1,90 @@ +// This file is generated by ttrpc-compiler 0.4.1. Do not edit +// @generated + +// https://github.com/Manishearth/rust-clippy/issues/702 +#![allow(unknown_lints)] +#![allow(clipto_camel_casepy)] + +#![cfg_attr(rustfmt, rustfmt_skip)] + +#![allow(box_pointers)] +#![allow(dead_code)] +#![allow(missing_docs)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] +#![allow(trivial_casts)] +#![allow(unsafe_code)] +#![allow(unused_imports)] +#![allow(unused_results)] +use protobuf::{CodedInputStream, CodedOutputStream, Message}; +use std::collections::HashMap; +use std::sync::Arc; +use async_trait::async_trait; + +#[derive(Clone)] +pub struct HealthClient { + client: ::ttrpc::r#async::Client, +} + +impl HealthClient { + pub fn new(client: ::ttrpc::r#async::Client) -> Self { + HealthClient { + client: client, + } + } + + pub async fn check(&mut self, ctx: ttrpc::context::Context, req: &super::health::CheckRequest) -> ::ttrpc::Result { + let mut cres = super::health::HealthCheckResponse::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.Health", "Check", cres); + } + + pub async fn version(&mut self, ctx: ttrpc::context::Context, req: &super::health::CheckRequest) -> ::ttrpc::Result { + let mut cres = super::health::VersionCheckResponse::new(); + ::ttrpc::async_client_request!(self, ctx, req, "grpc.Health", "Version", cres); + } +} + +struct CheckMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for CheckMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, health, CheckRequest, check); + } +} + +struct VersionMethod { + service: Arc>, +} + +#[async_trait] +impl ::ttrpc::r#async::MethodHandler for VersionMethod { + async fn handler(&self, ctx: ::ttrpc::r#async::TtrpcContext, req: ::ttrpc::Request) -> ::ttrpc::Result<(u32, Vec)> { + ::ttrpc::async_request_handler!(self, ctx, req, health, CheckRequest, version); + } +} + +#[async_trait] +pub trait Health: Sync { + async fn check(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::health::CheckRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.Health/Check is not supported".to_string()))) + } + async fn version(&self, _ctx: &::ttrpc::r#async::TtrpcContext, _req: super::health::CheckRequest) -> ::ttrpc::Result { + Err(::ttrpc::Error::RpcStatus(::ttrpc::get_status(::ttrpc::Code::NOT_FOUND, "/grpc.Health/Version is not supported".to_string()))) + } +} + +pub fn create_health(service: Arc>) -> HashMap > { + let mut methods = HashMap::new(); + + methods.insert("/grpc.Health/Check".to_string(), + std::boxed::Box::new(CheckMethod{service: service.clone()}) as std::boxed::Box); + + methods.insert("/grpc.Health/Version".to_string(), + std::boxed::Box::new(VersionMethod{service: service.clone()}) as std::boxed::Box); + + methods +} diff --git a/src/libs/protocols/src/lib.rs b/src/libs/protocols/src/lib.rs index 14298e52d9..0c62b8a933 100644 --- a/src/libs/protocols/src/lib.rs +++ b/src/libs/protocols/src/lib.rs @@ -7,9 +7,14 @@ pub mod agent; pub mod agent_ttrpc; +#[cfg(feature = "async")] +pub mod agent_ttrpc_async; pub mod csi; pub mod empty; pub mod health; pub mod health_ttrpc; +#[cfg(feature = "async")] +pub mod health_ttrpc_async; pub mod oci; +pub mod trans; pub mod types; diff --git a/src/libs/protocols/src/trans.rs b/src/libs/protocols/src/trans.rs new file mode 100644 index 0000000000..52fb0d99ea --- /dev/null +++ b/src/libs/protocols/src/trans.rs @@ -0,0 +1,1085 @@ +// Copyright (c) 2019-2022 Alibaba Cloud +// Copyright (c) 2019-2022 Ant Group +// +// SPDX-License-Identifier: Apache-2.0 +// + +use std::collections::HashMap; +use std::convert::From; + +use oci::{ + Hook, Hooks, Linux, LinuxBlockIo, LinuxCapabilities, LinuxCpu, LinuxDevice, LinuxHugepageLimit, + LinuxIdMapping, LinuxIntelRdt, LinuxInterfacePriority, LinuxMemory, LinuxNamespace, + LinuxNetwork, LinuxPids, LinuxResources, LinuxSeccomp, LinuxSeccompArg, LinuxSyscall, + LinuxThrottleDevice, LinuxWeightDevice, Mount, PosixRlimit, Process, Root, Spec, User, +}; + +// translate from interface to ttprc tools +fn from_option>(from: Option) -> ::protobuf::SingularPtrField { + match from { + Some(f) => ::protobuf::SingularPtrField::from_option(Some(T::from(f))), + None => ::protobuf::SingularPtrField::none(), + } +} + +fn from_vec>(from: Vec) -> ::protobuf::RepeatedField { + let mut to: Vec = vec![]; + for data in from { + to.push(T::from(data)); + } + ::protobuf::RepeatedField::from_vec(to) +} + +impl From for crate::oci::Box { + fn from(from: oci::Box) -> Self { + crate::oci::Box { + Height: from.height, + Width: from.width, + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::User { + fn from(from: User) -> Self { + crate::oci::User { + UID: from.uid, + GID: from.gid, + AdditionalGids: from.additional_gids, + Username: from.username, + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::LinuxCapabilities { + fn from(from: LinuxCapabilities) -> Self { + crate::oci::LinuxCapabilities { + Bounding: from_vec(from.bounding), + Effective: from_vec(from.effective), + Inheritable: from_vec(from.inheritable), + Permitted: from_vec(from.permitted), + Ambient: from_vec(from.ambient), + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::POSIXRlimit { + fn from(from: PosixRlimit) -> Self { + crate::oci::POSIXRlimit { + Type: from.r#type, + Hard: from.hard, + Soft: from.soft, + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::Process { + fn from(from: Process) -> Self { + crate::oci::Process { + Terminal: from.terminal, + ConsoleSize: from_option(from.console_size), + User: from_option(Some(from.user)), + Args: from_vec(from.args), + Env: from_vec(from.env), + Cwd: from.cwd, + Capabilities: from_option(from.capabilities), + Rlimits: from_vec(from.rlimits), + NoNewPrivileges: from.no_new_privileges, + ApparmorProfile: from.apparmor_profile, + OOMScoreAdj: from.oom_score_adj.map_or(0, |t| t as i64), + SelinuxLabel: from.selinux_label, + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::LinuxDeviceCgroup { + fn from(from: oci::LinuxDeviceCgroup) -> Self { + crate::oci::LinuxDeviceCgroup { + Allow: from.allow, + Type: from.r#type, + Major: from.major.map_or(0, |t| t as i64), + Minor: from.minor.map_or(0, |t| t as i64), + Access: from.access, + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::LinuxMemory { + fn from(from: LinuxMemory) -> Self { + crate::oci::LinuxMemory { + Limit: from.limit.map_or(0, |t| t), + Reservation: from.reservation.map_or(0, |t| t), + Swap: from.swap.map_or(0, |t| t), + Kernel: from.kernel.map_or(0, |t| t), + KernelTCP: from.kernel_tcp.map_or(0, |t| t), + Swappiness: from.swappiness.map_or(0, |t| t as u64), + DisableOOMKiller: from.disable_oom_killer.map_or(false, |t| t), + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::LinuxCPU { + fn from(from: LinuxCpu) -> Self { + crate::oci::LinuxCPU { + Shares: from.shares.map_or(0, |t| t), + Quota: from.quota.map_or(0, |t| t), + Period: from.period.map_or(0, |t| t), + RealtimeRuntime: from.realtime_runtime.map_or(0, |t| t), + RealtimePeriod: from.realtime_period.map_or(0, |t| t), + Cpus: from.cpus, + Mems: from.mems, + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::LinuxPids { + fn from(from: LinuxPids) -> Self { + crate::oci::LinuxPids { + Limit: from.limit, + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::LinuxWeightDevice { + fn from(from: LinuxWeightDevice) -> Self { + crate::oci::LinuxWeightDevice { + // TODO : check + Major: 0, + Minor: 0, + Weight: from.weight.map_or(0, |t| t as u32), + LeafWeight: from.leaf_weight.map_or(0, |t| t as u32), + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::LinuxThrottleDevice { + fn from(from: LinuxThrottleDevice) -> Self { + crate::oci::LinuxThrottleDevice { + // TODO : check + Major: 0, + Minor: 0, + Rate: from.rate, + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::LinuxBlockIO { + fn from(from: LinuxBlockIo) -> Self { + crate::oci::LinuxBlockIO { + Weight: from.weight.map_or(0, |t| t as u32), + LeafWeight: from.leaf_weight.map_or(0, |t| t as u32), + WeightDevice: from_vec(from.weight_device), + ThrottleReadBpsDevice: from_vec(from.throttle_read_bps_device), + ThrottleWriteBpsDevice: from_vec(from.throttle_write_bps_device), + ThrottleReadIOPSDevice: from_vec(from.throttle_read_iops_device), + ThrottleWriteIOPSDevice: from_vec(from.throttle_write_iops_device), + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::LinuxHugepageLimit { + fn from(from: LinuxHugepageLimit) -> Self { + crate::oci::LinuxHugepageLimit { + Pagesize: from.page_size, + Limit: from.limit, + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::LinuxInterfacePriority { + fn from(from: LinuxInterfacePriority) -> Self { + crate::oci::LinuxInterfacePriority { + Name: from.name, + Priority: from.priority, + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::LinuxNetwork { + fn from(from: LinuxNetwork) -> Self { + crate::oci::LinuxNetwork { + ClassID: from.class_id.map_or(0, |t| t), + Priorities: from_vec(from.priorities), + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::LinuxResources { + fn from(from: LinuxResources) -> Self { + crate::oci::LinuxResources { + Devices: from_vec(from.devices), + Memory: from_option(from.memory), + CPU: from_option(from.cpu), + Pids: from_option(from.pids), + BlockIO: from_option(from.block_io), + HugepageLimits: from_vec(from.hugepage_limits), + Network: from_option(from.network), + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::Root { + fn from(from: Root) -> Self { + crate::oci::Root { + Path: from.path, + Readonly: from.readonly, + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::Mount { + fn from(from: Mount) -> Self { + crate::oci::Mount { + destination: from.destination, + source: from.source, + field_type: from.r#type, + options: from_vec(from.options), + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::Hook { + fn from(from: Hook) -> Self { + let mut timeout: i64 = 0; + if let Some(v) = from.timeout { + timeout = v as i64; + } + crate::oci::Hook { + Path: from.path, + Args: from_vec(from.args), + Env: from_vec(from.env), + Timeout: timeout, + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::Hooks { + fn from(from: Hooks) -> Self { + crate::oci::Hooks { + Prestart: from_vec(from.prestart), + Poststart: from_vec(from.poststart), + Poststop: from_vec(from.poststop), + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::LinuxIDMapping { + fn from(from: LinuxIdMapping) -> Self { + crate::oci::LinuxIDMapping { + HostID: from.host_id, + ContainerID: from.container_id, + Size: from.size, + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::LinuxNamespace { + fn from(from: LinuxNamespace) -> Self { + crate::oci::LinuxNamespace { + Type: from.r#type, + Path: from.path, + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::LinuxDevice { + fn from(from: LinuxDevice) -> Self { + crate::oci::LinuxDevice { + Path: from.path, + Type: from.r#type, + Major: from.major, + Minor: from.minor, + FileMode: from.file_mode.map_or(0, |v| v as u32), + UID: from.uid.map_or(0, |v| v), + GID: from.gid.map_or(0, |v| v), + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::LinuxSeccompArg { + fn from(from: LinuxSeccompArg) -> Self { + crate::oci::LinuxSeccompArg { + Index: from.index as u64, + Value: from.value, + ValueTwo: from.value_two, + Op: from.op, + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::LinuxSyscall { + fn from(from: LinuxSyscall) -> Self { + crate::oci::LinuxSyscall { + Names: from_vec(from.names), + Action: from.action, + Args: from_vec(from.args), + ErrnoRet: Some(crate::oci::LinuxSyscall_oneof_ErrnoRet::errnoret( + from.errno_ret, + )), + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::LinuxSeccomp { + fn from(from: LinuxSeccomp) -> Self { + crate::oci::LinuxSeccomp { + DefaultAction: from.default_action, + Architectures: from_vec(from.architectures), + Syscalls: from_vec(from.syscalls), + Flags: from_vec(from.flags), + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::LinuxIntelRdt { + fn from(from: LinuxIntelRdt) -> Self { + crate::oci::LinuxIntelRdt { + L3CacheSchema: from.l3_cache_schema, + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::Linux { + fn from(from: Linux) -> Self { + crate::oci::Linux { + UIDMappings: from_vec(from.uid_mappings), + GIDMappings: from_vec(from.gid_mappings), + Sysctl: from.sysctl, + Resources: from_option(from.resources), + CgroupsPath: from.cgroups_path, + Namespaces: from_vec(from.namespaces), + Devices: from_vec(from.devices), + Seccomp: from_option(from.seccomp), + RootfsPropagation: from.rootfs_propagation, + MaskedPaths: from_vec(from.masked_paths), + ReadonlyPaths: from_vec(from.readonly_paths), + MountLabel: from.mount_label, + IntelRdt: from_option(from.intel_rdt), + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for crate::oci::Spec { + fn from(from: Spec) -> Self { + crate::oci::Spec { + Version: from.version, + Process: from_option(from.process), + Root: from_option(from.root), + Hostname: from.hostname, + Mounts: from_vec(from.mounts), + Hooks: from_option(from.hooks), + Annotations: from.annotations, + Linux: from_option(from.linux), + Solaris: Default::default(), + Windows: Default::default(), + unknown_fields: Default::default(), + cached_size: Default::default(), + } + } +} + +impl From for oci::Root { + fn from(from: crate::oci::Root) -> Self { + Self { + path: from.Path, + readonly: from.Readonly, + } + } +} + +impl From for oci::Mount { + fn from(mut from: crate::oci::Mount) -> Self { + let options = from.take_options().to_vec(); + Self { + r#type: from.take_field_type(), + destination: from.take_destination(), + source: from.take_source(), + options, + } + } +} + +impl From for oci::LinuxIdMapping { + fn from(from: crate::oci::LinuxIDMapping) -> Self { + LinuxIdMapping { + container_id: from.get_ContainerID(), + host_id: from.get_HostID(), + size: from.get_Size(), + } + } +} + +impl From for oci::LinuxDeviceCgroup { + fn from(mut from: crate::oci::LinuxDeviceCgroup) -> Self { + let mut major = None; + if from.get_Major() > 0 { + major = Some(from.get_Major() as i64); + } + + let mut minor = None; + if from.get_Minor() > 0 { + minor = Some(from.get_Minor() as i64) + } + + oci::LinuxDeviceCgroup { + allow: from.get_Allow(), + r#type: from.take_Type(), + major, + minor, + access: from.take_Access(), + } + } +} + +impl From for oci::LinuxMemory { + fn from(from: crate::oci::LinuxMemory) -> Self { + let mut limit = None; + if from.get_Limit() > 0 { + limit = Some(from.get_Limit()); + } + + let mut reservation = None; + if from.get_Reservation() > 0 { + reservation = Some(from.get_Reservation()); + } + + let mut swap = None; + if from.get_Swap() > 0 { + swap = Some(from.get_Swap()); + } + + let mut kernel = None; + if from.get_Kernel() > 0 { + kernel = Some(from.get_Kernel()); + } + + let mut kernel_tcp = None; + if from.get_KernelTCP() > 0 { + kernel_tcp = Some(from.get_KernelTCP()); + } + + let mut swappiness = None; + if from.get_Swappiness() > 0 { + swappiness = Some(from.get_Swappiness() as i64); + } + + let disable_oom_killer = Some(from.get_DisableOOMKiller()); + + oci::LinuxMemory { + limit, + reservation, + swap, + kernel, + kernel_tcp, + swappiness, + disable_oom_killer, + } + } +} + +impl From for oci::LinuxCpu { + fn from(mut from: crate::oci::LinuxCPU) -> Self { + let mut shares = None; + if from.get_Shares() > 0 { + shares = Some(from.get_Shares()); + } + + let mut quota = None; + if from.get_Quota() > 0 { + quota = Some(from.get_Quota()); + } + + let mut period = None; + if from.get_Period() > 0 { + period = Some(from.get_Period()); + } + + let mut realtime_runtime = None; + if from.get_RealtimeRuntime() > 0 { + realtime_runtime = Some(from.get_RealtimeRuntime()); + } + + let mut realtime_period = None; + if from.get_RealtimePeriod() > 0 { + realtime_period = Some(from.get_RealtimePeriod()); + } + + let cpus = from.take_Cpus(); + let mems = from.take_Mems(); + + oci::LinuxCpu { + shares, + quota, + period, + realtime_runtime, + realtime_period, + cpus, + mems, + } + } +} + +impl From for oci::LinuxPids { + fn from(from: crate::oci::LinuxPids) -> Self { + oci::LinuxPids { + limit: from.get_Limit(), + } + } +} + +impl From for oci::LinuxBlockIo { + fn from(from: crate::oci::LinuxBlockIO) -> Self { + let mut weight = None; + if from.get_Weight() > 0 { + weight = Some(from.get_Weight() as u16); + } + let mut leaf_weight = None; + if from.get_LeafWeight() > 0 { + leaf_weight = Some(from.get_LeafWeight() as u16); + } + let mut weight_device = Vec::new(); + for wd in from.get_WeightDevice() { + weight_device.push(wd.clone().into()); + } + + let mut throttle_read_bps_device = Vec::new(); + for td in from.get_ThrottleReadBpsDevice() { + throttle_read_bps_device.push(td.clone().into()); + } + + let mut throttle_write_bps_device = Vec::new(); + for td in from.get_ThrottleWriteBpsDevice() { + throttle_write_bps_device.push(td.clone().into()); + } + + let mut throttle_read_iops_device = Vec::new(); + for td in from.get_ThrottleReadIOPSDevice() { + throttle_read_iops_device.push(td.clone().into()); + } + + let mut throttle_write_iops_device = Vec::new(); + for td in from.get_ThrottleWriteIOPSDevice() { + throttle_write_iops_device.push(td.clone().into()); + } + + oci::LinuxBlockIo { + weight, + leaf_weight, + weight_device, + throttle_read_bps_device, + throttle_write_bps_device, + throttle_read_iops_device, + throttle_write_iops_device, + } + } +} + +impl From for oci::LinuxThrottleDevice { + fn from(from: crate::oci::LinuxThrottleDevice) -> Self { + oci::LinuxThrottleDevice { + blk: oci::LinuxBlockIoDevice { + major: from.Major, + minor: from.Minor, + }, + rate: from.Rate, + } + } +} + +impl From for oci::LinuxWeightDevice { + fn from(from: crate::oci::LinuxWeightDevice) -> Self { + oci::LinuxWeightDevice { + blk: oci::LinuxBlockIoDevice { + major: from.Major, + minor: from.Minor, + }, + weight: Some(from.Weight as u16), + leaf_weight: Some(from.LeafWeight as u16), + } + } +} + +impl From for oci::LinuxInterfacePriority { + fn from(mut from: crate::oci::LinuxInterfacePriority) -> Self { + oci::LinuxInterfacePriority { + name: from.take_Name(), + priority: from.get_Priority(), + } + } +} + +impl From for oci::LinuxNetwork { + fn from(mut from: crate::oci::LinuxNetwork) -> Self { + let mut class_id = None; + if from.get_ClassID() > 0 { + class_id = Some(from.get_ClassID()); + } + let mut priorities = Vec::new(); + for p in from.take_Priorities().to_vec() { + priorities.push(p.into()) + } + + oci::LinuxNetwork { + class_id, + priorities, + } + } +} + +impl From for oci::LinuxHugepageLimit { + fn from(mut from: crate::oci::LinuxHugepageLimit) -> Self { + oci::LinuxHugepageLimit { + page_size: from.take_Pagesize(), + limit: from.get_Limit(), + } + } +} + +impl From for oci::LinuxResources { + fn from(mut from: crate::oci::LinuxResources) -> Self { + let mut devices = Vec::new(); + for d in from.take_Devices().to_vec() { + devices.push(d.into()); + } + + let mut memory = None; + if from.has_Memory() { + memory = Some(from.take_Memory().into()); + } + + let mut cpu = None; + if from.has_CPU() { + cpu = Some(from.take_CPU().into()); + } + + let mut pids = None; + if from.has_Pids() { + pids = Some(from.get_Pids().clone().into()) + } + + let mut block_io = None; + if from.has_BlockIO() { + block_io = Some(from.get_BlockIO().clone().into()); + } + + let mut hugepage_limits = Vec::new(); + for hl in from.get_HugepageLimits() { + hugepage_limits.push(hl.clone().into()); + } + + let mut network = None; + if from.has_Network() { + network = Some(from.take_Network().into()); + } + + let rdma = HashMap::new(); + + LinuxResources { + devices, + memory, + cpu, + pids, + block_io, + hugepage_limits, + network, + rdma, + } + } +} + +impl From for oci::LinuxDevice { + fn from(mut from: crate::oci::LinuxDevice) -> Self { + oci::LinuxDevice { + path: from.take_Path(), + r#type: from.take_Type(), + major: from.get_Major(), + minor: from.get_Minor(), + file_mode: Some(from.get_FileMode()), + uid: Some(from.get_UID()), + gid: Some(from.get_GID()), + } + } +} + +impl From for oci::LinuxSeccompArg { + fn from(mut from: crate::oci::LinuxSeccompArg) -> Self { + oci::LinuxSeccompArg { + index: from.get_Index() as u32, + value: from.get_Value(), + value_two: from.get_ValueTwo(), + op: from.take_Op(), + } + } +} + +impl From for oci::LinuxSyscall { + fn from(mut from: crate::oci::LinuxSyscall) -> Self { + let mut args = Vec::new(); + for ag in from.take_Args().to_vec() { + args.push(ag.into()); + } + oci::LinuxSyscall { + names: from.take_Names().to_vec(), + action: from.take_Action(), + args, + errno_ret: from.get_errnoret(), + } + } +} + +impl From for oci::LinuxSeccomp { + fn from(mut from: crate::oci::LinuxSeccomp) -> Self { + let mut syscalls = Vec::new(); + for s in from.take_Syscalls().to_vec() { + syscalls.push(s.into()); + } + + oci::LinuxSeccomp { + default_action: from.take_DefaultAction(), + architectures: from.take_Architectures().to_vec(), + syscalls, + flags: from.take_Flags().to_vec(), + } + } +} + +impl From for oci::LinuxNamespace { + fn from(mut from: crate::oci::LinuxNamespace) -> Self { + oci::LinuxNamespace { + r#type: from.take_Type(), + path: from.take_Path(), + } + } +} + +impl From for oci::Linux { + fn from(mut from: crate::oci::Linux) -> Self { + let mut uid_mappings = Vec::new(); + for id_map in from.take_UIDMappings().to_vec() { + uid_mappings.push(id_map.into()) + } + + let mut gid_mappings = Vec::new(); + for id_map in from.take_GIDMappings().to_vec() { + gid_mappings.push(id_map.into()) + } + + let sysctl = from.get_Sysctl().clone(); + let mut resources = None; + if from.has_Resources() { + resources = Some(from.take_Resources().into()); + } + + let cgroups_path = from.take_CgroupsPath(); + let mut namespaces = Vec::new(); + for ns in from.take_Namespaces().to_vec() { + namespaces.push(ns.into()) + } + + let mut devices = Vec::new(); + for d in from.take_Devices().to_vec() { + devices.push(d.into()); + } + + let mut seccomp = None; + if from.has_Seccomp() { + seccomp = Some(from.take_Seccomp().into()); + } + + let rootfs_propagation = from.take_RootfsPropagation(); + let masked_paths = from.take_MaskedPaths().to_vec(); + + let readonly_paths = from.take_ReadonlyPaths().to_vec(); + + let mount_label = from.take_MountLabel(); + let intel_rdt = None; + + oci::Linux { + uid_mappings, + gid_mappings, + sysctl, + resources, + cgroups_path, + namespaces, + devices, + seccomp, + rootfs_propagation, + masked_paths, + readonly_paths, + mount_label, + intel_rdt, + } + } +} + +impl From for oci::PosixRlimit { + fn from(mut from: crate::oci::POSIXRlimit) -> Self { + oci::PosixRlimit { + r#type: from.take_Type(), + hard: from.get_Hard(), + soft: from.get_Soft(), + } + } +} + +impl From for oci::LinuxCapabilities { + fn from(mut from: crate::oci::LinuxCapabilities) -> Self { + oci::LinuxCapabilities { + bounding: from.take_Bounding().to_vec(), + effective: from.take_Effective().to_vec(), + inheritable: from.take_Inheritable().to_vec(), + permitted: from.take_Permitted().to_vec(), + ambient: from.take_Ambient().to_vec(), + } + } +} + +impl From for oci::User { + fn from(mut from: crate::oci::User) -> Self { + oci::User { + uid: from.get_UID(), + gid: from.get_GID(), + additional_gids: from.take_AdditionalGids().to_vec(), + username: from.take_Username(), + } + } +} + +impl From for oci::Box { + fn from(from: crate::oci::Box) -> Self { + oci::Box { + height: from.get_Height(), + width: from.get_Width(), + } + } +} + +impl From for oci::Process { + fn from(mut from: crate::oci::Process) -> Self { + let mut console_size = None; + if from.has_ConsoleSize() { + console_size = Some(from.take_ConsoleSize().into()); + } + + let user = from.take_User().into(); + let args = from.take_Args().into_vec(); + let env = from.take_Env().into_vec(); + let cwd = from.take_Cwd(); + let mut capabilities = None; + if from.has_Capabilities() { + capabilities = Some(from.take_Capabilities().into()); + } + let mut rlimits = Vec::new(); + for rl in from.take_Rlimits().to_vec() { + rlimits.push(rl.into()); + } + let no_new_privileges = from.get_NoNewPrivileges(); + let apparmor_profile = from.take_ApparmorProfile(); + let mut oom_score_adj = None; + if from.get_OOMScoreAdj() != 0 { + oom_score_adj = Some(from.get_OOMScoreAdj() as i32); + } + let selinux_label = from.take_SelinuxLabel(); + + oci::Process { + terminal: from.Terminal, + console_size, + user, + args, + env, + cwd, + capabilities, + rlimits, + no_new_privileges, + apparmor_profile, + oom_score_adj, + selinux_label, + } + } +} + +impl From for oci::Hook { + fn from(mut from: crate::oci::Hook) -> Self { + let mut timeout = None; + if from.get_Timeout() > 0 { + timeout = Some(from.get_Timeout() as i32); + } + oci::Hook { + path: from.take_Path(), + args: from.take_Args().to_vec(), + env: from.take_Env().to_vec(), + timeout, + } + } +} + +impl From for oci::Hooks { + fn from(mut from: crate::oci::Hooks) -> Self { + let mut prestart = Vec::new(); + for hook in from.take_Prestart().to_vec() { + prestart.push(hook.into()) + } + let mut poststart = Vec::new(); + for hook in from.take_Poststart().to_vec() { + poststart.push(hook.into()); + } + let mut poststop = Vec::new(); + for hook in from.take_Poststop().to_vec() { + poststop.push(hook.into()); + } + oci::Hooks { + prestart, + poststart, + poststop, + } + } +} + +impl From for oci::Spec { + fn from(mut from: crate::oci::Spec) -> Self { + let mut process = None; + if from.has_Process() { + process = Some(from.take_Process().into()); + } + + let mut root = None; + if from.has_Root() { + root = Some(from.take_Root().into()); + } + + let mut mounts = Vec::new(); + for m in from.take_Mounts().into_vec() { + mounts.push(m.into()) + } + + let mut hooks: Option = None; + if from.has_Hooks() { + hooks = Some(from.take_Hooks().into()); + } + + let annotations = from.take_Annotations(); + + let mut linux = None; + if from.has_Linux() { + linux = Some(from.take_Linux().into()); + } + + oci::Spec { + version: from.take_Version(), + process, + root, + hostname: from.take_Hostname(), + mounts, + hooks, + annotations, + linux, + solaris: None, + windows: None, + vm: None, + } + } +} + +#[cfg(test)] +mod tests { + use crate::trans::from_vec; + + #[derive(Clone)] + struct TestA { + pub from: String, + } + + #[derive(Clone)] + struct TestB { + pub to: String, + } + + impl From for TestB { + fn from(from: TestA) -> Self { + TestB { to: from.from } + } + } + + #[test] + fn test_from() { + let from = TestA { + from: "a".to_string(), + }; + let to: TestB = TestB::from(from.clone()); + + assert_eq!(from.from, to.to); + } + + #[test] + fn test_from_vec_len_0() { + let from: Vec = vec![]; + let to: ::protobuf::RepeatedField = from_vec(from.clone()); + assert_eq!(from.len(), to.len()); + } + + #[test] + fn test_from_vec_len_1() { + let from: Vec = vec![TestA { + from: "a".to_string(), + }]; + let to: ::protobuf::RepeatedField = from_vec(from.clone()); + + assert_eq!(from.len(), to.len()); + assert_eq!(from[0].from, to[0].to); + } +} diff --git a/src/tools/agent-ctl/Cargo.lock b/src/tools/agent-ctl/Cargo.lock index d82e11e6e8..ec036924e0 100644 --- a/src/tools/agent-ctl/Cargo.lock +++ b/src/tools/agent-ctl/Cargo.lock @@ -72,16 +72,6 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" -[[package]] -name = "bytes" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" -dependencies = [ - "byteorder", - "iovec", -] - [[package]] name = "bytes" version = "1.1.0" @@ -129,7 +119,7 @@ checksum = "1b827f9d9f6c2fff719d25f5d44cbc8d2ef6df1ef00d055c5c14d5dc25529579" dependencies = [ "libc", "log", - "nix 0.23.1", + "nix", "regex", ] @@ -398,15 +388,6 @@ dependencies = [ "libc", ] -[[package]] -name = "iovec" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" -dependencies = [ - "libc", -] - [[package]] name = "itertools" version = "0.10.3" @@ -434,7 +415,7 @@ dependencies = [ "lazy_static", "libc", "logging", - "nix 0.23.1", + "nix", "oci", "protobuf", "protocols", @@ -522,19 +503,6 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" -[[package]] -name = "nix" -version = "0.20.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5e06129fb611568ef4e868c14b326274959aa70ff7776e9d55323531c374945" -dependencies = [ - "bitflags", - "cc", - "cfg-if", - "libc", - "memoffset", -] - [[package]] name = "nix" version = "0.23.1" @@ -666,7 +634,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de5e2533f59d08fcf364fd374ebda0692a70bd6d7e66ef97f306f45c6c5d8020" dependencies = [ - "bytes 1.1.0", + "bytes", "prost-derive", ] @@ -676,7 +644,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "355f634b43cdd80724ee7848f95770e7e70eefa6dcf14fea676216573b8fd603" dependencies = [ - "bytes 1.1.0", + "bytes", "heck", "itertools", "log", @@ -707,15 +675,15 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "603bbd6394701d13f3f25aada59c7de9d35a6a5887cfc156181234a44002771b" dependencies = [ - "bytes 1.1.0", + "bytes", "prost", ] [[package]] name = "protobuf" -version = "2.14.0" +version = "2.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e86d370532557ae7573551a1ec8235a0f8d6cb276c7c9e6aa490b511c447485" +checksum = "cf7e6d18738ecd0902d30d1ad232c9125985a3422929b16c65517b38adc14f96" dependencies = [ "serde", "serde_derive", @@ -723,18 +691,18 @@ dependencies = [ [[package]] name = "protobuf-codegen" -version = "2.14.0" +version = "2.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de113bba758ccf2c1ef816b127c958001b7831136c9bc3f8e9ec695ac4e82b0c" +checksum = "aec1632b7c8f2e620343439a7dfd1f3c47b18906c4be58982079911482b5d707" dependencies = [ "protobuf", ] [[package]] name = "protobuf-codegen-pure" -version = "2.14.0" +version = "2.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d1a4febc73bf0cada1d77c459a0c8e5973179f1cfd5b0f1ab789d45b17b6440" +checksum = "9f8122fdb18e55190c796b088a16bdb70cd7acdcd48f7a8b796b58c62e532cc6" dependencies = [ "protobuf", "protobuf-codegen", @@ -744,7 +712,7 @@ dependencies = [ name = "protocols" version = "0.1.0" dependencies = [ - "async-trait", + "oci", "protobuf", "serde", "serde_json", @@ -858,7 +826,7 @@ dependencies = [ "inotify", "lazy_static", "libc", - "nix 0.23.1", + "nix", "oci", "path-absolutize", "protobuf", @@ -1080,7 +1048,7 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbbf1c778ec206785635ce8ad57fe52b3009ae9e0c9f574a728f3049d3e55838" dependencies = [ - "bytes 1.1.0", + "bytes", "libc", "memchr", "mio", @@ -1102,36 +1070,19 @@ dependencies = [ "syn", ] -[[package]] -name = "tokio-vsock" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e0723fc001950a3b018947b05eeb45014fd2b7c6e8f292502193ab74486bdb6" -dependencies = [ - "bytes 0.4.12", - "futures", - "libc", - "tokio", - "vsock", -] - [[package]] name = "ttrpc" -version = "0.5.2" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66a973ce6d5eaa20c173635b29ffb660dafbc7ef109172c0015ba44e47a23711" +checksum = "0c7d6c992964a013c17814c08d31708d577b0aae44ebadb58755659dd824c2d1" dependencies = [ - "async-trait", "byteorder", - "futures", "libc", "log", - "nix 0.20.2", + "nix", "protobuf", "protobuf-codegen-pure", "thiserror", - "tokio", - "tokio-vsock", ] [[package]] @@ -1185,16 +1136,6 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" -[[package]] -name = "vsock" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e32675ee2b3ce5df274c0ab52d19b28789632406277ca26bffee79a8e27dc133" -dependencies = [ - "libc", - "nix 0.23.1", -] - [[package]] name = "wasi" version = "0.10.2+wasi-snapshot-preview1" diff --git a/src/tools/agent-ctl/Cargo.toml b/src/tools/agent-ctl/Cargo.toml index 8847f734f4..4d5845f1c3 100644 --- a/src/tools/agent-ctl/Cargo.toml +++ b/src/tools/agent-ctl/Cargo.toml @@ -31,7 +31,7 @@ protobuf = "2.14.0" nix = "0.23.0" libc = "0.2.112" # XXX: Must be the same as the version used by the agent -ttrpc = { version = "0.5.2" } +ttrpc = { version = "0.6.0" } # For parsing timeouts humantime = "2.1.0" diff --git a/src/tools/agent-ctl/src/client.rs b/src/tools/agent-ctl/src/client.rs index 315969b87b..802bc79669 100644 --- a/src/tools/agent-ctl/src/client.rs +++ b/src/tools/agent-ctl/src/client.rs @@ -561,7 +561,7 @@ fn create_ttrpc_client( } }; - Ok(ttrpc::client::Client::new(fd)) + Ok(ttrpc::Client::new(fd)) } fn kata_service_agent( diff --git a/src/tools/agent-ctl/src/main.rs b/src/tools/agent-ctl/src/main.rs index 93d913ba86..fe5722b079 100644 --- a/src/tools/agent-ctl/src/main.rs +++ b/src/tools/agent-ctl/src/main.rs @@ -181,11 +181,11 @@ fn connect(name: &str, global_args: clap::ArgMatches) -> Result<()> { let cfg = Config { server_address, bundle_dir, - interactive, - ignore_errors, timeout_nano, hybrid_vsock_port, + interactive, hybrid_vsock, + ignore_errors, no_auto_values, }; diff --git a/src/tools/agent-ctl/src/utils.rs b/src/tools/agent-ctl/src/utils.rs index 064b54486a..bd094df170 100644 --- a/src/tools/agent-ctl/src/utils.rs +++ b/src/tools/agent-ctl/src/utils.rs @@ -203,11 +203,7 @@ pub fn get_option(name: &str, options: &mut Options, args: &str) -> Result { msg = "derived"; - match options.get("cid") { - Some(value) => value, - None => "", - } - .into() + options.get("cid").unwrap_or(&"".to_string()).into() } _ => "".into(), };