From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 598111FF348 for ; Wed, 17 Apr 2024 14:33:29 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8E33A5DAF; Wed, 17 Apr 2024 14:31:49 +0200 (CEST) From: Aaron Lauterer To: pve-devel@lists.proxmox.com Date: Wed, 17 Apr 2024 14:30:33 +0200 Message-Id: <20240417123108.212720-2-a.lauterer@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240417123108.212720-1-a.lauterer@proxmox.com> References: <20240417123108.212720-1-a.lauterer@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.047 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 v6 01/36] 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: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" 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. Tested-by: Christoph Heiss Reviewed-by: Christoph Heiss 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 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel