From efe625dfc1a23404a3730ba65e6f77a88d963ffc Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Fri, 5 Mar 2021 09:48:43 +0000 Subject: [PATCH 1/3] build: Remove whitespace Zap trailing whitespace. Signed-off-by: James O. D. Hunt --- tools/agent-ctl/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/agent-ctl/Makefile b/tools/agent-ctl/Makefile index 54c948a817..cfb46560ef 100644 --- a/tools/agent-ctl/Makefile +++ b/tools/agent-ctl/Makefile @@ -13,7 +13,7 @@ clean: test: -install: +install: check: From fcd45def537bd1c072369f847f6c56abc0cfe0db Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Fri, 26 Feb 2021 17:19:07 +0000 Subject: [PATCH 2/3] agent-ctl: Unbreak build The recent switch to an async rust agent broke the `agent-ctl` tool. However, we didn't notice because that isn't being built by the CI. Fix the breakage by passing a ttRPC context to all ttRPC API calls and also build the tool as part of the static checks CI. Fixes: #1471. Signed-off-by: James O. D. Hunt --- .github/workflows/static-checks.yaml | 3 + tools/agent-ctl/Cargo.lock | 281 +++++++-------------------- tools/agent-ctl/Cargo.toml | 2 +- tools/agent-ctl/src/client.rs | 279 +++++++++++++++++++------- 4 files changed, 274 insertions(+), 291 deletions(-) diff --git a/.github/workflows/static-checks.yaml b/.github/workflows/static-checks.yaml index 0668777558..0bcefcc0a1 100644 --- a/.github/workflows/static-checks.yaml +++ b/.github/workflows/static-checks.yaml @@ -66,3 +66,6 @@ jobs: - name: Run agent unit tests run: | cd ${GOPATH}/src/github.com/kata-containers/kata-containers/src/agent && make check + - name: Build agent-ctl tool (must be buildable against current agent) + run: | + cd ${GOPATH}/src/github.com/kata-containers/kata-containers/tools/agent-ctl && make diff --git a/tools/agent-ctl/Cargo.lock b/tools/agent-ctl/Cargo.lock index 26ffc33ffc..ce45a2c11e 100644 --- a/tools/agent-ctl/Cargo.lock +++ b/tools/agent-ctl/Cargo.lock @@ -30,7 +30,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" dependencies = [ - "winapi 0.3.8", + "winapi", ] [[package]] @@ -76,7 +76,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi", "libc", - "winapi 0.3.8", + "winapi", ] [[package]] @@ -140,19 +140,19 @@ dependencies = [ [[package]] name = "bytes" -version = "0.5.6" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" +checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" [[package]] name = "caps" -version = "0.3.4" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf6a638a1f7f409f1e545ff0036b8aa5541692c775dd36b48b75bbde50d83d1c" +checksum = "d092fbb6657fb1f98a7da70c14335ac97e5a9477e1a8156d4bbf19a3a7aece51" dependencies = [ "errno", - "error-chain", "libc", + "thiserror", ] [[package]] @@ -267,7 +267,7 @@ checksum = "8e93d7f5705de3e49895a2b5e0b8855a1c27f080192ae9c32a6432d50741a57a" dependencies = [ "libc", "redox_users", - "winapi 0.3.8", + "winapi", ] [[package]] @@ -284,7 +284,7 @@ checksum = "b480f641ccf0faf324e20c1d3e53d81b7484c698b42ea677f6907ae4db195371" dependencies = [ "errno-dragonfly", "libc", - "winapi 0.3.8", + "winapi", ] [[package]] @@ -297,15 +297,6 @@ dependencies = [ "libc", ] -[[package]] -name = "error-chain" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d371106cc88ffdfb1eabd7111e432da544f16f3e2d7bf1dfe8bf575f1df045cd" -dependencies = [ - "version_check", -] - [[package]] name = "failure" version = "0.1.8" @@ -321,28 +312,6 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86d4de0081402f5e88cdac65c8dcdcc73118c1a7a465e2a05f0da05843a8ea33" -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "fuchsia-zircon" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" -dependencies = [ - "bitflags", - "fuchsia-zircon-sys", -] - -[[package]] -name = "fuchsia-zircon-sys" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" - [[package]] name = "futures" version = "0.3.8" @@ -501,7 +470,7 @@ dependencies = [ "futures-core", "inotify-sys", "libc", - "tokio 1.0.1", + "tokio", ] [[package]] @@ -562,16 +531,6 @@ dependencies = [ "ttrpc", ] -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -626,25 +585,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "mio" -version = "0.6.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" -dependencies = [ - "cfg-if 0.1.10", - "fuchsia-zircon", - "fuchsia-zircon-sys", - "iovec", - "kernel32-sys", - "libc", - "log", - "miow 0.2.2", - "net2", - "slab", - "winapi 0.2.8", -] - [[package]] name = "mio" version = "0.7.7" @@ -653,44 +593,9 @@ checksum = "e50ae3f04d169fcc9bde0b547d1c205219b7157e07ded9c5aff03e0637cb3ed7" dependencies = [ "libc", "log", - "miow 0.3.6", + "miow", "ntapi", - "winapi 0.3.8", -] - -[[package]] -name = "mio-named-pipes" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0840c1c50fd55e521b247f949c241c9997709f23bd7f023b9762cd561e935656" -dependencies = [ - "log", - "mio 0.6.23", - "miow 0.3.6", - "winapi 0.3.8", -] - -[[package]] -name = "mio-uds" -version = "0.6.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0" -dependencies = [ - "iovec", - "libc", - "mio 0.6.23", -] - -[[package]] -name = "miow" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" -dependencies = [ - "kernel32-sys", - "net2", - "winapi 0.2.8", - "ws2_32-sys", + "winapi", ] [[package]] @@ -700,7 +605,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a33c1b55807fbed163481b5ba66db4b2fa6cde694a5027be10fb724206c5897" dependencies = [ "socket2", - "winapi 0.3.8", + "winapi", ] [[package]] @@ -709,17 +614,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2eb04b9f127583ed176e163fb9ec6f3e793b87e21deedd5734a69386a18a0151" -[[package]] -name = "net2" -version = "0.2.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "winapi 0.3.8", -] - [[package]] name = "nix" version = "0.16.1" @@ -758,6 +652,18 @@ dependencies = [ "libc", ] +[[package]] +name = "nix" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ccba0cfe4fdf15982d1674c69b1fd80bad427d293849982668dfe454bd61f2" +dependencies = [ + "bitflags", + "cc", + "cfg-if 1.0.0", + "libc", +] + [[package]] name = "nom" version = "2.2.1" @@ -770,7 +676,7 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a31937dea023539c72ddae0e3571deadc1414b300483fa7aaec176168cfa9d2" dependencies = [ - "winapi 0.3.8", + "winapi", ] [[package]] @@ -792,16 +698,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" -dependencies = [ - "hermit-abi", - "libc", -] - [[package]] name = "object" version = "0.21.1" @@ -872,12 +768,6 @@ dependencies = [ "syn 1.0.58", ] -[[package]] -name = "pin-project-lite" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c917123afa01924fc84bb20c4c03f004d9c38e5127e3c039bbf7f4b9c76a2f6b" - [[package]] name = "pin-project-lite" version = "0.2.1" @@ -1135,7 +1025,16 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" dependencies = [ - "winapi 0.3.8", + "winapi", +] + +[[package]] +name = "rlimit" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e7148757b4951f04391d2b301b2e3597d504c4d2434212d542b73c1a6b3f847" +dependencies = [ + "libc", ] [[package]] @@ -1178,7 +1077,6 @@ dependencies = [ "inotify", "lazy_static", "libc", - "mio 0.6.23", "nix 0.17.0", "oci", "path-absolutize", @@ -1186,6 +1084,7 @@ dependencies = [ "protobuf", "protocols", "regex", + "rlimit", "scan_fmt", "scopeguard", "serde", @@ -1194,7 +1093,7 @@ dependencies = [ "slog", "slog-scope", "tempfile", - "tokio 0.2.24", + "tokio", ] [[package]] @@ -1334,7 +1233,7 @@ checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" dependencies = [ "cfg-if 1.0.0", "libc", - "winapi 0.3.8", + "winapi", ] [[package]] @@ -1382,7 +1281,7 @@ dependencies = [ "rand", "redox_syscall", "remove_dir_all", - "winapi 0.3.8", + "winapi", ] [[package]] @@ -1430,49 +1329,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" dependencies = [ "libc", - "winapi 0.3.8", + "winapi", ] [[package]] name = "tokio" -version = "0.2.24" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099837d3464c16a808060bb3f02263b412f6fafcb5d01c533d309985fbeebe48" -dependencies = [ - "bytes 0.5.6", - "fnv", - "futures-core", - "lazy_static", - "libc", - "memchr", - "mio 0.6.23", - "mio-named-pipes", - "mio-uds", - "num_cpus", - "pin-project-lite 0.1.11", - "signal-hook-registry", - "slab", - "tokio-macros", - "winapi 0.3.8", -] - -[[package]] -name = "tokio" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d258221f566b6c803c7b4714abadc080172b272090cdc5e244a6d4dd13c3a6bd" +checksum = "e8190d04c665ea9e6b6a0dc45523ade572c088d2e6566244c1122671dbf4ae3a" dependencies = [ "autocfg", + "bytes 1.0.1", "libc", - "mio 0.7.7", - "pin-project-lite 0.2.1", + "memchr", + "mio", + "once_cell", + "pin-project-lite", + "signal-hook-registry", + "tokio-macros", + "winapi", ] [[package]] name = "tokio-macros" -version = "0.2.6" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e44da00bfc73a25f814cd8d7e57a68a5c31b74b3152a0a1d1f590c97ed06265a" +checksum = "caf7b11a536f46a809a8a9f0bb4237020f70ecbf115b842360afb127ea2fda57" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.7", @@ -1481,25 +1363,22 @@ dependencies = [ [[package]] name = "tokio-vsock" -version = "0.2.2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "547a35667d4d842422da7f5528612321770f2f640e7fd5df0431de7b717fb2b4" +checksum = "70c401a3d0e82328c6fa900e9e2c4152737a4caa304558b762f0154a8b306456" dependencies = [ "bytes 0.4.12", "futures", - "iovec", "libc", - "mio 0.6.23", - "nix 0.17.0", - "tokio 0.2.24", + "tokio", "vsock", ] [[package]] name = "ttrpc" -version = "0.4.14" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc512242eee1f113eadd48087dd97cbf807ccae4820006e7a890044044399c51" +checksum = "ff9ad10daac7027ac1e4c46326abc301349ab9b4006e931e9f7cb0feeb9a2096" dependencies = [ "async-trait", "byteorder", @@ -1510,15 +1389,15 @@ dependencies = [ "protobuf", "protobuf-codegen-pure", "thiserror", - "tokio 0.2.24", + "tokio", "tokio-vsock", ] [[package]] name = "ttrpc-codegen" -version = "0.1.2" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12e8844d7a8351fa833bea811f826401bec020b233e60a7c0a8f313f764ce5a5" +checksum = "809eda4e459820237104e4b61d6b41bbe6c9e1ce6adf4057955e6e6722a90408" dependencies = [ "protobuf", "protobuf-codegen", @@ -1528,9 +1407,9 @@ dependencies = [ [[package]] name = "ttrpc-compiler" -version = "0.3.2" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d290e64bdb994926d102f2983cc6550ece0778c8430253dc2de4e71cbf5285d9" +checksum = "8c2f2ce8c9a6e9422d0714bc8058b705d503fc9d028e69fae2236050c4721d75" dependencies = [ "derive-new", "prost", @@ -1571,12 +1450,6 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" -[[package]] -name = "version_check" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" - [[package]] name = "void" version = "1.0.2" @@ -1585,12 +1458,12 @@ checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" [[package]] name = "vsock" -version = "0.2.1" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dba063357047c0f2216c7c653879ea4e5e198d0c3cde7efa37ebfd9039b48491" +checksum = "50e2ef09834e1d203d24556512c0e58e66de203440bd9d74c30a33f7240091c6" dependencies = [ "libc", - "nix 0.17.0", + "nix 0.19.1", ] [[package]] @@ -1609,12 +1482,6 @@ dependencies = [ "libc", ] -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" - [[package]] name = "winapi" version = "0.3.8" @@ -1625,12 +1492,6 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -1642,13 +1503,3 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "ws2_32-sys" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] diff --git a/tools/agent-ctl/Cargo.toml b/tools/agent-ctl/Cargo.toml index 867063d980..693e3f4e3a 100644 --- a/tools/agent-ctl/Cargo.toml +++ b/tools/agent-ctl/Cargo.toml @@ -29,7 +29,7 @@ protobuf = "2.14.0" nix = "0.17.0" libc = "0.2.69" # XXX: Must be the same as the version used by the agent -ttrpc = { version = "0.4.14" } +ttrpc = { version = "0.5.0" } # For parsing timeouts humantime = "2.0.0" diff --git a/tools/agent-ctl/src/client.rs b/tools/agent-ctl/src/client.rs index ac38bcb381..3281d6d46f 100644 --- a/tools/agent-ctl/src/client.rs +++ b/tools/agent-ctl/src/client.rs @@ -22,6 +22,15 @@ use std::os::unix::net::UnixStream; use std::thread::sleep; use std::time::Duration; use ttrpc; +use ttrpc::context::Context; + +// Hack until the actual Context type supports this. +fn clone_context(ctx: &Context) -> Context { + Context { + metadata: ctx.metadata.clone(), + timeout_nano: ctx.timeout_nano, + } +} // Agent command handler type // @@ -35,6 +44,7 @@ type AgentCmdFp = fn( cfg: &Config, client: &AgentServiceClient, health: &HealthClient, + ctx: &Context, options: &mut Options, args: &str, ) -> Result<()>; @@ -521,6 +531,8 @@ pub fn client(cfg: &Config, commands: Vec<&str>) -> Result<()> { let mut options = Options::new(); + let ttrpc_ctx = ttrpc::context::with_timeout(cfg.timeout_nano); + // Special-case loading the OCI config file so it is accessible // to all commands. let oci_spec_json = utils::get_oci_spec_json(cfg)?; @@ -533,7 +545,7 @@ pub fn client(cfg: &Config, commands: Vec<&str>) -> Result<()> { "server-address" => cfg.server_address.to_string()); if cfg.interactive { - return interactive_client_loop(&cfg, &mut options, &client, &health); + return interactive_client_loop(&cfg, &mut options, &client, &health, &ttrpc_ctx); } let mut repeat_count = 1; @@ -544,8 +556,15 @@ pub fn client(cfg: &Config, commands: Vec<&str>) -> Result<()> { continue; } - let (result, shutdown) = - handle_cmd(&cfg, &client, &health, repeat_count, &mut options, &cmd); + let (result, shutdown) = handle_cmd( + &cfg, + &client, + &health, + &ttrpc_ctx, + repeat_count, + &mut options, + &cmd, + ); if result.is_err() { return result; } @@ -566,6 +585,7 @@ fn handle_cmd( cfg: &Config, client: &AgentServiceClient, health: &HealthClient, + ctx: &Context, repeat_count: i64, options: &mut Options, cmdline: &str, @@ -611,7 +631,7 @@ fn handle_cmd( if first.is_lowercase() { result = handle_builtin_cmd(cfg, options, cmd, &args); } else { - result = handle_agent_cmd(cfg, client, health, options, cmd, &args); + result = handle_agent_cmd(cfg, client, health, ctx, options, cmd, &args); } if result.0.is_err() { @@ -665,6 +685,7 @@ fn handle_agent_cmd( cfg: &Config, client: &AgentServiceClient, health: &HealthClient, + ctx: &Context, options: &mut Options, cmd: &str, args: &str, @@ -674,7 +695,8 @@ fn handle_agent_cmd( Err(e) => return (Err(e), false), }; - let result = f(cfg, client, health, options, &args); + // BUG: FIXME: clone ctx here? + let result = f(cfg, client, health, ctx, options, &args); if result.is_err() { return (result, false); } @@ -689,6 +711,7 @@ fn interactive_client_loop( options: &mut Options, client: &AgentServiceClient, health: &HealthClient, + ctx: &Context, ) -> Result<()> { let result = builtin_cmd_list(cfg, options, ""); if result.0.is_err() { @@ -710,7 +733,8 @@ fn interactive_client_loop( continue; } - let (result, shutdown) = handle_cmd(cfg, client, health, repeat_count, options, &cmdline); + let (result, shutdown) = + handle_cmd(cfg, client, health, ctx, repeat_count, options, &cmdline); if result.is_err() { return result; } @@ -744,21 +768,24 @@ fn readline(prompt: &str) -> std::result::Result { } fn agent_cmd_health_check( - cfg: &Config, + _cfg: &Config, _client: &AgentServiceClient, health: &HealthClient, + ctx: &Context, _options: &mut Options, _args: &str, ) -> Result<()> { let mut req = CheckRequest::default(); + let ctx = clone_context(ctx); + // value unused req.set_service("".to_string()); debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = health - .check(&req, cfg.timeout_nano) + .check(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -768,22 +795,25 @@ fn agent_cmd_health_check( } fn agent_cmd_health_version( - cfg: &Config, + _cfg: &Config, _client: &AgentServiceClient, health: &HealthClient, + ctx: &Context, _options: &mut Options, _args: &str, ) -> Result<()> { // XXX: Yes, the API is actually broken! let mut req = CheckRequest::default(); + let ctx = clone_context(ctx); + // value unused req.set_service("".to_string()); debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = health - .version(&req, cfg.timeout_nano) + .version(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -793,21 +823,24 @@ fn agent_cmd_health_version( } fn agent_cmd_sandbox_create( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { let mut req = CreateSandboxRequest::default(); + let ctx = clone_context(ctx); + let sid = utils::get_option("sid", options, args); req.set_sandbox_id(sid); debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .create_sandbox(&req, cfg.timeout_nano) + .create_sandbox(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -817,18 +850,21 @@ fn agent_cmd_sandbox_create( } fn agent_cmd_sandbox_destroy( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, _options: &mut Options, _args: &str, ) -> Result<()> { let req = DestroySandboxRequest::default(); + let ctx = clone_context(ctx); + debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .destroy_sandbox(&req, cfg.timeout_nano) + .destroy_sandbox(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -838,14 +874,17 @@ fn agent_cmd_sandbox_destroy( } fn agent_cmd_container_create( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { let mut req = CreateContainerRequest::default(); + let ctx = clone_context(ctx); + let cid = utils::get_option("cid", options, args); let exec_id = utils::get_option("exec_id", options, args); @@ -860,7 +899,7 @@ fn agent_cmd_container_create( debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .create_container(&req, cfg.timeout_nano) + .create_container(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -870,9 +909,10 @@ fn agent_cmd_container_create( } fn agent_cmd_container_remove( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { @@ -880,12 +920,14 @@ fn agent_cmd_container_remove( let cid = utils::get_option("cid", options, args); + let ctx = clone_context(ctx); + req.set_container_id(cid); debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .remove_container(&req, cfg.timeout_nano) + .remove_container(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -898,11 +940,14 @@ fn agent_cmd_container_exec( cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { let mut req = ExecProcessRequest::default(); + let ctx = clone_context(ctx); + let cid = utils::get_option("cid", options, args); let exec_id = utils::get_option("exec_id", options, args); @@ -924,7 +969,7 @@ fn agent_cmd_container_exec( debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .exec_process(&req, cfg.timeout_nano) + .exec_process(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -934,14 +979,17 @@ fn agent_cmd_container_exec( } fn agent_cmd_container_stats( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { let mut req = StatsContainerRequest::default(); + let ctx = clone_context(ctx); + let cid = utils::get_option("cid", options, args); req.set_container_id(cid); @@ -949,7 +997,7 @@ fn agent_cmd_container_stats( debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .stats_container(&req, cfg.timeout_nano) + .stats_container(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -959,14 +1007,17 @@ fn agent_cmd_container_stats( } fn agent_cmd_container_pause( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { let mut req = PauseContainerRequest::default(); + let ctx = clone_context(ctx); + let cid = utils::get_option("cid", options, args); req.set_container_id(cid); @@ -974,7 +1025,7 @@ fn agent_cmd_container_pause( debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .pause_container(&req, cfg.timeout_nano) + .pause_container(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -984,9 +1035,10 @@ fn agent_cmd_container_pause( } fn agent_cmd_container_resume( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { @@ -994,12 +1046,14 @@ fn agent_cmd_container_resume( let cid = utils::get_option("cid", options, args); + let ctx = clone_context(ctx); + req.set_container_id(cid); debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .resume_container(&req, cfg.timeout_nano) + .resume_container(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -1009,14 +1063,17 @@ fn agent_cmd_container_resume( } fn agent_cmd_container_start( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { let mut req = StartContainerRequest::default(); + let ctx = clone_context(ctx); + let cid = utils::get_option("cid", options, args); req.set_container_id(cid); @@ -1024,7 +1081,7 @@ fn agent_cmd_container_start( debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .start_container(&req, cfg.timeout_nano) + .start_container(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -1034,20 +1091,23 @@ fn agent_cmd_container_start( } fn agent_cmd_sandbox_get_guest_details( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, _options: &mut Options, _args: &str, ) -> Result<()> { let mut req = GuestDetailsRequest::default(); + let ctx = clone_context(ctx); + req.set_mem_block_size(true); debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .get_guest_details(&req, cfg.timeout_nano) + .get_guest_details(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -1057,14 +1117,17 @@ fn agent_cmd_sandbox_get_guest_details( } fn agent_cmd_container_list_processes( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { let mut req = ListProcessesRequest::default(); + let ctx = clone_context(ctx); + let cid = utils::get_option("cid", options, args); let mut list_format = utils::get_option("format", options, args); @@ -1079,7 +1142,7 @@ fn agent_cmd_container_list_processes( debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .list_processes(&req, cfg.timeout_nano) + .list_processes(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -1089,14 +1152,17 @@ fn agent_cmd_container_list_processes( } fn agent_cmd_container_wait_process( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { let mut req = WaitProcessRequest::default(); + let ctx = clone_context(ctx); + let cid = utils::get_option("cid", options, args); let exec_id = utils::get_option("exec_id", options, args); @@ -1106,7 +1172,7 @@ fn agent_cmd_container_wait_process( debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .wait_process(&req, cfg.timeout_nano) + .wait_process(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -1116,14 +1182,17 @@ fn agent_cmd_container_wait_process( } fn agent_cmd_container_signal_process( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { let mut req = SignalProcessRequest::default(); + let ctx = clone_context(ctx); + let cid = utils::get_option("cid", options, args); let exec_id = utils::get_option("exec_id", options, args); @@ -1143,7 +1212,7 @@ fn agent_cmd_container_signal_process( debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .signal_process(&req, cfg.timeout_nano) + .signal_process(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -1153,18 +1222,21 @@ fn agent_cmd_container_signal_process( } fn agent_cmd_sandbox_tracing_start( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, _options: &mut Options, _args: &str, ) -> Result<()> { let req = StartTracingRequest::default(); + let ctx = clone_context(ctx); + debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .start_tracing(&req, cfg.timeout_nano) + .start_tracing(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -1174,18 +1246,21 @@ fn agent_cmd_sandbox_tracing_start( } fn agent_cmd_sandbox_tracing_stop( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, _options: &mut Options, _args: &str, ) -> Result<()> { let req = StopTracingRequest::default(); + let ctx = clone_context(ctx); + debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .stop_tracing(&req, cfg.timeout_nano) + .stop_tracing(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -1195,17 +1270,20 @@ fn agent_cmd_sandbox_tracing_stop( } fn agent_cmd_sandbox_update_interface( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, _options: &mut Options, _args: &str, ) -> Result<()> { let req = UpdateInterfaceRequest::default(); + let ctx = clone_context(ctx); + debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .update_interface(&req, cfg.timeout_nano) + .update_interface(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; // FIXME: Implement 'UpdateInterface' fully. @@ -1218,18 +1296,21 @@ fn agent_cmd_sandbox_update_interface( } fn agent_cmd_sandbox_update_routes( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, _options: &mut Options, _args: &str, ) -> Result<()> { let req = UpdateRoutesRequest::default(); + let ctx = clone_context(ctx); + debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .update_routes(&req, cfg.timeout_nano) + .update_routes(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; // FIXME: Implement 'UpdateRoutes' fully. @@ -1242,18 +1323,21 @@ fn agent_cmd_sandbox_update_routes( } fn agent_cmd_sandbox_list_interfaces( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, _options: &mut Options, _args: &str, ) -> Result<()> { let req = ListInterfacesRequest::default(); + let ctx = clone_context(ctx); + debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .list_interfaces(&req, cfg.timeout_nano) + .list_interfaces(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -1263,18 +1347,21 @@ fn agent_cmd_sandbox_list_interfaces( } fn agent_cmd_sandbox_list_routes( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, _options: &mut Options, _args: &str, ) -> Result<()> { let req = ListRoutesRequest::default(); + let ctx = clone_context(ctx); + debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .list_routes(&req, cfg.timeout_nano) + .list_routes(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -1284,14 +1371,17 @@ fn agent_cmd_sandbox_list_routes( } fn agent_cmd_container_tty_win_resize( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { let mut req = TtyWinResizeRequest::default(); + let ctx = clone_context(ctx); + let cid = utils::get_option("cid", options, args); let exec_id = utils::get_option("exec_id", options, args); @@ -1320,7 +1410,7 @@ fn agent_cmd_container_tty_win_resize( debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .tty_win_resize(&req, cfg.timeout_nano) + .tty_win_resize(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -1330,14 +1420,17 @@ fn agent_cmd_container_tty_win_resize( } fn agent_cmd_container_close_stdin( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { let mut req = CloseStdinRequest::default(); + let ctx = clone_context(ctx); + let cid = utils::get_option("cid", options, args); let exec_id = utils::get_option("exec_id", options, args); @@ -1347,7 +1440,7 @@ fn agent_cmd_container_close_stdin( debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .close_stdin(&req, cfg.timeout_nano) + .close_stdin(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -1357,14 +1450,17 @@ fn agent_cmd_container_close_stdin( } fn agent_cmd_container_read_stdout( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { let mut req = ReadStreamRequest::default(); + let ctx = clone_context(ctx); + let cid = utils::get_option("cid", options, args); let exec_id = utils::get_option("exec_id", options, args); @@ -1383,7 +1479,7 @@ fn agent_cmd_container_read_stdout( debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .read_stdout(&req, cfg.timeout_nano) + .read_stdout(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -1393,14 +1489,17 @@ fn agent_cmd_container_read_stdout( } fn agent_cmd_container_read_stderr( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { let mut req = ReadStreamRequest::default(); + let ctx = clone_context(ctx); + let cid = utils::get_option("cid", options, args); let exec_id = utils::get_option("exec_id", options, args); @@ -1419,7 +1518,7 @@ fn agent_cmd_container_read_stderr( debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .read_stderr(&req, cfg.timeout_nano) + .read_stderr(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -1429,14 +1528,17 @@ fn agent_cmd_container_read_stderr( } fn agent_cmd_container_write_stdin( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { let mut req = WriteStreamRequest::default(); + let ctx = clone_context(ctx); + let cid = utils::get_option("cid", options, args); let exec_id = utils::get_option("exec_id", options, args); @@ -1450,7 +1552,7 @@ fn agent_cmd_container_write_stdin( debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .write_stdin(&req, cfg.timeout_nano) + .write_stdin(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -1460,18 +1562,21 @@ fn agent_cmd_container_write_stdin( } fn agent_cmd_sandbox_get_metrics( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, _options: &mut Options, _args: &str, ) -> Result<()> { let req = GetMetricsRequest::default(); + let ctx = clone_context(ctx); + debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .get_metrics(&req, cfg.timeout_nano) + .get_metrics(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -1481,18 +1586,21 @@ fn agent_cmd_sandbox_get_metrics( } fn agent_cmd_sandbox_get_oom_event( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, _options: &mut Options, _args: &str, ) -> Result<()> { let req = GetOOMEventRequest::default(); + let ctx = clone_context(ctx); + debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .get_oom_event(&req, cfg.timeout_nano) + .get_oom_event(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -1502,14 +1610,17 @@ fn agent_cmd_sandbox_get_oom_event( } fn agent_cmd_sandbox_copy_file( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { let mut req = CopyFileRequest::default(); + let ctx = clone_context(ctx); + let path = utils::get_option("path", options, args); if path != "" { req.set_path(path); @@ -1582,7 +1693,7 @@ fn agent_cmd_sandbox_copy_file( debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .copy_file(&req, cfg.timeout_nano) + .copy_file(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -1592,14 +1703,17 @@ fn agent_cmd_sandbox_copy_file( } fn agent_cmd_sandbox_reseed_random_dev( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { let mut req = ReseedRandomDevRequest::default(); + let ctx = clone_context(ctx); + let str_data = utils::get_option("data", options, args); let data = utils::str_to_bytes(&str_data)?; @@ -1608,7 +1722,7 @@ fn agent_cmd_sandbox_reseed_random_dev( debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .reseed_random_dev(&req, cfg.timeout_nano) + .reseed_random_dev(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -1618,14 +1732,17 @@ fn agent_cmd_sandbox_reseed_random_dev( } fn agent_cmd_sandbox_online_cpu_mem( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { let mut req = OnlineCPUMemRequest::default(); + let ctx = clone_context(ctx); + let wait_str = utils::get_option("wait", options, args); if wait_str != "" { @@ -1659,7 +1776,7 @@ fn agent_cmd_sandbox_online_cpu_mem( debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .online_cpu_mem(&req, cfg.timeout_nano) + .online_cpu_mem(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -1669,14 +1786,17 @@ fn agent_cmd_sandbox_online_cpu_mem( } fn agent_cmd_sandbox_set_guest_date_time( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { let mut req = SetGuestDateTimeRequest::default(); + let ctx = clone_context(ctx); + let secs_str = utils::get_option("sec", options, args); if secs_str != "" { @@ -1700,7 +1820,7 @@ fn agent_cmd_sandbox_set_guest_date_time( debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .set_guest_date_time(&req, cfg.timeout_nano) + .set_guest_date_time(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -1710,21 +1830,24 @@ fn agent_cmd_sandbox_set_guest_date_time( } fn agent_cmd_sandbox_add_arp_neighbors( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, _options: &mut Options, _args: &str, ) -> Result<()> { let req = AddARPNeighborsRequest::default(); + let ctx = clone_context(ctx); + // FIXME: Implement fully. eprintln!("FIXME: 'AddARPNeighbors' not fully implemented"); debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .add_arp_neighbors(&req, cfg.timeout_nano) + .add_arp_neighbors(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -1734,14 +1857,17 @@ fn agent_cmd_sandbox_add_arp_neighbors( } fn agent_cmd_sandbox_update_container( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { let mut req = UpdateContainerRequest::default(); + let ctx = clone_context(ctx); + let cid = utils::get_option("cid", options, args); req.set_container_id(cid); @@ -1752,7 +1878,7 @@ fn agent_cmd_sandbox_update_container( debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .update_container(&req, cfg.timeout_nano) + .update_container(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; @@ -1762,14 +1888,17 @@ fn agent_cmd_sandbox_update_container( } fn agent_cmd_sandbox_mem_hotplug_by_probe( - cfg: &Config, + _cfg: &Config, client: &AgentServiceClient, _health: &HealthClient, + ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { let mut req = MemHotplugByProbeRequest::default(); + let ctx = clone_context(ctx); + // Expected to be a comma separated list of hex addresses let addr_list = utils::get_option("memHotplugProbeAddr", options, args); @@ -1796,7 +1925,7 @@ fn agent_cmd_sandbox_mem_hotplug_by_probe( debug!(sl!(), "sending request"; "request" => format!("{:?}", req)); let reply = client - .mem_hotplug_by_probe(&req, cfg.timeout_nano) + .mem_hotplug_by_probe(ctx, &req) .map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?; info!(sl!(), "response received"; From c258ea25d447c954ab5b3c776521ede9946356a9 Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Fri, 5 Mar 2021 09:50:21 +0000 Subject: [PATCH 3/3] agent-ctl: Function parameter cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove unused function parameters from the following types: - `AgentCmdFp`: Removed the config parameter and made the context parameter the first (à la golang). - `BuiltinCmdFp`: Removed the config and options parameters. Signed-off-by: James O. D. Hunt --- tools/agent-ctl/src/client.rs | 148 +++++++++++++--------------------- 1 file changed, 55 insertions(+), 93 deletions(-) diff --git a/tools/agent-ctl/src/client.rs b/tools/agent-ctl/src/client.rs index 3281d6d46f..26f8e2934f 100644 --- a/tools/agent-ctl/src/client.rs +++ b/tools/agent-ctl/src/client.rs @@ -41,16 +41,15 @@ fn clone_context(ctx: &Context) -> Context { // - 'options' can be read and written to, allowing commands to pass state to // each other via well-known option names. type AgentCmdFp = fn( - cfg: &Config, + ctx: &Context, client: &AgentServiceClient, health: &HealthClient, - ctx: &Context, options: &mut Options, args: &str, ) -> Result<()>; // Builtin command handler type -type BuiltinCmdFp = fn(cfg: &Config, options: &mut Options, args: &str) -> (Result<()>, bool); +type BuiltinCmdFp = fn(args: &str) -> (Result<()>, bool); enum ServiceType { Agent, @@ -629,9 +628,9 @@ fn handle_cmd( info!(sl!(), "Run command {:} ({})", cmd, count_msg); if first.is_lowercase() { - result = handle_builtin_cmd(cfg, options, cmd, &args); + result = handle_builtin_cmd(cmd, &args); } else { - result = handle_agent_cmd(cfg, client, health, ctx, options, cmd, &args); + result = handle_agent_cmd(ctx, client, health, options, cmd, &args); } if result.0.is_err() { @@ -665,27 +664,21 @@ fn handle_cmd( } } -fn handle_builtin_cmd( - cfg: &Config, - options: &mut Options, - cmd: &str, - args: &str, -) -> (Result<()>, bool) { +fn handle_builtin_cmd(cmd: &str, args: &str) -> (Result<()>, bool) { let f = match get_builtin_cmd_func(&cmd) { Ok(fp) => fp, Err(e) => return (Err(e), false), }; - f(cfg, options, &args) + f(&args) } // Execute the ttRPC specified by the first field of "line". Return a result // along with a bool which if set means the client should shutdown. fn handle_agent_cmd( - cfg: &Config, + ctx: &Context, client: &AgentServiceClient, health: &HealthClient, - ctx: &Context, options: &mut Options, cmd: &str, args: &str, @@ -695,8 +688,7 @@ fn handle_agent_cmd( Err(e) => return (Err(e), false), }; - // BUG: FIXME: clone ctx here? - let result = f(cfg, client, health, ctx, options, &args); + let result = f(ctx, client, health, options, &args); if result.is_err() { return (result, false); } @@ -713,7 +705,7 @@ fn interactive_client_loop( health: &HealthClient, ctx: &Context, ) -> Result<()> { - let result = builtin_cmd_list(cfg, options, ""); + let result = builtin_cmd_list(""); if result.0.is_err() { return result.0; } @@ -768,10 +760,9 @@ fn readline(prompt: &str) -> std::result::Result { } fn agent_cmd_health_check( - _cfg: &Config, + ctx: &Context, _client: &AgentServiceClient, health: &HealthClient, - ctx: &Context, _options: &mut Options, _args: &str, ) -> Result<()> { @@ -795,10 +786,9 @@ fn agent_cmd_health_check( } fn agent_cmd_health_version( - _cfg: &Config, + ctx: &Context, _client: &AgentServiceClient, health: &HealthClient, - ctx: &Context, _options: &mut Options, _args: &str, ) -> Result<()> { @@ -823,10 +813,9 @@ fn agent_cmd_health_version( } fn agent_cmd_sandbox_create( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { @@ -850,10 +839,9 @@ fn agent_cmd_sandbox_create( } fn agent_cmd_sandbox_destroy( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, _options: &mut Options, _args: &str, ) -> Result<()> { @@ -874,10 +862,9 @@ fn agent_cmd_sandbox_destroy( } fn agent_cmd_container_create( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { @@ -909,10 +896,9 @@ fn agent_cmd_container_create( } fn agent_cmd_container_remove( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { @@ -937,10 +923,9 @@ fn agent_cmd_container_remove( } fn agent_cmd_container_exec( - cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { @@ -953,12 +938,17 @@ fn agent_cmd_container_exec( let grpc_spec = utils::get_grpc_spec(options, &cid).map_err(|e| anyhow!(e))?; + let bundle_dir = options + .get("bundle-dir") + .ok_or("BUG: bundle-dir missing") + .map_err(|e| anyhow!(e))?; + let process = grpc_spec .Process .into_option() .ok_or(format!( "failed to get process from OCI spec: {}", - cfg.bundle_dir + bundle_dir, )) .map_err(|e| anyhow!(e))?; @@ -979,10 +969,9 @@ fn agent_cmd_container_exec( } fn agent_cmd_container_stats( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { @@ -1007,10 +996,9 @@ fn agent_cmd_container_stats( } fn agent_cmd_container_pause( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { @@ -1035,10 +1023,9 @@ fn agent_cmd_container_pause( } fn agent_cmd_container_resume( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { @@ -1063,10 +1050,9 @@ fn agent_cmd_container_resume( } fn agent_cmd_container_start( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { @@ -1091,10 +1077,9 @@ fn agent_cmd_container_start( } fn agent_cmd_sandbox_get_guest_details( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, _options: &mut Options, _args: &str, ) -> Result<()> { @@ -1117,10 +1102,9 @@ fn agent_cmd_sandbox_get_guest_details( } fn agent_cmd_container_list_processes( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { @@ -1152,10 +1136,9 @@ fn agent_cmd_container_list_processes( } fn agent_cmd_container_wait_process( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { @@ -1182,10 +1165,9 @@ fn agent_cmd_container_wait_process( } fn agent_cmd_container_signal_process( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { @@ -1222,10 +1204,9 @@ fn agent_cmd_container_signal_process( } fn agent_cmd_sandbox_tracing_start( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, _options: &mut Options, _args: &str, ) -> Result<()> { @@ -1246,10 +1227,9 @@ fn agent_cmd_sandbox_tracing_start( } fn agent_cmd_sandbox_tracing_stop( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, _options: &mut Options, _args: &str, ) -> Result<()> { @@ -1270,10 +1250,9 @@ fn agent_cmd_sandbox_tracing_stop( } fn agent_cmd_sandbox_update_interface( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, _options: &mut Options, _args: &str, ) -> Result<()> { @@ -1296,10 +1275,9 @@ fn agent_cmd_sandbox_update_interface( } fn agent_cmd_sandbox_update_routes( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, _options: &mut Options, _args: &str, ) -> Result<()> { @@ -1323,10 +1301,9 @@ fn agent_cmd_sandbox_update_routes( } fn agent_cmd_sandbox_list_interfaces( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, _options: &mut Options, _args: &str, ) -> Result<()> { @@ -1347,10 +1324,9 @@ fn agent_cmd_sandbox_list_interfaces( } fn agent_cmd_sandbox_list_routes( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, _options: &mut Options, _args: &str, ) -> Result<()> { @@ -1371,10 +1347,9 @@ fn agent_cmd_sandbox_list_routes( } fn agent_cmd_container_tty_win_resize( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { @@ -1420,10 +1395,9 @@ fn agent_cmd_container_tty_win_resize( } fn agent_cmd_container_close_stdin( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { @@ -1450,10 +1424,9 @@ fn agent_cmd_container_close_stdin( } fn agent_cmd_container_read_stdout( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { @@ -1489,10 +1462,9 @@ fn agent_cmd_container_read_stdout( } fn agent_cmd_container_read_stderr( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { @@ -1528,10 +1500,9 @@ fn agent_cmd_container_read_stderr( } fn agent_cmd_container_write_stdin( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { @@ -1562,10 +1533,9 @@ fn agent_cmd_container_write_stdin( } fn agent_cmd_sandbox_get_metrics( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, _options: &mut Options, _args: &str, ) -> Result<()> { @@ -1586,10 +1556,9 @@ fn agent_cmd_sandbox_get_metrics( } fn agent_cmd_sandbox_get_oom_event( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, _options: &mut Options, _args: &str, ) -> Result<()> { @@ -1610,10 +1579,9 @@ fn agent_cmd_sandbox_get_oom_event( } fn agent_cmd_sandbox_copy_file( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { @@ -1703,10 +1671,9 @@ fn agent_cmd_sandbox_copy_file( } fn agent_cmd_sandbox_reseed_random_dev( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { @@ -1732,10 +1699,9 @@ fn agent_cmd_sandbox_reseed_random_dev( } fn agent_cmd_sandbox_online_cpu_mem( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { @@ -1786,10 +1752,9 @@ fn agent_cmd_sandbox_online_cpu_mem( } fn agent_cmd_sandbox_set_guest_date_time( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { @@ -1830,10 +1795,9 @@ fn agent_cmd_sandbox_set_guest_date_time( } fn agent_cmd_sandbox_add_arp_neighbors( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, _options: &mut Options, _args: &str, ) -> Result<()> { @@ -1857,10 +1821,9 @@ fn agent_cmd_sandbox_add_arp_neighbors( } fn agent_cmd_sandbox_update_container( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { @@ -1888,10 +1851,9 @@ fn agent_cmd_sandbox_update_container( } fn agent_cmd_sandbox_mem_hotplug_by_probe( - _cfg: &Config, + ctx: &Context, client: &AgentServiceClient, _health: &HealthClient, - ctx: &Context, options: &mut Options, args: &str, ) -> Result<()> { @@ -1935,7 +1897,7 @@ fn agent_cmd_sandbox_mem_hotplug_by_probe( } #[inline] -fn builtin_cmd_repeat(_cfg: &Config, _options: &mut Options, _args: &str) -> (Result<()>, bool) { +fn builtin_cmd_repeat(_args: &str) -> (Result<()>, bool) { // XXX: NOP implementation. Due to the way repeat has to work, providing a // handler like this is "too late" to be useful. However, a handler // is required as "repeat" is a valid command. @@ -1947,7 +1909,7 @@ fn builtin_cmd_repeat(_cfg: &Config, _options: &mut Options, _args: &str) -> (Re (Ok(()), false) } -fn builtin_cmd_sleep(_cfg: &Config, _options: &mut Options, args: &str) -> (Result<()>, bool) { +fn builtin_cmd_sleep(args: &str) -> (Result<()>, bool) { let ns = match utils::human_time_to_ns(args) { Ok(t) => t, Err(e) => return (Err(e), false), @@ -1958,17 +1920,17 @@ fn builtin_cmd_sleep(_cfg: &Config, _options: &mut Options, args: &str) -> (Resu (Ok(()), false) } -fn builtin_cmd_echo(_cfg: &Config, _options: &mut Options, args: &str) -> (Result<()>, bool) { +fn builtin_cmd_echo(args: &str) -> (Result<()>, bool) { println!("{}", args); (Ok(()), false) } -fn builtin_cmd_quit(_cfg: &Config, _options: &mut Options, _args: &str) -> (Result<()>, bool) { +fn builtin_cmd_quit(_args: &str) -> (Result<()>, bool) { (Ok(()), true) } -fn builtin_cmd_list(_cfg: &Config, _options: &mut Options, _args: &str) -> (Result<()>, bool) { +fn builtin_cmd_list(_args: &str) -> (Result<()>, bool) { let cmds = get_all_cmd_details(); cmds.iter().for_each(|n| println!(" - {}", n));