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 BE44ABC48C for ; Thu, 28 Mar 2024 14:50:31 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A485DC280 for ; Thu, 28 Mar 2024 14:50:31 +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 ; Thu, 28 Mar 2024 14:50:30 +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 3F1A842900 for ; Thu, 28 Mar 2024 14:50:30 +0100 (CET) From: Aaron Lauterer To: pve-devel@lists.proxmox.com Date: Thu, 28 Mar 2024 14:49:59 +0100 Message-Id: <20240328135028.504520-2-a.lauterer@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240328135028.504520-1-a.lauterer@proxmox.com> References: <20240328135028.504520-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 Subject: [pve-devel] [PATCH v3 01/30] tui: common: move InstallConfig struct to common crate 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: Thu, 28 Mar 2024 13:50:31 -0000 It describes the data structure expected by the low-level-installer. We do this so we can use it in more than the TUI installer, for example the planned auto installer. Make the members public so we can easily implement a custom From method for each dependent crate. Signed-off-by: Aaron Lauterer --- proxmox-installer-common/src/setup.rs | 86 +++++++++++++++- proxmox-tui-installer/src/setup.rs | 98 +------------------ .../src/views/install_progress.rs | 4 +- 3 files changed, 90 insertions(+), 98 deletions(-) diff --git a/proxmox-installer-common/src/setup.rs b/proxmox-installer-common/src/setup.rs index 472e1f2..03beb77 100644 --- a/proxmox-installer-common/src/setup.rs +++ b/proxmox-installer-common/src/setup.rs @@ -12,7 +12,10 @@ use std::{ use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; use crate::{ - options::{Disk, ZfsBootdiskOptions, ZfsChecksumOption, ZfsCompressOption}, + options::{ + BtrfsRaidLevel, Disk, FsType, ZfsBootdiskOptions, ZfsChecksumOption, ZfsCompressOption, + ZfsRaidLevel, + }, utils::CidrAddress, }; @@ -387,3 +390,84 @@ pub fn spawn_low_level_installer(test_mode: bool) -> io::Result .stdout(Stdio::piped()) .spawn() } + +/// See Proxmox::Install::Config +#[derive(Serialize)] +pub struct InstallConfig { + pub autoreboot: usize, + + #[serde(serialize_with = "serialize_fstype")] + pub filesys: FsType, + pub hdsize: f64, + #[serde(skip_serializing_if = "Option::is_none")] + pub swapsize: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub maxroot: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub minfree: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub maxvz: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + pub zfs_opts: Option, + + #[serde( + serialize_with = "serialize_disk_opt", + skip_serializing_if = "Option::is_none" + )] + pub target_hd: Option, + #[serde(skip_serializing_if = "HashMap::is_empty")] + pub disk_selection: HashMap, + + pub country: String, + pub timezone: String, + pub keymap: String, + + pub password: String, + pub mailto: String, + + pub mngmt_nic: String, + + pub hostname: String, + pub domain: String, + #[serde(serialize_with = "serialize_as_display")] + pub cidr: CidrAddress, + pub gateway: IpAddr, + pub dns: IpAddr, +} + +fn serialize_disk_opt(value: &Option, serializer: S) -> Result +where + S: Serializer, +{ + if let Some(disk) = value { + serializer.serialize_str(&disk.path) + } else { + serializer.serialize_none() + } +} + +fn serialize_fstype(value: &FsType, serializer: S) -> Result +where + S: Serializer, +{ + use FsType::*; + let value = match value { + // proxinstall::$fssetup + Ext4 => "ext4", + Xfs => "xfs", + // proxinstall::get_zfs_raid_setup() + Zfs(ZfsRaidLevel::Raid0) => "zfs (RAID0)", + Zfs(ZfsRaidLevel::Raid1) => "zfs (RAID1)", + Zfs(ZfsRaidLevel::Raid10) => "zfs (RAID10)", + Zfs(ZfsRaidLevel::RaidZ) => "zfs (RAIDZ-1)", + Zfs(ZfsRaidLevel::RaidZ2) => "zfs (RAIDZ-2)", + Zfs(ZfsRaidLevel::RaidZ3) => "zfs (RAIDZ-3)", + // proxinstall::get_btrfs_raid_setup() + Btrfs(BtrfsRaidLevel::Raid0) => "btrfs (RAID0)", + Btrfs(BtrfsRaidLevel::Raid1) => "btrfs (RAID1)", + Btrfs(BtrfsRaidLevel::Raid10) => "btrfs (RAID10)", + }; + + serializer.collect_str(value) +} diff --git a/proxmox-tui-installer/src/setup.rs b/proxmox-tui-installer/src/setup.rs index 79421d7..e816c12 100644 --- a/proxmox-tui-installer/src/setup.rs +++ b/proxmox-tui-installer/src/setup.rs @@ -1,59 +1,11 @@ -use std::{collections::HashMap, fmt, net::IpAddr}; - -use serde::{Serialize, Serializer}; +use std::collections::HashMap; use crate::options::InstallerOptions; use proxmox_installer_common::{ - options::{AdvancedBootdiskOptions, BtrfsRaidLevel, Disk, FsType, ZfsRaidLevel}, - setup::InstallZfsOption, - utils::CidrAddress, + options::AdvancedBootdiskOptions, + setup::InstallConfig, }; -/// See Proxmox::Install::Config -#[derive(Serialize)] -pub struct InstallConfig { - autoreboot: usize, - - #[serde(serialize_with = "serialize_fstype")] - filesys: FsType, - hdsize: f64, - #[serde(skip_serializing_if = "Option::is_none")] - swapsize: Option, - #[serde(skip_serializing_if = "Option::is_none")] - maxroot: Option, - #[serde(skip_serializing_if = "Option::is_none")] - minfree: Option, - #[serde(skip_serializing_if = "Option::is_none")] - maxvz: Option, - - #[serde(skip_serializing_if = "Option::is_none")] - zfs_opts: Option, - - #[serde( - serialize_with = "serialize_disk_opt", - skip_serializing_if = "Option::is_none" - )] - target_hd: Option, - #[serde(skip_serializing_if = "HashMap::is_empty")] - disk_selection: HashMap, - - country: String, - timezone: String, - keymap: String, - - password: String, - mailto: String, - - mngmt_nic: String, - - hostname: String, - domain: String, - #[serde(serialize_with = "serialize_as_display")] - cidr: CidrAddress, - gateway: IpAddr, - dns: IpAddr, -} - impl From for InstallConfig { fn from(options: InstallerOptions) -> Self { let mut config = Self { @@ -121,47 +73,3 @@ impl From for InstallConfig { config } } - -fn serialize_disk_opt(value: &Option, serializer: S) -> Result -where - S: Serializer, -{ - if let Some(disk) = value { - serializer.serialize_str(&disk.path) - } else { - serializer.serialize_none() - } -} - -fn serialize_fstype(value: &FsType, serializer: S) -> Result -where - S: Serializer, -{ - use FsType::*; - let value = match value { - // proxinstall::$fssetup - Ext4 => "ext4", - Xfs => "xfs", - // proxinstall::get_zfs_raid_setup() - Zfs(ZfsRaidLevel::Raid0) => "zfs (RAID0)", - Zfs(ZfsRaidLevel::Raid1) => "zfs (RAID1)", - Zfs(ZfsRaidLevel::Raid10) => "zfs (RAID10)", - Zfs(ZfsRaidLevel::RaidZ) => "zfs (RAIDZ-1)", - Zfs(ZfsRaidLevel::RaidZ2) => "zfs (RAIDZ-2)", - Zfs(ZfsRaidLevel::RaidZ3) => "zfs (RAIDZ-3)", - // proxinstall::get_btrfs_raid_setup() - Btrfs(BtrfsRaidLevel::Raid0) => "btrfs (RAID0)", - Btrfs(BtrfsRaidLevel::Raid1) => "btrfs (RAID1)", - Btrfs(BtrfsRaidLevel::Raid10) => "btrfs (RAID10)", - }; - - serializer.collect_str(value) -} - -fn serialize_as_display(value: &T, serializer: S) -> Result -where - S: Serializer, - T: fmt::Display, -{ - serializer.collect_str(value) -} diff --git a/proxmox-tui-installer/src/views/install_progress.rs b/proxmox-tui-installer/src/views/install_progress.rs index c2c9ddf..56356ad 100644 --- a/proxmox-tui-installer/src/views/install_progress.rs +++ b/proxmox-tui-installer/src/views/install_progress.rs @@ -13,8 +13,8 @@ use std::{ time::Duration, }; -use crate::{abort_install_button, prompt_dialog, setup::InstallConfig, InstallerState}; -use proxmox_installer_common::setup::spawn_low_level_installer; +use crate::{abort_install_button, prompt_dialog, InstallerState}; +use proxmox_installer_common::setup::{InstallConfig, spawn_low_level_installer}; pub struct InstallProgressView { view: PaddedView, -- 2.39.2