public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Aaron Lauterer <a.lauterer@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer v4 26/30] auto installer: factor out fetch-answer and autoinst-helper
Date: Thu,  4 Apr 2024 16:48:58 +0200	[thread overview]
Message-ID: <20240404144902.273800-27-a.lauterer@proxmox.com> (raw)
In-Reply-To: <20240404144902.273800-1-a.lauterer@proxmox.com>

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.

Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
---
 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<Vec<String>> {
+    let ip_output = Command::new("/usr/sbin/ip")
+        .arg("-j")
+        .arg("link")
+        .output()?;
+    let parsed_links: Vec<IpLinksUdevInfo> =
+        serde_json::from_str(String::from_utf8(ip_output.stdout)?.as_str())?;
+    let mut links: Vec<String> = 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<String, String>,
     udev_list: &BTreeMap<String, BTreeMap<String, String>>,
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 <a.lauterer@proxmox.com>" ]
+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<BTreeMap<String, BTreeMap<String, String>>> {
     Ok(disks)
 }
 
-
 fn get_nics() -> Result<BTreeMap<String, BTreeMap<String, String>>> {
     let re_props = Regex::new(r"(?m)^E: (.*)=(.*)$")?;
     let mut nics: BTreeMap<String, BTreeMap<String, String>> = 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 <a.lauterer@proxmox.com>" ]
+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<bool> {
     }
     Ok(false)
 }
-
-#[derive(Deserialize, Debug)]
-struct IpLinksUdevInfo {
-    ifname: String,
-}
-
-/// Returns vec of usable NICs
-pub fn get_nic_list() -> Result<Vec<String>> {
-    let ip_output = Command::new("/usr/sbin/ip")
-        .arg("-j")
-        .arg("link")
-        .output()?;
-    let parsed_links: Vec<IpLinksUdevInfo> =
-        serde_json::from_str(String::from_utf8(ip_output.stdout)?.as_str())?;
-    let mut links: Vec<String> = 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<String> {
-    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





  parent reply	other threads:[~2024-04-04 14:54 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-04 14:48 [pve-devel] [PATCH installer v4 00/30] add automated/unattended installation Aaron Lauterer
2024-04-04 14:48 ` [pve-devel] [PATCH installer v4 01/30] tui: common: move InstallConfig struct to common crate Aaron Lauterer
2024-04-04 14:48 ` [pve-devel] [PATCH installer v4 02/30] common: make InstallZfsOption members public Aaron Lauterer
2024-04-04 14:48 ` [pve-devel] [PATCH installer v4 03/30] common: tui: use BTreeMap for predictable ordering Aaron Lauterer
2024-04-04 14:48 ` [pve-devel] [PATCH installer v4 04/30] common: utils: add deserializer for CidrAddress Aaron Lauterer
2024-04-04 14:48 ` [pve-devel] [PATCH installer v4 05/30] common: options: add Deserialize trait Aaron Lauterer
2024-04-04 14:48 ` [pve-devel] [PATCH installer v4 06/30] low-level: add dump-udev command Aaron Lauterer
2024-04-04 14:48 ` [pve-devel] [PATCH installer v4 07/30] add auto-installer crate Aaron Lauterer
2024-04-04 14:48 ` [pve-devel] [PATCH installer v4 08/30] auto-installer: add dependencies Aaron Lauterer
2024-04-04 14:48 ` [pve-devel] [PATCH installer v4 09/30] auto-installer: add answer file definition Aaron Lauterer
2024-04-04 14:48 ` [pve-devel] [PATCH installer v4 10/30] auto-installer: add struct to hold udev info Aaron Lauterer
2024-04-04 14:48 ` [pve-devel] [PATCH installer v4 11/30] auto-installer: add utils Aaron Lauterer
2024-04-04 14:48 ` [pve-devel] [PATCH installer v4 12/30] auto-installer: add simple logging Aaron Lauterer
2024-04-04 14:48 ` [pve-devel] [PATCH installer v4 13/30] auto-installer: add tests for answer file parsing Aaron Lauterer
2024-04-04 14:48 ` [pve-devel] [PATCH installer v4 14/30] auto-installer: add auto-installer binary Aaron Lauterer
2024-04-04 14:48 ` [pve-devel] [PATCH installer v4 15/30] auto-installer: add fetch answer binary Aaron Lauterer
2024-04-04 14:48 ` [pve-devel] [PATCH installer v4 16/30] unconfigured: add proxauto as option to start auto installer Aaron Lauterer
2024-04-04 14:48 ` [pve-devel] [PATCH installer v4 17/30] auto-installer: use glob crate for pattern matching Aaron Lauterer
2024-04-04 14:48 ` [pve-devel] [PATCH installer v4 18/30] auto-installer: utils: make get_udev_index functions public Aaron Lauterer
2024-04-04 14:48 ` [pve-devel] [PATCH installer v4 19/30] auto-installer: add proxmox-autoinst-helper tool Aaron Lauterer
2024-04-04 14:48 ` [pve-devel] [PATCH installer v4 20/30] common: add Display trait to ProxmoxProduct Aaron Lauterer
2024-04-04 14:48 ` [pve-devel] [PATCH installer v4 21/30] auto-installer: fetch: add gathering of system identifiers and restructure code Aaron Lauterer
2024-04-04 14:48 ` [pve-devel] [PATCH installer v4 22/30] auto-installer: helper: add subcommand to view indentifiers Aaron Lauterer
2024-04-04 14:48 ` [pve-devel] [PATCH installer v4 23/30] auto-installer: fetch: add http post utility module Aaron Lauterer
2024-04-04 14:48 ` [pve-devel] [PATCH installer v4 24/30] auto-installer: fetch: add http plugin to fetch answer Aaron Lauterer
2024-04-04 14:48 ` [pve-devel] [PATCH installer v4 25/30] control: update build depends for auto installer Aaron Lauterer
2024-04-04 14:48 ` Aaron Lauterer [this message]
2024-04-04 14:48 ` [pve-devel] [PATCH installer v4 27/30] low-level: write low level config to /tmp Aaron Lauterer
2024-04-04 14:49 ` [pve-devel] [PATCH installer v4 28/30] common: add deserializer for FsType Aaron Lauterer
2024-04-04 14:49 ` [pve-devel] [PATCH installer v4 29/30] common: skip target_hd when deserializing InstallConfig Aaron Lauterer
2024-04-04 14:49 ` [pve-devel] [PATCH installer v4 30/30] add proxmox-chroot utility Aaron Lauterer
2024-04-05 12:38 ` [pve-devel] [PATCH installer v4 00/30] add automated/unattended installation Christoph Heiss
2024-04-05 14:25 ` [pve-devel] [PATCH v4 installer 31/30 follow-up] auto-installer: answer: deny unknown fields Aaron Lauterer
2024-04-09  9:20   ` Christoph Heiss

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240404144902.273800-27-a.lauterer@proxmox.com \
    --to=a.lauterer@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal