From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id D0B141FF348 for ; Wed, 17 Apr 2024 14:40:27 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 6EB0669B3; Wed, 17 Apr 2024 14:40:21 +0200 (CEST) From: Aaron Lauterer To: pve-devel@lists.proxmox.com Date: Wed, 17 Apr 2024 14:30:58 +0200 Message-Id: <20240417123108.212720-27-a.lauterer@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240417123108.212720-1-a.lauterer@proxmox.com> References: <20240417123108.212720-1-a.lauterer@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.095 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment PROLO_LEO1 0.1 Meta Catches all Leo drug variations so far SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH installer v6 26/36] auto installer: factor out fetch-answer and autoinst-helper X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" Putting proxmox-fetch-answer into it's own crate, will keep the use of OpenSSL localized to where we need it. Otherwise building other binaries will always depend on OpenSSL as well, even without actually needing it. Having a dedicated crate for the proxmox-autoinst-helper should make it easier to build it independently to have it available outside of the install environment. The fetch plugins have been moved to the proxmox-fetch-answer crate, except for the 'get_nic_list' function and 'sysinfo.rs'. Since both are also needed by the proxmox-autoinst-helper, they are kept in the proxmox-auto-installer crate. Tested-by: Christoph Heiss Reviewed-by: Christoph Heiss Signed-off-by: Aaron Lauterer --- Cargo.toml | 2 ++ Makefile | 5 +++- proxmox-auto-installer/Cargo.toml | 6 ---- .../src/fetch_plugins/mod.rs | 3 -- proxmox-auto-installer/src/lib.rs | 2 +- .../src/{fetch_plugins/utils => }/sysinfo.rs | 2 +- proxmox-auto-installer/src/utils.rs | 25 ++++++++++++++++ proxmox-autoinst-helper/Cargo.toml | 21 +++++++++++++ .../src/main.rs | 5 ++-- proxmox-fetch-answer/Cargo.toml | 22 ++++++++++++++ .../src/fetch_plugins/http.rs | 3 +- proxmox-fetch-answer/src/fetch_plugins/mod.rs | 3 ++ .../src/fetch_plugins/partition.rs | 2 +- .../src/fetch_plugins/utils/mod.rs | 30 +------------------ .../src/fetch_plugins/utils/post.rs | 2 +- .../src/main.rs | 8 ++--- 16 files changed, 90 insertions(+), 51 deletions(-) delete mode 100644 proxmox-auto-installer/src/fetch_plugins/mod.rs rename proxmox-auto-installer/src/{fetch_plugins/utils => }/sysinfo.rs (98%) create mode 100644 proxmox-autoinst-helper/Cargo.toml rename proxmox-auto-installer/src/bin/proxmox-autoinst-helper.rs => proxmox-autoinst-helper/src/main.rs (98%) create mode 100644 proxmox-fetch-answer/Cargo.toml rename {proxmox-auto-installer => proxmox-fetch-answer}/src/fetch_plugins/http.rs (98%) create mode 100644 proxmox-fetch-answer/src/fetch_plugins/mod.rs rename {proxmox-auto-installer => proxmox-fetch-answer}/src/fetch_plugins/partition.rs (100%) rename {proxmox-auto-installer => proxmox-fetch-answer}/src/fetch_plugins/utils/mod.rs (81%) rename {proxmox-auto-installer => proxmox-fetch-answer}/src/fetch_plugins/utils/post.rs (99%) rename proxmox-auto-installer/src/bin/proxmox-fetch-answer.rs => proxmox-fetch-answer/src/main.rs (93%) diff --git a/Cargo.toml b/Cargo.toml index 7017ac5..b694d5b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,8 @@ [workspace] members = [ "proxmox-auto-installer", + "proxmox-autoinst-helper", + "proxmox-fetch-answer", "proxmox-installer-common", "proxmox-tui-installer", ] diff --git a/Makefile b/Makefile index 197a351..e32d28f 100644 --- a/Makefile +++ b/Makefile @@ -52,6 +52,8 @@ $(BUILDDIR): proxinstall \ proxmox-low-level-installer \ proxmox-auto-installer/ \ + proxmox-autoinst-helper/ \ + proxmox-fetch-answer/ \ proxmox-tui-installer/ \ proxmox-installer-common/ \ test/ \ @@ -124,7 +126,8 @@ $(COMPILED_BINS): cargo-build cargo-build: $(CARGO) build --package proxmox-tui-installer --bin proxmox-tui-installer \ --package proxmox-auto-installer --bin proxmox-auto-installer \ - --bin proxmox-fetch-answer --bin proxmox-autoinst-helper $(CARGO_BUILD_ARGS) + --package proxmox-fetch-answer --bin proxmox-fetch-answer \ + --package proxmox-autoinst-helper --bin proxmox-autoinst-helper $(CARGO_BUILD_ARGS) %-banner.png: %-banner.svg rsvg-convert -o $@ $< diff --git a/proxmox-auto-installer/Cargo.toml b/proxmox-auto-installer/Cargo.toml index ac2f3a6..bb0b49c 100644 --- a/proxmox-auto-installer/Cargo.toml +++ b/proxmox-auto-installer/Cargo.toml @@ -18,9 +18,3 @@ toml = "0.7" enum-iterator = "0.6.0" log = "0.4.20" regex = "1.7" -ureq = { version = "2.6", features = [ "native-certs", "native-tls" ] } -rustls = { version = "0.20", features = [ "dangerous_configuration" ] } -rustls-native-certs = "0.6" -native-tls = "0.2" -sha2 = "0.10" -hex = "0.4" diff --git a/proxmox-auto-installer/src/fetch_plugins/mod.rs b/proxmox-auto-installer/src/fetch_plugins/mod.rs deleted file mode 100644 index 354fa7e..0000000 --- a/proxmox-auto-installer/src/fetch_plugins/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod http; -pub mod partition; -pub mod utils; diff --git a/proxmox-auto-installer/src/lib.rs b/proxmox-auto-installer/src/lib.rs index 0a153b2..3bdf0b5 100644 --- a/proxmox-auto-installer/src/lib.rs +++ b/proxmox-auto-installer/src/lib.rs @@ -1,5 +1,5 @@ pub mod answer; -pub mod fetch_plugins; pub mod log; +pub mod sysinfo; pub mod udevinfo; pub mod utils; diff --git a/proxmox-auto-installer/src/fetch_plugins/utils/sysinfo.rs b/proxmox-auto-installer/src/sysinfo.rs similarity index 98% rename from proxmox-auto-installer/src/fetch_plugins/utils/sysinfo.rs rename to proxmox-auto-installer/src/sysinfo.rs index 8c57283..f5de214 100644 --- a/proxmox-auto-installer/src/fetch_plugins/utils/sysinfo.rs +++ b/proxmox-auto-installer/src/sysinfo.rs @@ -3,7 +3,7 @@ use proxmox_installer_common::setup::SetupInfo; use serde::Serialize; use std::{collections::HashMap, fs, io, path::Path}; -use super::get_nic_list; +use crate::utils::get_nic_list; const DMI_PATH: &str = "/sys/devices/virtual/dmi/id"; diff --git a/proxmox-auto-installer/src/utils.rs b/proxmox-auto-installer/src/utils.rs index ea645ad..ff90ae8 100644 --- a/proxmox-auto-installer/src/utils.rs +++ b/proxmox-auto-installer/src/utils.rs @@ -72,6 +72,31 @@ pub fn get_single_udev_index( Ok(dev_index.unwrap()) } +#[derive(Deserialize, Debug)] +struct IpLinksUdevInfo { + ifname: String, +} + +/// Returns vec of usable NICs +pub fn get_nic_list() -> Result> { + let ip_output = Command::new("/usr/sbin/ip") + .arg("-j") + .arg("link") + .output()?; + let parsed_links: Vec = + serde_json::from_str(String::from_utf8(ip_output.stdout)?.as_str())?; + let mut links: Vec = Vec::new(); + + for link in parsed_links { + if link.ifname == *"lo" { + continue; + } + links.push(link.ifname); + } + + Ok(links) +} + pub fn get_matched_udev_indexes( filter: BTreeMap, udev_list: &BTreeMap>, diff --git a/proxmox-autoinst-helper/Cargo.toml b/proxmox-autoinst-helper/Cargo.toml new file mode 100644 index 0000000..2a88c0f --- /dev/null +++ b/proxmox-autoinst-helper/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "proxmox-autoinst-helper" +version = "0.1.0" +edition = "2021" +authors = [ "Aaron Lauterer " ] +license = "AGPL-3" +exclude = [ "build", "debian" ] +homepage = "https://www.proxmox.com" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +anyhow = "1.0" +clap = { version = "4.0", features = ["derive"] } +glob = "0.3" +proxmox-auto-installer = { path = "../proxmox-auto-installer" } +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +toml = "0.7" +log = "0.4.20" +regex = "1.7" diff --git a/proxmox-auto-installer/src/bin/proxmox-autoinst-helper.rs b/proxmox-autoinst-helper/src/main.rs similarity index 98% rename from proxmox-auto-installer/src/bin/proxmox-autoinst-helper.rs rename to proxmox-autoinst-helper/src/main.rs index f0ee8f4..fe1cbec 100644 --- a/proxmox-auto-installer/src/bin/proxmox-autoinst-helper.rs +++ b/proxmox-autoinst-helper/src/main.rs @@ -8,8 +8,8 @@ use std::{collections::BTreeMap, fs, io::Read, path::PathBuf, process::Command}; use proxmox_auto_installer::{ answer::Answer, answer::FilterMatch, - fetch_plugins::utils::{sysinfo, get_nic_list}, - utils::{get_matched_udev_indexes, get_single_udev_index}, + sysinfo, + utils::{get_matched_udev_indexes, get_nic_list, get_single_udev_index}, }; /// This tool validates the format of an answer file. Additionally it can test match filters and @@ -291,7 +291,6 @@ fn get_disks() -> Result>> { Ok(disks) } - fn get_nics() -> Result>> { let re_props = Regex::new(r"(?m)^E: (.*)=(.*)$")?; let mut nics: BTreeMap> = BTreeMap::new(); diff --git a/proxmox-fetch-answer/Cargo.toml b/proxmox-fetch-answer/Cargo.toml new file mode 100644 index 0000000..fbcca46 --- /dev/null +++ b/proxmox-fetch-answer/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "proxmox-fetch-answer" +version = "0.1.0" +edition = "2021" +authors = [ "Aaron Lauterer " ] +license = "AGPL-3" +exclude = [ "build", "debian" ] +homepage = "https://www.proxmox.com" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +anyhow = "1.0" +clap = { version = "4.0", features = ["derive"] } +proxmox-auto-installer = { path = "../proxmox-auto-installer" } +log = "0.4.20" +ureq = { version = "2.6", features = [ "native-certs", "native-tls" ] } +rustls = { version = "0.20", features = [ "dangerous_configuration" ] } +rustls-native-certs = "0.6" +native-tls = "0.2" +sha2 = "0.10" +hex = "0.4" diff --git a/proxmox-auto-installer/src/fetch_plugins/http.rs b/proxmox-fetch-answer/src/fetch_plugins/http.rs similarity index 98% rename from proxmox-auto-installer/src/fetch_plugins/http.rs rename to proxmox-fetch-answer/src/fetch_plugins/http.rs index 4ac9afb..5772c42 100644 --- a/proxmox-auto-installer/src/fetch_plugins/http.rs +++ b/proxmox-fetch-answer/src/fetch_plugins/http.rs @@ -6,7 +6,8 @@ use std::{ process::Command, }; -use crate::fetch_plugins::utils::{post, sysinfo}; +use crate::fetch_plugins::utils::post; +use proxmox_auto_installer::sysinfo; use super::utils; diff --git a/proxmox-fetch-answer/src/fetch_plugins/mod.rs b/proxmox-fetch-answer/src/fetch_plugins/mod.rs new file mode 100644 index 0000000..d148e4c --- /dev/null +++ b/proxmox-fetch-answer/src/fetch_plugins/mod.rs @@ -0,0 +1,3 @@ +pub(crate) mod http; +pub(crate) mod partition; +pub(crate) mod utils; diff --git a/proxmox-auto-installer/src/fetch_plugins/partition.rs b/proxmox-fetch-answer/src/fetch_plugins/partition.rs similarity index 100% rename from proxmox-auto-installer/src/fetch_plugins/partition.rs rename to proxmox-fetch-answer/src/fetch_plugins/partition.rs index 0c47a62..dbe5dda 100644 --- a/proxmox-auto-installer/src/fetch_plugins/partition.rs +++ b/proxmox-fetch-answer/src/fetch_plugins/partition.rs @@ -1,6 +1,6 @@ use anyhow::{Error, Result}; -use std::{fs::read_to_string, path::Path}; use log::info; +use std::{fs::read_to_string, path::Path}; use crate::fetch_plugins::utils::mount_proxmoxinst_part; diff --git a/proxmox-auto-installer/src/fetch_plugins/utils/mod.rs b/proxmox-fetch-answer/src/fetch_plugins/utils/mod.rs similarity index 81% rename from proxmox-auto-installer/src/fetch_plugins/utils/mod.rs rename to proxmox-fetch-answer/src/fetch_plugins/utils/mod.rs index 6b4c7db..e5ea4b8 100644 --- a/proxmox-auto-installer/src/fetch_plugins/utils/mod.rs +++ b/proxmox-fetch-answer/src/fetch_plugins/utils/mod.rs @@ -1,7 +1,5 @@ use anyhow::{Error, Result}; use log::{info, warn}; -use serde::Deserialize; -use serde_json; use std::{ fs::{self, create_dir_all}, path::{Path, PathBuf}, @@ -12,8 +10,7 @@ static ANSWER_MP: &str = "/mnt/answer"; static PARTLABEL: &str = "proxmoxinst"; static SEARCH_PATH: &str = "/dev/disk/by-label"; -pub mod post; -pub mod sysinfo; +pub(crate) mod post; /// Searches for upper and lower case existence of the partlabel in the search_path /// @@ -86,28 +83,3 @@ fn check_if_mounted(target_path: &str) -> Result { } Ok(false) } - -#[derive(Deserialize, Debug)] -struct IpLinksUdevInfo { - ifname: String, -} - -/// Returns vec of usable NICs -pub fn get_nic_list() -> Result> { - let ip_output = Command::new("/usr/sbin/ip") - .arg("-j") - .arg("link") - .output()?; - let parsed_links: Vec = - serde_json::from_str(String::from_utf8(ip_output.stdout)?.as_str())?; - let mut links: Vec = Vec::new(); - - for link in parsed_links { - if link.ifname == *"lo" { - continue; - } - links.push(link.ifname); - } - - Ok(links) -} diff --git a/proxmox-auto-installer/src/fetch_plugins/utils/post.rs b/proxmox-fetch-answer/src/fetch_plugins/utils/post.rs similarity index 99% rename from proxmox-auto-installer/src/fetch_plugins/utils/post.rs rename to proxmox-fetch-answer/src/fetch_plugins/utils/post.rs index 193e920..89658f3 100644 --- a/proxmox-auto-installer/src/fetch_plugins/utils/post.rs +++ b/proxmox-fetch-answer/src/fetch_plugins/utils/post.rs @@ -16,7 +16,7 @@ use ureq::{Agent, AgentBuilder}; /// * `fingerprint` - SHA256 cert fingerprint if certificate pinning should be used. Optional. /// * `payload` - The payload to send to the server. Expected to be a JSON formatted string. pub fn call(url: String, fingerprint: Option<&str>, payload: String) -> Result { - let answer ; + let answer; if let Some(fingerprint) = fingerprint { let tls_config = ClientConfig::builder() diff --git a/proxmox-auto-installer/src/bin/proxmox-fetch-answer.rs b/proxmox-fetch-answer/src/main.rs similarity index 93% rename from proxmox-auto-installer/src/bin/proxmox-fetch-answer.rs rename to proxmox-fetch-answer/src/main.rs index 6d42df2..8c762e9 100644 --- a/proxmox-auto-installer/src/bin/proxmox-fetch-answer.rs +++ b/proxmox-fetch-answer/src/main.rs @@ -1,12 +1,12 @@ use anyhow::{anyhow, Error, Result}; +use fetch_plugins::{http::FetchFromHTTP, partition::FetchFromPartition}; use log::{error, info, LevelFilter}; -use proxmox_auto_installer::{ - fetch_plugins::{http::FetchFromHTTP, partition::FetchFromPartition}, - log::AutoInstLogger, -}; +use proxmox_auto_installer::log::AutoInstLogger; use std::io::Write; use std::process::{Command, ExitCode, Stdio}; +mod fetch_plugins; + static LOGGER: AutoInstLogger = AutoInstLogger; pub fn init_log() -> Result<()> { -- 2.39.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel