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 362639728C for ; Tue, 16 Apr 2024 17:33:42 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 45A171F4BC for ; Tue, 16 Apr 2024 17:33:37 +0200 (CEST) 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 ; Tue, 16 Apr 2024 17:33:33 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 5473C45AC8 for ; Tue, 16 Apr 2024 17:33:33 +0200 (CEST) From: Aaron Lauterer To: pve-devel@lists.proxmox.com Date: Tue, 16 Apr 2024 17:33:11 +0200 Message-Id: <20240416153325.1154224-23-a.lauterer@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240416153325.1154224-1-a.lauterer@proxmox.com> References: <20240416153325.1154224-1-a.lauterer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.052 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 Subject: [pve-devel] [PATCH installer v5 22/36] 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: Tue, 16 Apr 2024 15:33:42 -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 058d5ff..f0ee8f4 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 { ValidateAnswer(CommandValidateAnswer), - 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-autoinst-helper 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, @@ -74,6 +76,11 @@ struct CommandValidateAnswer { debug: bool, } +/// 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 @@ -109,9 +116,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::ValidateAnswer(args) => validate_answer(args), + Commands::DeviceInfo(args) => info(args), + Commands::DeviceMatch(args) => match_filter(args), + Commands::Identifiers(args) => show_identifiers(args), }; if let Err(err) = res { eprintln!("{err}"); @@ -119,7 +127,7 @@ fn main() { } } -fn info(args: &CommandInfo) -> Result<()> { +fn info(args: &CommandDeviceInfo) -> Result<()> { let mut devs = Devs { disks: None, nics: None, @@ -141,7 +149,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(), @@ -205,6 +213,14 @@ fn validate_answer(args: &CommandValidateAnswer) -> 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]*", @@ -275,30 +291,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