From 002b18054d82e594a50c2bb0c0fd6fd837c370dd Mon Sep 17 00:00:00 2001 From: Chelsea Mafrica Date: Wed, 13 Jul 2022 00:52:36 -0700 Subject: [PATCH] kata-ctl: Add initial rust code for kata-ctl Use agent-ctl tool rust code as an example for a skeleton for the new kata-ctl tool. Signed-off-by: Chelsea Mafrica --- src/tools/kata-ctl/.gitignore | 1 + src/tools/kata-ctl/Cargo.lock | 122 ++++++++++++++++++++++++++++++ src/tools/kata-ctl/Cargo.toml | 14 ++++ src/tools/kata-ctl/Makefile | 33 ++++++++ src/tools/kata-ctl/README.md | 15 ++++ src/tools/kata-ctl/src/main.rs | 129 ++++++++++++++++++++++++++++++++ src/tools/kata-ctl/src/utils.rs | 8 ++ 7 files changed, 322 insertions(+) create mode 100644 src/tools/kata-ctl/.gitignore create mode 100644 src/tools/kata-ctl/Cargo.lock create mode 100644 src/tools/kata-ctl/Cargo.toml create mode 100644 src/tools/kata-ctl/Makefile create mode 100644 src/tools/kata-ctl/README.md create mode 100644 src/tools/kata-ctl/src/main.rs create mode 100644 src/tools/kata-ctl/src/utils.rs diff --git a/src/tools/kata-ctl/.gitignore b/src/tools/kata-ctl/.gitignore new file mode 100644 index 000000000..57872d0f1 --- /dev/null +++ b/src/tools/kata-ctl/.gitignore @@ -0,0 +1 @@ +/vendor/ diff --git a/src/tools/kata-ctl/Cargo.lock b/src/tools/kata-ctl/Cargo.lock new file mode 100644 index 000000000..84da4ddc6 --- /dev/null +++ b/src/tools/kata-ctl/Cargo.lock @@ -0,0 +1,122 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + +[[package]] +name = "anyhow" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb07d2053ccdbe10e2af2995a2f116c1330396493dc1269f6a91d0ae82e19704" + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "clap" +version = "2.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +dependencies = [ + "ansi_term", + "atty", + "bitflags", + "strsim", + "textwrap", + "unicode-width", + "vec_map", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "kata-ctl" +version = "0.0.0" +dependencies = [ + "anyhow", + "clap", +] + +[[package]] +name = "libc" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" + +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "unicode-width" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" + +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/src/tools/kata-ctl/Cargo.toml b/src/tools/kata-ctl/Cargo.toml new file mode 100644 index 000000000..c3ec304ac --- /dev/null +++ b/src/tools/kata-ctl/Cargo.toml @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 +# + +[package] +name = "kata-ctl" +version = "0.0.0" +authors = ["The Kata Containers community "] +edition = "2021" + +[dependencies] +clap = "2.33.0" +anyhow = "1.0.31" diff --git a/src/tools/kata-ctl/Makefile b/src/tools/kata-ctl/Makefile new file mode 100644 index 000000000..c050d6d47 --- /dev/null +++ b/src/tools/kata-ctl/Makefile @@ -0,0 +1,33 @@ +# Copyright (c) 2022 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 +# + +include ../../../utils.mk + +.DEFAULT_GOAL := default +default: build + +build: + @RUSTFLAGS="$(EXTRA_RUSTFLAGS) --deny warnings" cargo build --target $(TRIPLE) --$(BUILD_TYPE) + +clean: + cargo clean + +vendor: + cargo vendor + +test: + +install: + @RUSTFLAGS="$(EXTRA_RUSTFLAGS) --deny warnings" cargo install --target $(TRIPLE) --path . + +check: standard_rust_check + +.PHONY: \ + build \ + check \ + clean \ + install \ + test \ + vendor diff --git a/src/tools/kata-ctl/README.md b/src/tools/kata-ctl/README.md new file mode 100644 index 000000000..1e441d58b --- /dev/null +++ b/src/tools/kata-ctl/README.md @@ -0,0 +1,15 @@ +# Kata Containers control tool + +## Overview + +## Audience and environment + +## History + +## Full details + +## Code summary + +## Run the tool + +### Prerequisites diff --git a/src/tools/kata-ctl/src/main.rs b/src/tools/kata-ctl/src/main.rs new file mode 100644 index 000000000..9b3c0bf2e --- /dev/null +++ b/src/tools/kata-ctl/src/main.rs @@ -0,0 +1,129 @@ +// Copyright (c) 2022 Intel Corporation +// +// SPDX-License-Identifier: Apache-2.0 +// + +use anyhow::{anyhow, Result}; +use clap::{crate_name, crate_version, App, Arg, SubCommand}; +use std::process::exit; + +mod utils; + +const DESCRIPTION_TEXT: &str = r#"DESCRIPTION: + kata-ctl description placeholder."#; + +const ABOUT_TEXT: &str = "Kata Containers control tool"; + +fn real_main() -> Result<()> { + let name = crate_name!(); + + let app = App::new(name) + .version(crate_version!()) + .about(ABOUT_TEXT) + .long_about(DESCRIPTION_TEXT) + .subcommand( + SubCommand::with_name("check") + .about("tests if system can run Kata Containers") + ) + .subcommand( + SubCommand::with_name("command-example") + .about("(remove when other subcommands have sufficient detail)") + .arg( + Arg::with_name("arg-example-1") + .long("arg-example-1") + .help("arg example for command-example") + .takes_value(true) + ) + ) + .subcommand( + SubCommand::with_name("direct-volume") + .about("directly assign a volume to Kata Containers to manage") + ) + .subcommand( + SubCommand::with_name("env") + .about("display settings. Default to TOML") + ) + .subcommand( + SubCommand::with_name("exec") + .about("enter into guest by debug console") + ) + .subcommand( + SubCommand::with_name("factory") + .about("manage vm factory") + ) + .subcommand( + SubCommand::with_name("help") + .about("shows a list of commands or help for one command") + ) + .subcommand( + SubCommand::with_name("iptables") + .about("") + ) + .subcommand( + SubCommand::with_name("metrics") + .about("gather metrics associated with infrastructure used to run a sandbox") + ) + .subcommand( + SubCommand::with_name("version") + .about("display version details") + + ); + + let args = app.get_matches(); + + let subcmd = args + .subcommand_name() + .ok_or_else(|| anyhow!("need sub-command"))?; + + match subcmd { + "command-example" => { + println!("{}", utils::command_example(args)); + Ok(()) + } + "check" => { + println!("Not implemented"); + Ok(()) + } + "direct-volume" => { + println!("Not implemented"); + Ok(()) + } + "env" => { + println!("Not implemented"); + Ok(()) + } + "exec" => { + println!("Not implemented"); + Ok(()) + } + "factory" => { + println!("Not implemented"); + Ok(()) + } + "help" => { + println!("Not implemented"); + Ok(()) + } + "iptables" => { + println!("Not implemented"); + Ok(()) + } + "metrics" => { + println!("Not implemented"); + Ok(()) + } + "version" => { + println!("Not implemented"); + Ok(()) + } + _ => return Err(anyhow!(format!("invalid sub-command: {:?}", subcmd))), + } + +} + +fn main() { + if let Err(e) = real_main() { + eprintln!("ERROR: {:#?}", e); + exit(1); + } +} diff --git a/src/tools/kata-ctl/src/utils.rs b/src/tools/kata-ctl/src/utils.rs new file mode 100644 index 000000000..b779c2147 --- /dev/null +++ b/src/tools/kata-ctl/src/utils.rs @@ -0,0 +1,8 @@ +// Copyright (c) 2022 Intel Corporation +// +// SPDX-License-Identifier: Apache-2.0 +// + +pub fn command_example(_global_args: clap::ArgMatches) -> String { + "test utils command".to_string() +}