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 DB26891B55 for ; Thu, 4 Apr 2024 16:49:17 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E8D844686 for ; Thu, 4 Apr 2024 16:49:16 +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 ; Thu, 4 Apr 2024 16:49:11 +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 131CB45245 for ; Thu, 4 Apr 2024 16:49:11 +0200 (CEST) From: Aaron Lauterer To: pve-devel@lists.proxmox.com Date: Thu, 4 Apr 2024 16:49:00 +0200 Message-Id: <20240404144902.273800-29-a.lauterer@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240404144902.273800-1-a.lauterer@proxmox.com> References: <20240404144902.273800-1-a.lauterer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.057 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 v4 28/30] common: add deserializer for FsType 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, 04 Apr 2024 14:49:17 -0000 Signed-off-by: Aaron Lauterer --- proxmox-installer-common/Cargo.toml | 1 + proxmox-installer-common/src/options.rs | 10 ++++++--- proxmox-installer-common/src/setup.rs | 30 ++++++++++++++++++++++--- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/proxmox-installer-common/Cargo.toml b/proxmox-installer-common/Cargo.toml index bde5457..70f828a 100644 --- a/proxmox-installer-common/Cargo.toml +++ b/proxmox-installer-common/Cargo.toml @@ -8,5 +8,6 @@ exclude = [ "build", "debian" ] homepage = "https://www.proxmox.com" [dependencies] +regex = "1.7" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/proxmox-installer-common/src/options.rs b/proxmox-installer-common/src/options.rs index 1efac66..1e782f9 100644 --- a/proxmox-installer-common/src/options.rs +++ b/proxmox-installer-common/src/options.rs @@ -1,6 +1,6 @@ +use serde::Deserialize; use std::net::{IpAddr, Ipv4Addr}; use std::{cmp, fmt}; -use serde::Deserialize; use crate::setup::{ LocaleInfo, NetworkInfo, ProductConfig, ProxmoxProduct, RuntimeInfo, SetupInfo, @@ -32,8 +32,11 @@ pub enum ZfsRaidLevel { Raid0, Raid1, Raid10, + #[serde(rename = "raidz-1")] RaidZ, + #[serde(rename = "raidz-2")] RaidZ2, + #[serde(rename = "raidz-3")] RaidZ3, } @@ -51,7 +54,8 @@ impl fmt::Display for ZfsRaidLevel { } } -#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq)] +#[serde(rename_all = "lowercase")] pub enum FsType { Ext4, Xfs, @@ -226,7 +230,7 @@ pub enum AdvancedBootdiskOptions { Btrfs(BtrfsBootdiskOptions), } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, Deserialize, PartialEq)] pub struct Disk { pub index: String, pub path: String, diff --git a/proxmox-installer-common/src/setup.rs b/proxmox-installer-common/src/setup.rs index 25d0e9e..c580477 100644 --- a/proxmox-installer-common/src/setup.rs +++ b/proxmox-installer-common/src/setup.rs @@ -155,7 +155,7 @@ pub fn installer_setup(in_test_mode: bool) -> Result<(SetupInfo, LocaleInfo, Run } } -#[derive(Serialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct InstallZfsOption { pub ashift: usize, #[serde(serialize_with = "serialize_as_display")] @@ -402,11 +402,11 @@ pub fn spawn_low_level_installer(test_mode: bool) -> io::Result } /// See Proxmox::Install::Config -#[derive(Serialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct InstallConfig { pub autoreboot: usize, - #[serde(serialize_with = "serialize_fstype")] + #[serde(serialize_with = "serialize_fstype", deserialize_with = "deserialize_fs_type")] pub filesys: FsType, pub hdsize: f64, #[serde(skip_serializing_if = "Option::is_none")] @@ -481,3 +481,27 @@ where serializer.collect_str(value) } + +pub fn deserialize_fs_type<'de, D>(deserializer: D) -> Result +where + D: Deserializer<'de>, +{ + use FsType::*; + let de_fs: String = Deserialize::deserialize(deserializer)?; + + println!("deserializing fstype"); + match de_fs.as_str() { + "ext4" => Ok(Ext4), + "xfs" => Ok(Xfs), + "zfs (RAID0)" => Ok(Zfs(ZfsRaidLevel::Raid0)), + "zfs (RAID1)" => Ok(Zfs(ZfsRaidLevel::Raid1)), + "zfs (RAID10)" => Ok(Zfs(ZfsRaidLevel::Raid10)), + "zfs (RAIDZ-1)" => Ok(Zfs(ZfsRaidLevel::RaidZ)), + "zfs (RAIDZ-2)" => Ok(Zfs(ZfsRaidLevel::RaidZ2)), + "zfs (RAIDZ-3)" => Ok(Zfs(ZfsRaidLevel::RaidZ3)), + "btrfs (RAID0)" => Ok(Btrfs(BtrfsRaidLevel::Raid0)), + "btrfs (RAID1)" => Ok(Btrfs(BtrfsRaidLevel::Raid1)), + "btrfs (RAID10)" => Ok(Btrfs(BtrfsRaidLevel::Raid10)), + _ => Err(de::Error::custom("could not find file system: {de_fs}")) + } +} -- 2.39.2