mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-31 16:36:38 +00:00
Merge pull request #6660 from amshinde/kata-ctl-cmd
Implement the "kata-ctl env" command
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -6,6 +6,8 @@
|
||||
**/.vscode
|
||||
**/.idea
|
||||
**/.fleet
|
||||
**/*.swp
|
||||
**/*.swo
|
||||
pkg/logging/Cargo.lock
|
||||
src/agent/src/version.rs
|
||||
src/agent/kata-agent.service
|
||||
|
@@ -80,6 +80,7 @@ pub struct Agent {
|
||||
pub kernel_modules: Vec<String>,
|
||||
|
||||
/// container pipe size
|
||||
#[serde(default)]
|
||||
pub container_pipe_size: u32,
|
||||
}
|
||||
|
||||
|
@@ -16,6 +16,7 @@ lazy_static! {
|
||||
pub static ref DEFAULT_RUNTIME_CONFIGURATIONS: Vec::<&'static str> = vec![
|
||||
"/etc/kata-containers/configuration.toml",
|
||||
"/usr/share/defaults/kata-containers/configuration.toml",
|
||||
"/opt/kata/share/defaults/kata-containers/configuration.toml",
|
||||
];
|
||||
}
|
||||
|
||||
|
@@ -127,6 +127,14 @@ impl TomlConfig {
|
||||
result
|
||||
}
|
||||
|
||||
/// Load raw Kata configuration information from default configuration file.
|
||||
///
|
||||
/// Configuration file is probed according to the default configuration file list
|
||||
/// default::DEFAULT_RUNTIME_CONFIGURATIONS.
|
||||
pub fn load_from_default() -> Result<(TomlConfig, PathBuf)> {
|
||||
Self::load_raw_from_file("")
|
||||
}
|
||||
|
||||
/// Load raw Kata configuration information from configuration files.
|
||||
///
|
||||
/// If `config_file` is valid, it will used, otherwise a built-in default path list will be
|
||||
@@ -196,7 +204,7 @@ impl TomlConfig {
|
||||
}
|
||||
|
||||
/// Probe configuration file according to the default configuration file list.
|
||||
fn get_default_config_file() -> Result<PathBuf> {
|
||||
pub fn get_default_config_file() -> Result<PathBuf> {
|
||||
for f in default::DEFAULT_RUNTIME_CONFIGURATIONS.iter() {
|
||||
if let Ok(path) = fs::canonicalize(f) {
|
||||
return Ok(path);
|
||||
|
440
src/tools/kata-ctl/Cargo.lock
generated
440
src/tools/kata-ctl/Cargo.lock
generated
@@ -33,6 +33,46 @@ dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "342258dd14006105c2b75ab1bd7543a03bdf0cfc94383303ac212a04939dff6f"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"anstyle-parse",
|
||||
"anstyle-wincon",
|
||||
"concolor-override",
|
||||
"concolor-query",
|
||||
"is-terminal",
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle"
|
||||
version = "0.3.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23ea9e81bd02e310c216d080f6223c179012256e5151c41db88d12c88a1684d2"
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-parse"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7d1bb534e9efed14f3e5f44e7dd1a4f709384023a4165199a4241e18dff0116"
|
||||
dependencies = [
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-wincon"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3127af6145b149f3287bb9a0d10ad9c5692dba8c53ad48285e5bec4063834fa"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"windows-sys 0.45.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.69"
|
||||
@@ -53,18 +93,7 @@ checksum = "1cd7fce9ba8c3c042128ce72d8b2ddbf3a05747efb67ea0313c635e10bda47a2"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||
dependencies = [
|
||||
"hermit-abi 0.1.19",
|
||||
"libc",
|
||||
"winapi",
|
||||
"syn 1.0.107",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -98,7 +127,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd9e32d7420c85055e8107e5b2463c4eeefeaac18b52359fe9f9c08a18f342b2"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 1.0.107",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -149,41 +178,60 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "3.2.23"
|
||||
version = "4.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5"
|
||||
checksum = "046ae530c528f252094e4a77886ee1374437744b2bff1497aa898bbddbbb29b3"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"bitflags",
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "223163f58c9a40c3b0a43e1c4b50a9ce09f007ea2cb1ec258a687945b4b7929f"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
"bitflags",
|
||||
"clap_lex",
|
||||
"indexmap",
|
||||
"once_cell",
|
||||
"strsim",
|
||||
"termcolor",
|
||||
"textwrap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "3.2.18"
|
||||
version = "4.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65"
|
||||
checksum = "3f9644cd56d6b87dbe899ef8b053e331c0637664e9e21a33dfcdc36093f5c5c4"
|
||||
dependencies = [
|
||||
"heck 0.4.1",
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.13",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.2.4"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5"
|
||||
checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1"
|
||||
|
||||
[[package]]
|
||||
name = "concolor-override"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a855d4a1978dc52fb0536a04d384c2c0c1aa273597f08b77c8c4d3b2eec6037f"
|
||||
|
||||
[[package]]
|
||||
name = "concolor-query"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "88d11d52c3d7ca2e6d0040212be9e4dbbcd78b6447f535b6b561f449427944cf"
|
||||
dependencies = [
|
||||
"os_str_bytes",
|
||||
"windows-sys 0.45.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -229,7 +277,7 @@ checksum = "3418329ca0ad70234b9735dc4ceed10af4df60eff9c8e7b06cb5e520d92c3535"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 1.0.107",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -257,6 +305,27 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "50d6a0976c999d473fe89ad888d5a284e55366d9dc9038b1ba2aa15128c4afa0"
|
||||
dependencies = [
|
||||
"errno-dragonfly",
|
||||
"libc",
|
||||
"windows-sys 0.45.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "errno-dragonfly"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fastrand"
|
||||
version = "1.8.0"
|
||||
@@ -358,7 +427,7 @@ checksum = "95a73af87da33b5acf53acfebdc339fe592ecf5357ac7c0a7734ab9d8c876a70"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 1.0.107",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -437,15 +506,6 @@ version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.2.6"
|
||||
@@ -455,6 +515,12 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286"
|
||||
|
||||
[[package]]
|
||||
name = "hex"
|
||||
version = "0.4.3"
|
||||
@@ -587,6 +653,17 @@ dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "io-lifetimes"
|
||||
version = "1.0.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c66c74d2ae7e79a5a8f7ac924adbe38ee42a859c6539ad869eb51f0b52dc220"
|
||||
dependencies = [
|
||||
"hermit-abi 0.3.1",
|
||||
"libc",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iovec"
|
||||
version = "0.1.4"
|
||||
@@ -602,6 +679,18 @@ version = "2.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146"
|
||||
|
||||
[[package]]
|
||||
name = "is-terminal"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "256017f749ab3117e93acb91063009e1f1bb56d03965b14c2c8df4eb02c524d8"
|
||||
dependencies = [
|
||||
"hermit-abi 0.3.1",
|
||||
"io-lifetimes",
|
||||
"rustix",
|
||||
"windows-sys 0.45.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.10.5"
|
||||
@@ -653,10 +742,12 @@ dependencies = [
|
||||
"slog-scope",
|
||||
"strum",
|
||||
"strum_macros",
|
||||
"sys-info",
|
||||
"tempfile",
|
||||
"test-utils",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"toml",
|
||||
"url",
|
||||
"vmm-sys-util",
|
||||
]
|
||||
@@ -694,6 +785,12 @@ version = "0.2.139"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d59d8c75012853d2e872fb56bc8a2e53718e2cafe1a4c823143141c6d90c322f"
|
||||
|
||||
[[package]]
|
||||
name = "lock_api"
|
||||
version = "0.4.9"
|
||||
@@ -772,7 +869,7 @@ dependencies = [
|
||||
"libc",
|
||||
"log",
|
||||
"wasi",
|
||||
"windows-sys",
|
||||
"windows-sys 0.42.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -901,7 +998,7 @@ checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 1.0.107",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -923,12 +1020,6 @@ dependencies = [
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "os_str_bytes"
|
||||
version = "6.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee"
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot"
|
||||
version = "0.11.2"
|
||||
@@ -987,7 +1078,7 @@ checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 1.0.107",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1018,35 +1109,11 @@ dependencies = [
|
||||
"nix 0.26.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
||||
dependencies = [
|
||||
"proc-macro-error-attr",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error-attr"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.51"
|
||||
version = "1.0.56"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6"
|
||||
checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
@@ -1089,7 +1156,7 @@ dependencies = [
|
||||
"itertools",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 1.0.107",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1181,9 +1248,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.23"
|
||||
version = "1.0.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
|
||||
checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
@@ -1280,6 +1347,20 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.37.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62b24138615de35e32031d041a09032ef3487a616d901ca4db224e7d557efae2"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"errno",
|
||||
"io-lifetimes",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
"windows-sys 0.45.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustls"
|
||||
version = "0.20.8"
|
||||
@@ -1326,7 +1407,7 @@ version = "0.1.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3"
|
||||
dependencies = [
|
||||
"windows-sys",
|
||||
"windows-sys 0.42.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1391,7 +1472,7 @@ checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 1.0.107",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1436,7 +1517,7 @@ checksum = "b2acd6defeddb41eb60bb468f8825d0cfd0c2a76bc03bfd235b6a1dc4f6a1ad5"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 1.0.107",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1549,7 +1630,7 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rustversion",
|
||||
"syn",
|
||||
"syn 1.0.107",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1563,6 +1644,27 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c9da457c5285ac1f936ebd076af6dac17a61cfe7826f2076b4d015cf47bc8ec"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sys-info"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b3a0d0aba8bf96a0e1ddfdc352fc53b3df7f39318c71854910c3c4b024ae52c"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "take_mut"
|
||||
version = "0.2.2"
|
||||
@@ -1583,15 +1685,6 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "test-utils"
|
||||
version = "0.1.0"
|
||||
@@ -1599,12 +1692,6 @@ dependencies = [
|
||||
"nix 0.24.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "textwrap"
|
||||
version = "0.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d"
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.38"
|
||||
@@ -1622,7 +1709,7 @@ checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 1.0.107",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1692,7 +1779,7 @@ dependencies = [
|
||||
"pin-project-lite",
|
||||
"socket2",
|
||||
"tokio-macros",
|
||||
"windows-sys",
|
||||
"windows-sys 0.42.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1703,7 +1790,7 @@ checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 1.0.107",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1885,18 +1972,18 @@ dependencies = [
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "utf8parse"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
|
||||
|
||||
[[package]]
|
||||
name = "vcpkg"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||
|
||||
[[package]]
|
||||
name = "vmm-sys-util"
|
||||
version = "0.11.1"
|
||||
@@ -1954,7 +2041,7 @@ dependencies = [
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 1.0.107",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
@@ -1988,7 +2075,7 @@ checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 1.0.107",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
@@ -2055,15 +2142,6 @@ version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-util"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
@@ -2076,56 +2154,146 @@ version = "0.42.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
"windows_aarch64_gnullvm 0.42.2",
|
||||
"windows_aarch64_msvc 0.42.2",
|
||||
"windows_i686_gnu 0.42.2",
|
||||
"windows_i686_msvc 0.42.2",
|
||||
"windows_x86_64_gnu 0.42.2",
|
||||
"windows_x86_64_gnullvm 0.42.2",
|
||||
"windows_x86_64_msvc 0.42.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.45.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
|
||||
dependencies = [
|
||||
"windows-targets 0.42.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
|
||||
dependencies = [
|
||||
"windows-targets 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm 0.42.2",
|
||||
"windows_aarch64_msvc 0.42.2",
|
||||
"windows_i686_gnu 0.42.2",
|
||||
"windows_i686_msvc 0.42.2",
|
||||
"windows_x86_64_gnu 0.42.2",
|
||||
"windows_x86_64_gnullvm 0.42.2",
|
||||
"windows_x86_64_msvc 0.42.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm 0.48.0",
|
||||
"windows_aarch64_msvc 0.48.0",
|
||||
"windows_i686_gnu 0.48.0",
|
||||
"windows_i686_msvc 0.48.0",
|
||||
"windows_x86_64_gnu 0.48.0",
|
||||
"windows_x86_64_gnullvm 0.48.0",
|
||||
"windows_x86_64_msvc 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.42.1"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608"
|
||||
checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.42.1"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7"
|
||||
checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.42.1"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640"
|
||||
checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.42.1"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605"
|
||||
checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.42.1"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45"
|
||||
checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.42.1"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463"
|
||||
checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.42.1"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd"
|
||||
checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
|
||||
|
||||
[[package]]
|
||||
name = "winreg"
|
||||
|
@@ -14,7 +14,7 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.31"
|
||||
clap = { version = "3.2.20", features = ["derive", "cargo"] }
|
||||
clap = { version = "4.1.13", features = ["derive", "cargo"] }
|
||||
serde_json = "1.0.85"
|
||||
thiserror = "1.0.35"
|
||||
privdrop = "0.5.2"
|
||||
@@ -25,6 +25,8 @@ serde = { version = "1.0.149", features = ["derive"] }
|
||||
url = "2.3.1"
|
||||
futures = "0.3.24"
|
||||
base64 = "0.13.0"
|
||||
toml = "0.5.8"
|
||||
sys-info = "0.9.1"
|
||||
|
||||
shim-interface = { path = "../../libs/shim-interface"}
|
||||
kata-types = { path = "../../libs/kata-types" }
|
||||
|
@@ -12,10 +12,10 @@ PROJECT_COMPONENT = kata-ctl
|
||||
TARGET = $(PROJECT_COMPONENT)
|
||||
|
||||
VERSION_FILE := ./VERSION
|
||||
VERSION := $(shell grep -v ^\# $(VERSION_FILE))
|
||||
export VERSION := $(shell grep -v ^\# $(VERSION_FILE))
|
||||
COMMIT_NO := $(shell git rev-parse HEAD 2>/dev/null || true)
|
||||
COMMIT_NO_SHORT := $(shell git rev-parse --short HEAD 2>/dev/null || true)
|
||||
COMMIT := $(if $(shell git status --porcelain --untracked-files=no 2>/dev/null || true),${COMMIT_NO}-dirty,${COMMIT_NO})
|
||||
export COMMIT := $(if $(shell git status --porcelain --untracked-files=no 2>/dev/null || true),${COMMIT_NO}-dirty,${COMMIT_NO})
|
||||
|
||||
# Exported to allow cargo to see it
|
||||
export KATA_CTL_VERSION := $(if $(COMMIT),$(VERSION)-$(COMMIT),$(VERSION))
|
||||
@@ -23,7 +23,9 @@ export KATA_CTL_VERSION := $(if $(COMMIT),$(VERSION)-$(COMMIT),$(VERSION))
|
||||
GENERATED_CODE = src/ops/version.rs
|
||||
|
||||
GENERATED_REPLACEMENTS= \
|
||||
KATA_CTL_VERSION
|
||||
KATA_CTL_VERSION \
|
||||
VERSION \
|
||||
COMMIT
|
||||
|
||||
GENERATED_FILES := $(GENERATED_CODE)
|
||||
|
||||
|
@@ -9,6 +9,7 @@ pub use arch_specific::*;
|
||||
mod arch_specific {
|
||||
use crate::check;
|
||||
use crate::types::*;
|
||||
use crate::utils;
|
||||
use anyhow::Result;
|
||||
use std::path::Path;
|
||||
|
||||
@@ -37,6 +38,34 @@ mod arch_specific {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn normalize_vendor(vendor: &str) -> String {
|
||||
match vendor {
|
||||
"0x41" => String::from("ARM Limited"),
|
||||
_ => String::from("3rd Party Limited"),
|
||||
}
|
||||
}
|
||||
|
||||
fn normalize_model(model: &str) -> String {
|
||||
match model {
|
||||
"8" => String::from("v8"),
|
||||
"7" | "7M" | "?(12)" | "?(13)" | "?(14)" | "?(15)" | "?(16)" | "?(17)" => {
|
||||
String::from("v7")
|
||||
}
|
||||
"6" | "6TEJ" => String::from("v6"),
|
||||
"5" | "5T" | "5TE" | "5TEJ" => String::from("v5"),
|
||||
"4" | "4T" => String::from("v4"),
|
||||
"3" => String::from("v3"),
|
||||
_ => String::from("unknown"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_cpu_details() -> Result<(String, String)> {
|
||||
let (vendor, model) = utils::get_generic_cpu_details(check::PROC_CPUINFO)?;
|
||||
let norm_vendor = normalize_vendor(&vendor);
|
||||
let norm_model = normalize_model(&model);
|
||||
Ok((norm_vendor, norm_model))
|
||||
}
|
||||
|
||||
pub fn get_checks() -> Option<&'static [CheckItem<'static>]> {
|
||||
Some(CHECK_LIST)
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@ pub use arch_specific::*;
|
||||
|
||||
mod arch_specific {
|
||||
use crate::check;
|
||||
use crate::utils;
|
||||
use anyhow::Result;
|
||||
|
||||
pub const ARCH_CPU_VENDOR_FIELD: &str = "";
|
||||
@@ -24,6 +25,14 @@ mod arch_specific {
|
||||
|
||||
const PEF_SYS_FIRMWARE_DIR: &str = "/sys/firmware/ultravisor/";
|
||||
|
||||
pub fn get_cpu_details() -> Result<(String, String)> {
|
||||
utils::get_generic_cpu_details(check::PROC_CPUINFO)
|
||||
|
||||
// TODO: In case of error from get_generic_cpu_details, implement functionality
|
||||
// to get cpu details specific to powerpc architecture similar
|
||||
// to the goloang implementation of function getCPUDetails()
|
||||
}
|
||||
|
||||
pub fn available_guest_protection() -> Result<check::GuestProtection, check::ProtectionError> {
|
||||
if !Uid::effective().is_root() {
|
||||
return Err(check::ProtectionError::NoPerms);
|
||||
|
@@ -10,6 +10,7 @@ pub use arch_specific::*;
|
||||
mod arch_specific {
|
||||
use crate::check;
|
||||
use crate::types::*;
|
||||
use crate::utils;
|
||||
use anyhow::{anyhow, Result};
|
||||
use nix::unistd::Uid;
|
||||
use std::collections::HashMap;
|
||||
@@ -144,6 +145,14 @@ mod arch_specific {
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
pub fn get_cpu_details() -> Result<(String, String)> {
|
||||
utils::get_generic_cpu_details(check::PROC_CPUINFO)
|
||||
|
||||
// TODO: In case of error from get_generic_cpu_details, implement functionality
|
||||
// to get cpu details specific to s390x architecture similar
|
||||
// to the goloang implementation of function getS390xCPUDetails()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
// Guest protection is not supported on ARM64.
|
||||
pub fn available_guest_protection() -> Result<check::GuestProtection, check::ProtectionError> {
|
||||
|
@@ -12,6 +12,7 @@ mod arch_specific {
|
||||
use crate::check;
|
||||
use crate::check::{GuestProtection, ProtectionError};
|
||||
use crate::types::*;
|
||||
use crate::utils;
|
||||
use anyhow::{anyhow, Result};
|
||||
use nix::unistd::Uid;
|
||||
use std::fs;
|
||||
@@ -109,6 +110,10 @@ mod arch_specific {
|
||||
Ok(cpu_flags)
|
||||
}
|
||||
|
||||
pub fn get_cpu_details() -> Result<(String, String)> {
|
||||
utils::get_generic_cpu_details(check::PROC_CPUINFO)
|
||||
}
|
||||
|
||||
pub const TDX_SYS_FIRMWARE_DIR: &str = "/sys/firmware/tdx_seam/";
|
||||
pub const TDX_CPU_FLAG: &str = "tdx";
|
||||
pub const SEV_KVM_PARAMETER_PATH: &str = "/sys/module/kvm_amd/parameters/sev";
|
||||
|
@@ -23,7 +23,7 @@ pub enum Commands {
|
||||
DirectVolume(DirectVolumeCommand),
|
||||
|
||||
/// Display settings
|
||||
Env,
|
||||
Env(EnvArgument),
|
||||
|
||||
/// Enter into guest VM by debug console
|
||||
Exec(ExecArguments),
|
||||
@@ -69,6 +69,15 @@ pub enum CheckSubCommand {
|
||||
List,
|
||||
}
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
pub struct EnvArgument {
|
||||
/// Format output as JSON
|
||||
#[arg(long)]
|
||||
pub json: bool,
|
||||
/// File to write env output to
|
||||
#[arg(short = 'f', long = "file")]
|
||||
pub file: Option<String>,
|
||||
}
|
||||
#[derive(Debug, Args)]
|
||||
pub struct MetricsCommand {
|
||||
#[clap(subcommand)]
|
||||
|
@@ -8,6 +8,7 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
use reqwest::header::{CONTENT_TYPE, USER_AGENT};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
use thiserror::Error;
|
||||
|
||||
#[cfg(any(target_arch = "x86_64"))]
|
||||
@@ -46,7 +47,6 @@ pub const GENERIC_CPU_MODEL_FIELD: &str = "model name";
|
||||
#[allow(dead_code)]
|
||||
pub const PROC_CPUINFO: &str = "/proc/cpuinfo";
|
||||
|
||||
#[cfg(any(target_arch = "s390x", target_arch = "x86_64"))]
|
||||
fn read_file_contents(file_path: &str) -> Result<String> {
|
||||
let contents = std::fs::read_to_string(file_path)?;
|
||||
Ok(contents)
|
||||
@@ -54,7 +54,6 @@ fn read_file_contents(file_path: &str) -> Result<String> {
|
||||
|
||||
// get_single_cpu_info returns the contents of the first cpu from
|
||||
// the specified cpuinfo file by parsing based on a specified delimiter
|
||||
#[cfg(any(target_arch = "s390x", target_arch = "x86_64"))]
|
||||
pub fn get_single_cpu_info(cpu_info_file: &str, substring: &str) -> Result<String> {
|
||||
let contents = read_file_contents(cpu_info_file)?;
|
||||
|
||||
@@ -147,6 +146,19 @@ pub enum GuestProtection {
|
||||
Se,
|
||||
}
|
||||
|
||||
impl fmt::Display for GuestProtection {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
GuestProtection::Tdx => write!(f, "tdx"),
|
||||
GuestProtection::Sev => write!(f, "sev"),
|
||||
GuestProtection::Snp => write!(f, "snp"),
|
||||
GuestProtection::Pef => write!(f, "pef"),
|
||||
GuestProtection::Se => write!(f, "se"),
|
||||
GuestProtection::NoProtection => write!(f, "none"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Error, Debug)]
|
||||
pub enum ProtectionError {
|
||||
|
@@ -17,8 +17,9 @@ use std::process::exit;
|
||||
use args::{Commands, KataCtlCli};
|
||||
|
||||
use ops::check_ops::{
|
||||
handle_check, handle_env, handle_factory, handle_iptables, handle_metrics, handle_version,
|
||||
handle_check, handle_factory, handle_iptables, handle_metrics, handle_version,
|
||||
};
|
||||
use ops::env_ops::handle_env;
|
||||
use ops::exec_ops::handle_exec;
|
||||
use ops::volume_ops::handle_direct_volume;
|
||||
|
||||
@@ -29,7 +30,7 @@ fn real_main() -> Result<()> {
|
||||
Commands::Check(args) => handle_check(args),
|
||||
Commands::DirectVolume(args) => handle_direct_volume(args),
|
||||
Commands::Exec(args) => handle_exec(args),
|
||||
Commands::Env => handle_env(),
|
||||
Commands::Env(args) => handle_env(args),
|
||||
Commands::Factory => handle_factory(),
|
||||
Commands::Iptables(args) => handle_iptables(args),
|
||||
Commands::Metrics(args) => handle_metrics(args),
|
||||
|
@@ -4,6 +4,7 @@
|
||||
//
|
||||
|
||||
pub mod check_ops;
|
||||
pub mod env_ops;
|
||||
pub mod exec_ops;
|
||||
pub mod version;
|
||||
pub mod volume_ops;
|
||||
|
@@ -107,10 +107,6 @@ pub fn handle_check(checkcmd: CheckArgument) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn handle_env() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn handle_factory() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
469
src/tools/kata-ctl/src/ops/env_ops.rs
Normal file
469
src/tools/kata-ctl/src/ops/env_ops.rs
Normal file
@@ -0,0 +1,469 @@
|
||||
// Copyright (c) 2022 Intel Corporation
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
// Contains checks that are not architecture-specific
|
||||
|
||||
use crate::arch::arch_specific;
|
||||
use crate::args::EnvArgument;
|
||||
use crate::ops::version;
|
||||
use crate::utils;
|
||||
use kata_types::config::TomlConfig;
|
||||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use nix::unistd::Uid;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs::File;
|
||||
use std::io::{self, Write};
|
||||
use std::process::Command;
|
||||
use sys_info;
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize)]
|
||||
pub struct HostInfo {
|
||||
#[serde(default)]
|
||||
available_guest_protection: String,
|
||||
#[serde(default)]
|
||||
kernel: String,
|
||||
#[serde(default)]
|
||||
architecture: String,
|
||||
#[serde(default)]
|
||||
vm_container_capable: bool,
|
||||
#[serde(default)]
|
||||
support_vsocks: bool,
|
||||
#[serde(default)]
|
||||
distro: DistroInfo,
|
||||
#[serde(default)]
|
||||
cpu: CPUInfo,
|
||||
#[serde(default)]
|
||||
memory: MemoryInfo,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize)]
|
||||
pub struct DistroInfo {
|
||||
#[serde(default)]
|
||||
name: String,
|
||||
#[serde(default)]
|
||||
version: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize)]
|
||||
pub struct CPUInfo {
|
||||
#[serde(default)]
|
||||
vendor: String,
|
||||
#[serde(default)]
|
||||
model: String,
|
||||
#[serde(default)]
|
||||
cpus: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize)]
|
||||
pub struct MemoryInfo {
|
||||
#[serde(default)]
|
||||
total: u64,
|
||||
#[serde(default)]
|
||||
available: u64,
|
||||
#[serde(default)]
|
||||
free: u64,
|
||||
}
|
||||
|
||||
// Semantic version for the output of the command.
|
||||
//
|
||||
// XXX: Increment for every change to the output format
|
||||
// (meaning any change to the EnvInfo type).
|
||||
const FORMAT_VERSION: &str = "0.0.1-kata-ctl";
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize)]
|
||||
pub struct MetaInfo {
|
||||
#[serde(default)]
|
||||
version: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize)]
|
||||
pub struct VersionInfo {
|
||||
#[serde(default)]
|
||||
semver: String,
|
||||
#[serde(default)]
|
||||
commit: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize)]
|
||||
pub struct RuntimeConfigInfo {
|
||||
#[serde(default)]
|
||||
path: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize)]
|
||||
pub struct RuntimeInfo {
|
||||
#[serde(default)]
|
||||
path: String,
|
||||
#[serde(default)]
|
||||
guest_selinux_label: String,
|
||||
#[serde(default)]
|
||||
pub experimental: Vec<String>,
|
||||
#[serde(default)]
|
||||
debug: bool,
|
||||
#[serde(default)]
|
||||
trace: bool,
|
||||
#[serde(default)]
|
||||
disable_guest_seccomp: bool,
|
||||
#[serde(default)]
|
||||
disable_new_net_ns: bool,
|
||||
#[serde(default)]
|
||||
sandbox_cgroup_only: bool,
|
||||
#[serde(default)]
|
||||
static_sandbox_resource_mgmt: bool,
|
||||
#[serde(default)]
|
||||
config: RuntimeConfigInfo,
|
||||
#[serde(default)]
|
||||
version: VersionInfo,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize)]
|
||||
pub struct AgentInfo {
|
||||
#[serde(default)]
|
||||
debug: bool,
|
||||
#[serde(default)]
|
||||
trace: bool,
|
||||
}
|
||||
// KernelInfo stores kernel details
|
||||
#[derive(Debug, Default, Deserialize, Serialize)]
|
||||
pub struct KernelInfo {
|
||||
#[serde(default)]
|
||||
path: String,
|
||||
#[serde(default)]
|
||||
parameters: String,
|
||||
}
|
||||
|
||||
// InitrdInfo stores initrd image details
|
||||
#[derive(Debug, Default, Deserialize, Serialize)]
|
||||
pub struct InitrdInfo {
|
||||
#[serde(default)]
|
||||
path: String,
|
||||
}
|
||||
|
||||
// ImageInfo stores root filesystem image details
|
||||
#[derive(Debug, Default, Deserialize, Serialize)]
|
||||
pub struct ImageInfo {
|
||||
#[serde(default)]
|
||||
path: String,
|
||||
}
|
||||
|
||||
// HypervisorInfo stores hypervisor details
|
||||
#[derive(Debug, Default, Deserialize, Serialize)]
|
||||
pub struct HypervisorInfo {
|
||||
#[serde(default)]
|
||||
machine_type: String,
|
||||
#[serde(default)]
|
||||
machine_accelerators: String,
|
||||
#[serde(default)]
|
||||
version: String,
|
||||
#[serde(default)]
|
||||
path: String,
|
||||
#[serde(default)]
|
||||
block_device_driver: String,
|
||||
#[serde(default)]
|
||||
entropy_source: String,
|
||||
#[serde(default)]
|
||||
shared_fs: String,
|
||||
#[serde(default)]
|
||||
virtio_fs_daemon: String,
|
||||
#[serde(default)]
|
||||
msize_9p: u32,
|
||||
#[serde(default)]
|
||||
memory_slots: u32,
|
||||
#[serde(default)]
|
||||
pcie_root_port: u32,
|
||||
#[serde(default)]
|
||||
hotplug_vfio_on_rootbus: bool,
|
||||
#[serde(default)]
|
||||
debug: bool,
|
||||
#[serde(default)]
|
||||
enable_iommu: bool,
|
||||
#[serde(default)]
|
||||
enable_iommu_platform: bool,
|
||||
#[serde(default)]
|
||||
default_vcpus: i32,
|
||||
#[serde(default)]
|
||||
cpu_features: String,
|
||||
}
|
||||
|
||||
// EnvInfo collects all information that will be displayed by the
|
||||
// env command.
|
||||
//
|
||||
// XXX: Any changes must be coupled with a change to formatVersion.
|
||||
#[derive(Debug, Default, Deserialize, Serialize)]
|
||||
pub struct EnvInfo {
|
||||
#[serde(default)]
|
||||
kernel: KernelInfo,
|
||||
#[serde(default)]
|
||||
meta: MetaInfo,
|
||||
#[serde(default)]
|
||||
image: ImageInfo,
|
||||
#[serde(default)]
|
||||
initrd: InitrdInfo,
|
||||
#[serde(default)]
|
||||
hypervisor: HypervisorInfo,
|
||||
#[serde(default)]
|
||||
runtime: RuntimeInfo,
|
||||
#[serde(default)]
|
||||
host: HostInfo,
|
||||
#[serde(default)]
|
||||
agent: AgentInfo,
|
||||
}
|
||||
|
||||
pub fn get_meta_info() -> MetaInfo {
|
||||
MetaInfo {
|
||||
version: String::from(FORMAT_VERSION),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_memory_info() -> Result<MemoryInfo> {
|
||||
let mem_info = sys_info::mem_info().context("get host memory information")?;
|
||||
Ok(MemoryInfo {
|
||||
total: mem_info.total,
|
||||
available: mem_info.avail,
|
||||
free: mem_info.free,
|
||||
})
|
||||
}
|
||||
|
||||
fn get_host_info() -> Result<HostInfo> {
|
||||
let host_kernel_version = utils::get_kernel_version(utils::PROC_VERSION_FILE)?;
|
||||
let (host_distro_name, host_distro_version) =
|
||||
utils::get_distro_details(utils::OS_RELEASE, utils::OS_RELEASE_CLR)?;
|
||||
let (cpu_vendor, cpu_model) = arch_specific::get_cpu_details()?;
|
||||
|
||||
let host_distro = DistroInfo {
|
||||
name: host_distro_name,
|
||||
version: host_distro_version,
|
||||
};
|
||||
|
||||
let cores: usize = std::thread::available_parallelism()
|
||||
.context("get available parallelism")?
|
||||
.into();
|
||||
|
||||
let host_cpu = CPUInfo {
|
||||
vendor: cpu_vendor,
|
||||
model: cpu_model,
|
||||
cpus: cores,
|
||||
};
|
||||
|
||||
let memory_info = get_memory_info()?;
|
||||
|
||||
let guest_protection =
|
||||
arch_specific::available_guest_protection().map_err(|e| anyhow!(e.to_string()))?;
|
||||
|
||||
let guest_protection = guest_protection.to_string();
|
||||
|
||||
let support_vsocks = utils::supports_vsocks(utils::VHOST_VSOCK_DEVICE)?;
|
||||
|
||||
Ok(HostInfo {
|
||||
kernel: host_kernel_version,
|
||||
architecture: String::from(std::env::consts::ARCH),
|
||||
distro: host_distro,
|
||||
cpu: host_cpu,
|
||||
memory: memory_info,
|
||||
available_guest_protection: guest_protection,
|
||||
// TODO: See https://github.com/kata-containers/kata-containers/issues/6727
|
||||
vm_container_capable: true,
|
||||
support_vsocks,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_runtime_info(toml_config: &TomlConfig) -> Result<RuntimeInfo> {
|
||||
let version = VersionInfo {
|
||||
semver: String::from(version::VERSION),
|
||||
commit: String::from(version::COMMIT),
|
||||
};
|
||||
|
||||
let config_path = TomlConfig::get_default_config_file();
|
||||
let mut toml_path = String::new();
|
||||
if config_path.is_ok() {
|
||||
let p = config_path?;
|
||||
let path_str = p.to_str();
|
||||
toml_path = match path_str {
|
||||
Some(s) => String::from(s),
|
||||
None => String::new(),
|
||||
};
|
||||
}
|
||||
|
||||
Ok(RuntimeInfo {
|
||||
// TODO: Needs to be implemented: https://github.com/kata-containers/kata-containers/issues/6518
|
||||
path: String::from("not implemented yet. See: https://github.com/kata-containers/kata-containers/issues/6518"),
|
||||
version,
|
||||
experimental: toml_config.runtime.experimental.clone(),
|
||||
// TODO: See https://github.com/kata-containers/kata-containers/issues/6667
|
||||
guest_selinux_label: String::from("not implemented yet: See https://github.com/kata-containers/kata-containers/issues/6667"),
|
||||
debug: toml_config.runtime.debug,
|
||||
trace: toml_config.runtime.enable_tracing,
|
||||
disable_guest_seccomp: toml_config.runtime.disable_guest_seccomp,
|
||||
disable_new_net_ns: toml_config.runtime.disable_new_netns,
|
||||
sandbox_cgroup_only: toml_config.runtime.sandbox_cgroup_only,
|
||||
static_sandbox_resource_mgmt: toml_config.runtime.static_sandbox_resource_mgmt,
|
||||
config: RuntimeConfigInfo { path: toml_path },
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_agent_info(toml_config: &TomlConfig) -> Result<AgentInfo> {
|
||||
// Assign the first entry to the agent config, to make this
|
||||
// work for configs where agent_name is absent.
|
||||
// This is a workaround for https://github.com/kata-containers/kata-containers/issues/5954
|
||||
let key_val = toml_config.agent.iter().next();
|
||||
let mut agent_config = match key_val {
|
||||
Some(x) => Ok(x.1),
|
||||
None => Err(anyhow!("Missing agent config")),
|
||||
}?;
|
||||
|
||||
// If the agent_name config is present, use that
|
||||
if !&toml_config.runtime.agent_name.is_empty() {
|
||||
agent_config = toml_config
|
||||
.agent
|
||||
.get(&toml_config.runtime.agent_name)
|
||||
.ok_or("could not find agent config in configuration")
|
||||
.map_err(|e| anyhow!(e))?;
|
||||
}
|
||||
|
||||
Ok(AgentInfo {
|
||||
debug: agent_config.debug,
|
||||
trace: agent_config.enable_tracing,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_command_version(cmd: &str) -> Result<String> {
|
||||
// Path is empty in case of dragonball hypervisor
|
||||
if cmd.is_empty() {
|
||||
return Ok("unknown".to_string());
|
||||
}
|
||||
let output = Command::new(cmd)
|
||||
.arg("--version")
|
||||
.output()
|
||||
.map_err(|e| anyhow!(e))?;
|
||||
|
||||
let version = String::from_utf8(output.stdout).map_err(|e| anyhow!(e))?;
|
||||
|
||||
Ok(version)
|
||||
}
|
||||
|
||||
pub fn get_hypervisor_info(
|
||||
toml_config: &TomlConfig,
|
||||
) -> Result<(HypervisorInfo, ImageInfo, KernelInfo, InitrdInfo)> {
|
||||
// Assign the first entry in the hashmap to the hypervisor config, to make this
|
||||
// work for configs where hypervisor_name is absent.
|
||||
// This is a workaround for https://github.com/kata-containers/kata-containers/issues/5954
|
||||
let key_val = toml_config.hypervisor.iter().next();
|
||||
let mut hypervisor_config = match key_val {
|
||||
Some(x) => Ok(x.1),
|
||||
None => Err(anyhow!("Missing hypervisor config")),
|
||||
}?;
|
||||
|
||||
// If hypervisor_name config is present, use that
|
||||
if !&toml_config.runtime.hypervisor_name.is_empty() {
|
||||
hypervisor_config = toml_config
|
||||
.hypervisor
|
||||
.get(&toml_config.runtime.hypervisor_name)
|
||||
.ok_or("could not find hypervisor config in configuration")
|
||||
.map_err(|e| anyhow!(e))?;
|
||||
}
|
||||
|
||||
let version =
|
||||
get_command_version(&hypervisor_config.path).context("error getting hypervisor version")?;
|
||||
|
||||
let hypervisor_info = HypervisorInfo {
|
||||
machine_type: hypervisor_config.machine_info.machine_type.to_string(),
|
||||
machine_accelerators: hypervisor_config
|
||||
.machine_info
|
||||
.machine_accelerators
|
||||
.to_string(),
|
||||
version,
|
||||
path: hypervisor_config.path.to_string(),
|
||||
block_device_driver: hypervisor_config
|
||||
.blockdev_info
|
||||
.block_device_driver
|
||||
.to_string(),
|
||||
entropy_source: hypervisor_config.machine_info.entropy_source.to_string(),
|
||||
shared_fs: hypervisor_config
|
||||
.shared_fs
|
||||
.shared_fs
|
||||
.clone()
|
||||
.unwrap_or_else(|| String::from("none")),
|
||||
virtio_fs_daemon: hypervisor_config.shared_fs.virtio_fs_daemon.to_string(),
|
||||
msize_9p: hypervisor_config.shared_fs.msize_9p,
|
||||
memory_slots: hypervisor_config.memory_info.memory_slots,
|
||||
pcie_root_port: hypervisor_config.device_info.pcie_root_port,
|
||||
hotplug_vfio_on_rootbus: hypervisor_config.device_info.hotplug_vfio_on_root_bus,
|
||||
debug: hypervisor_config.debug_info.enable_debug,
|
||||
enable_iommu: hypervisor_config.device_info.enable_iommu,
|
||||
enable_iommu_platform: hypervisor_config.device_info.enable_iommu_platform,
|
||||
default_vcpus: hypervisor_config.cpu_info.default_vcpus,
|
||||
cpu_features: hypervisor_config.cpu_info.cpu_features.to_string(),
|
||||
};
|
||||
|
||||
let image_info = ImageInfo {
|
||||
path: hypervisor_config.boot_info.image.clone(),
|
||||
};
|
||||
|
||||
let kernel_info = KernelInfo {
|
||||
path: hypervisor_config.boot_info.kernel.to_string(),
|
||||
parameters: hypervisor_config.boot_info.kernel_params.to_string(),
|
||||
};
|
||||
|
||||
let initrd_info = InitrdInfo {
|
||||
path: hypervisor_config.boot_info.initrd.to_string(),
|
||||
};
|
||||
|
||||
Ok((hypervisor_info, image_info, kernel_info, initrd_info))
|
||||
}
|
||||
|
||||
pub fn get_env_info(toml_config: &TomlConfig) -> Result<EnvInfo> {
|
||||
let metainfo = get_meta_info();
|
||||
|
||||
let runtime_info = get_runtime_info(toml_config).context("get runtime info")?;
|
||||
|
||||
let agent_info = get_agent_info(toml_config).context("get agent configuration")?;
|
||||
|
||||
let host_info = get_host_info().context("get host information")?;
|
||||
|
||||
let (hypervisor_info, _image_info, kernel_info, initrd_info) =
|
||||
get_hypervisor_info(toml_config).context("get hypervisor configuration")?;
|
||||
|
||||
let env_info = EnvInfo {
|
||||
meta: metainfo,
|
||||
runtime: runtime_info,
|
||||
kernel: kernel_info,
|
||||
image: _image_info,
|
||||
initrd: initrd_info,
|
||||
hypervisor: hypervisor_info,
|
||||
host: host_info,
|
||||
agent: agent_info,
|
||||
};
|
||||
|
||||
Ok(env_info)
|
||||
}
|
||||
|
||||
pub fn handle_env(env_args: EnvArgument) -> Result<()> {
|
||||
if !Uid::effective().is_root() {
|
||||
return Err(anyhow!("kata-ctl env command requires root privileges to get host information. Please run as root or use sudo"));
|
||||
}
|
||||
|
||||
let mut file: Box<dyn Write> = if let Some(path) = env_args.file {
|
||||
Box::new(
|
||||
File::create(path.as_str()).with_context(|| format!("Error creating file {}", path))?,
|
||||
)
|
||||
} else {
|
||||
Box::new(io::stdout())
|
||||
};
|
||||
|
||||
let (toml_config, _) = TomlConfig::load_from_default().context("load toml config")?;
|
||||
|
||||
let env_info = get_env_info(&toml_config)?;
|
||||
|
||||
if env_args.json {
|
||||
let serialized_json = serde_json::to_string_pretty(&env_info)?;
|
||||
write!(file, "{}", serialized_json)?;
|
||||
} else {
|
||||
let toml = toml::to_string(&env_info)?;
|
||||
write!(file, "{}", toml)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
@@ -10,6 +10,8 @@
|
||||
use clap::crate_version;
|
||||
|
||||
const KATA_CTL_VERSION: &str = "@KATA_CTL_VERSION@";
|
||||
pub const VERSION: &str = "@VERSION@";
|
||||
pub const COMMIT: &str = "@COMMIT@";
|
||||
|
||||
pub fn get() -> Result<String, String> {
|
||||
if KATA_CTL_VERSION.trim().is_empty() {
|
||||
|
@@ -5,9 +5,7 @@
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
#[cfg(any(target_arch = "s390x", target_arch = "x86_64"))]
|
||||
use crate::arch::arch_specific;
|
||||
#[cfg(any(target_arch = "s390x", target_arch = "x86_64"))]
|
||||
use crate::check::get_single_cpu_info;
|
||||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
@@ -27,7 +25,7 @@ pub fn drop_privs() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
const PROC_VERSION_FILE: &str = "/proc/version";
|
||||
pub const PROC_VERSION_FILE: &str = "/proc/version";
|
||||
|
||||
pub fn get_kernel_version(proc_version_file: &str) -> Result<String> {
|
||||
let contents = fs::read_to_string(proc_version_file)
|
||||
@@ -43,10 +41,10 @@ pub fn get_kernel_version(proc_version_file: &str) -> Result<String> {
|
||||
Ok(kernel_version)
|
||||
}
|
||||
|
||||
const OS_RELEASE: &str = "/etc/os-release";
|
||||
pub const OS_RELEASE: &str = "/etc/os-release";
|
||||
|
||||
// Clear Linux has a different path (for stateless support)
|
||||
const OS_RELEASE_CLR: &str = "/usr/lib/os-release";
|
||||
pub const OS_RELEASE_CLR: &str = "/usr/lib/os-release";
|
||||
|
||||
const UNKNOWN: &str = "unknown";
|
||||
|
||||
@@ -106,11 +104,10 @@ pub fn get_distro_details(os_release: &str, os_release_clr: &str) -> Result<(Str
|
||||
Ok((name, version))
|
||||
}
|
||||
|
||||
#[cfg(any(target_arch = "s390x", target_arch = "x86_64"))]
|
||||
#[cfg(any(target_arch = "s390x", target_arch = "x86_64", target_arch = "aarch64"))]
|
||||
pub fn get_generic_cpu_details(cpu_info_file: &str) -> Result<(String, String)> {
|
||||
let cpu_info = get_single_cpu_info(cpu_info_file, "\n\n")?;
|
||||
let lines = cpu_info.lines();
|
||||
println!("Single cpu info: {}", cpu_info);
|
||||
let mut vendor = String::new();
|
||||
let mut model = String::new();
|
||||
|
||||
@@ -144,9 +141,14 @@ pub fn get_generic_cpu_details(cpu_info_file: &str) -> Result<(String, String)>
|
||||
Ok((vendor, model))
|
||||
}
|
||||
|
||||
const VHOST_VSOCK_DEVICE: &str = "/dev/vhost-vsock";
|
||||
pub const VHOST_VSOCK_DEVICE: &str = "/dev/vhost-vsock";
|
||||
pub fn supports_vsocks(vsock_path: &str) -> Result<bool> {
|
||||
let metadata = fs::metadata(vsock_path)?;
|
||||
let metadata = fs::metadata(vsock_path).map_err(|err| {
|
||||
anyhow!(
|
||||
"Host system does not support vhost-vsock (try running (`sudo modprobe vhost_vsock`) : {}",
|
||||
err.to_string()
|
||||
)
|
||||
})?;
|
||||
Ok(metadata.is_file())
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user