[pve-devel] [PATCH installer 2/3] common: allow lowercase and uppercase btrfs raid levels
Daniel Kral
d.kral at proxmox.com
Wed Nov 20 19:24:13 CET 2024
Allows the BTRFS RAID levels to be either lowercase or uppercase when
deserializing them from string values, i.e. currently only the config
value of `btrfs.raid` in auto-installer answer files.
Signed-off-by: Daniel Kral <d.kral at proxmox.com>
---
When we're already at it, let's do the same for btrfs...
Here's the output from `cargo expand` again, first for deserialization:
```
fn visit_str<__E>(
self,
__value: &str,
) -> _serde::__private::Result<Self::Value, __E>
where
__E: _serde::de::Error,
{
match __value {
"RAID0" | "raid0" => _serde::__private::Ok(__Field::__field0),
"RAID1" | "raid1" => _serde::__private::Ok(__Field::__field1),
"RAID10" | "raid10" => {
_serde::__private::Ok(__Field::__field2)
}
_ => {
_serde::__private::Err(
_serde::de::Error::unknown_variant(__value, VARIANTS),
)
}
}
}
```
and second for serialization:
```
impl _serde::Serialize for BtrfsRaidLevel {
fn serialize<__S>(
&self,
__serializer: __S,
) -> _serde::__private::Result<__S::Ok, __S::Error>
where
__S: _serde::Serializer,
{
match *self {
BtrfsRaidLevel::Raid0 => {
_serde::Serializer::serialize_unit_variant(
__serializer,
"BtrfsRaidLevel",
0u32,
"RAID0",
)
}
BtrfsRaidLevel::Raid1 => {
_serde::Serializer::serialize_unit_variant(
__serializer,
"BtrfsRaidLevel",
1u32,
"RAID1",
)
}
BtrfsRaidLevel::Raid10 => {
_serde::Serializer::serialize_unit_variant(
__serializer,
"BtrfsRaidLevel",
2u32,
"RAID10",
)
}
}
}
}
```
On some error (`btrfs.raid = "rAID10"`), the message is:
```
proxmox-auto-install-assistant validate-answer answer.toml
Error: Error parsing answer file: TOML parse error at line 21, column 14
|
21 | btrfs.raid = "rAID10"
| ^^^^^^^^
unknown variant `rAID10`, expected one of `raid0`, `raid1`, `raid10`
```
proxmox-installer-common/src/options.rs | 3 +++
1 file changed, 3 insertions(+)
diff --git a/proxmox-installer-common/src/options.rs b/proxmox-installer-common/src/options.rs
index 434ce26..58fadf8 100644
--- a/proxmox-installer-common/src/options.rs
+++ b/proxmox-installer-common/src/options.rs
@@ -14,8 +14,11 @@ use crate::utils::{CidrAddress, Fqdn};
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all(deserialize = "lowercase", serialize = "UPPERCASE"))]
pub enum BtrfsRaidLevel {
+ #[serde(alias = "RAID0")]
Raid0,
+ #[serde(alias = "RAID1")]
Raid1,
+ #[serde(alias = "RAID10")]
Raid10,
}
--
2.39.5
More information about the pve-devel
mailing list