From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 4BFFD93DCC for ; Wed, 21 Feb 2024 12:08:17 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 532A115788 for ; Wed, 21 Feb 2024 12:08:15 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 21 Feb 2024 12:08:11 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 011B04446A for ; Wed, 21 Feb 2024 12:08:11 +0100 (CET) From: Aaron Lauterer To: pve-devel@lists.proxmox.com Date: Wed, 21 Feb 2024 12:08:02 +0100 Message-Id: <20240221110805.931925-20-a.lauterer@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240221110805.931925-1-a.lauterer@proxmox.com> References: <20240221110805.931925-1-a.lauterer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.063 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 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH v2 19/22] auto-installer: helper: add subcommand to view indentifiers 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: , X-List-Received-Date: Wed, 21 Feb 2024 11:08:17 -0000 It will collect the information from the current system and show the payload of identifiers that will be send. To avoid confusion, the subcommands for the device info and filter matching have been renamed. Signed-off-by: Aaron Lauterer --- .../src/bin/proxmox-autoinst-helper.rs | 54 +++++++++---------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/proxmox-auto-installer/src/bin/proxmox-autoinst-helper.rs b/proxmox-auto-installer/src/bin/proxmox-autoinst-helper.rs index 9be7876..0ce85b4 100644 --- a/proxmox-auto-installer/src/bin/proxmox-autoinst-helper.rs +++ b/proxmox-auto-installer/src/bin/proxmox-autoinst-helper.rs @@ -2,12 +2,13 @@ use anyhow::{bail, Result}; use clap::{Args, Parser, Subcommand, ValueEnum}; use glob::Pattern; use regex::Regex; -use serde::{Deserialize, Serialize}; +use serde::Serialize; 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}, }; @@ -23,13 +24,14 @@ struct Cli { #[derive(Subcommand, Debug)] enum Commands { Answer(CommandAnswer), - Match(CommandMatch), - Info(CommandInfo), + DeviceMatch(CommandDeviceMatch), + DeviceInfo(CommandDeviceInfo), + Identifiers(CommandIdentifiers), } /// Show device information that can be used for filters #[derive(Args, Debug)] -struct CommandInfo { +struct CommandDeviceInfo { /// For which device type information should be shown #[arg(name="type", short, long, value_enum, default_value_t=AllDeviceTypes::All)] device: AllDeviceTypes, @@ -52,7 +54,7 @@ struct CommandInfo { /// proxmox-installer-filter match --filter-match all disk 'ID_SERIAL_SHORT=*2222*' 'DEVNAME=*nvme*' #[derive(Args, Debug)] #[command(verbatim_doc_comment)] -struct CommandMatch { +struct CommandDeviceMatch { /// Device type to match the filter against r#type: Devicetype, @@ -72,6 +74,11 @@ struct CommandAnswer { path: PathBuf, } +/// Show identifiers for the current machine. This information is part of the POST request to fetch +/// an answer file. +#[derive(Args, Debug)] +struct CommandIdentifiers {} + #[derive(Args, Debug)] struct GlobalOpts { /// Output format @@ -107,9 +114,10 @@ struct Devs { fn main() { let args = Cli::parse(); let res = match &args.command { - Commands::Info(args) => info(args), - Commands::Match(args) => match_filter(args), + Commands::DeviceInfo(args) => info(args), + Commands::DeviceMatch(args) => match_filter(args), Commands::Answer(args) => validate_answer(args), + Commands::Identifiers(args) => show_identifiers(args), }; if let Err(err) = res { eprintln!("{err}"); @@ -117,7 +125,7 @@ fn main() { } } -fn info(args: &CommandInfo) -> Result<()> { +fn info(args: &CommandDeviceInfo) -> Result<()> { let mut devs = Devs { disks: None, nics: None, @@ -139,7 +147,7 @@ fn info(args: &CommandInfo) -> Result<()> { Ok(()) } -fn match_filter(args: &CommandMatch) -> Result<()> { +fn match_filter(args: &CommandDeviceMatch) -> Result<()> { let devs: BTreeMap> = match args.r#type { Devicetype::Disk => get_disks().unwrap(), Devicetype::Network => get_nics().unwrap(), @@ -200,6 +208,14 @@ fn validate_answer(args: &CommandAnswer) -> Result<()> { Ok(()) } +fn show_identifiers(_args: &CommandIdentifiers) -> Result<()> { + match sysinfo::get_sysinfo(true) { + Ok(res) => println!("{res}"), + Err(err) => eprintln!("Error fetching system identifiers: {err}"), + } + Ok(()) +} + fn get_disks() -> Result>> { let unwantend_block_devs = vec![ "ram[0-9]*", @@ -270,30 +286,12 @@ fn get_disks() -> Result>> { Ok(disks) } -#[derive(Deserialize, Debug)] -struct IpLinksInfo { - ifname: String, -} fn get_nics() -> Result>> { let re_props = Regex::new(r"(?m)^E: (.*)=(.*)$")?; let mut nics: BTreeMap> = BTreeMap::new(); - 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); - } - + let links = get_nic_list()?; for link in links { let path = format!("/sys/class/net/{link}"); -- 2.39.2