use proxmox_auto_installer::{
answer::Answer,
answer::FilterMatch,
- sysinfo,
+ sysinfo::SysInfo,
utils::{
get_matched_udev_indexes, get_nic_list, get_single_udev_index, AutoInstModes,
AutoInstSettings,
}
fn show_identifiers(_args: &CommandIdentifiers) -> Result<()> {
- match sysinfo::get_sysinfo(true) {
+ match SysInfo::as_json_pretty() {
Ok(res) => println!("{res}"),
Err(err) => eprintln!("Error fetching system identifiers: {err}"),
}
const DMI_PATH: &str = "/sys/devices/virtual/dmi/id";
-pub fn get_sysinfo(pretty: bool) -> Result<String> {
- let dmi = SystemDMI::get()?;
-
- let setup_info: SetupInfo = match fs::File::open("/run/proxmox-installer/iso-info.json") {
- Ok(iso_info_file) => {
- let reader = io::BufReader::new(iso_info_file);
- serde_json::from_reader(reader)?
- }
- Err(err) if err.kind() == io::ErrorKind::NotFound => SetupInfo::mocked(),
- Err(err) => bail!("failed to open iso-info.json - {err}"),
- };
-
- let sysinfo = SysInfo {
- product: setup_info.config,
- iso: setup_info.iso_info,
- network_interfaces: NetdevWithMac::get_all()?,
- dmi,
- };
- if pretty {
- return Ok(serde_json::to_string_pretty(&sysinfo)?);
- }
- Ok(serde_json::to_string(&sysinfo)?)
-}
-
#[derive(Debug, Serialize)]
-struct SysInfo {
+pub struct SysInfo {
product: ProductConfig,
iso: IsoInfo,
dmi: SystemDMI,
network_interfaces: Vec<NetdevWithMac>,
}
+impl SysInfo {
+ pub fn get() -> Result<Self> {
+ let setup_info: SetupInfo = match fs::File::open("/run/proxmox-installer/iso-info.json") {
+ Ok(iso_info_file) => {
+ let reader = io::BufReader::new(iso_info_file);
+ serde_json::from_reader(reader)?
+ }
+ Err(err) if err.kind() == io::ErrorKind::NotFound => SetupInfo::mocked(),
+ Err(err) => bail!("failed to open iso-info.json - {err}"),
+ };
+
+ Ok(Self {
+ product: setup_info.config,
+ iso: setup_info.iso_info,
+ network_interfaces: NetdevWithMac::get_all()?,
+ dmi: SystemDMI::get()?,
+ })
+ }
+
+ pub fn as_json_pretty() -> Result<String> {
+ let info = Self::get()?;
+ Ok(serde_json::to_string_pretty(&info)?)
+ }
+
+ pub fn as_json() -> Result<String> {
+ let info = Self::get()?;
+ Ok(serde_json::to_string(&info)?)
+ }
+}
+
#[derive(Debug, Serialize)]
struct NetdevWithMac {
/// The network link name
process::Command,
};
-use proxmox_auto_installer::{sysinfo, utils::AutoInstSettings};
+use proxmox_auto_installer::{sysinfo::SysInfo, utils::AutoInstSettings};
static ANSWER_URL_SUBDOMAIN: &str = "proxmox-auto-installer";
static ANSWER_CERT_FP_SUBDOMAIN: &str = "proxmox-auto-installer-cert-fingerprint";
}
info!("Gathering system information.");
- let payload = sysinfo::get_sysinfo(false)?;
+ let payload = SysInfo::as_json()?;
info!("Sending POST request to '{answer_url}'.");
let answer = http_post::call(answer_url, fingerprint.as_deref(), payload)?;
Ok(answer)