From: Stefan Hanreich <s.hanreich@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH proxmox-yew-comp v2 1/1] pve: qemu: handle fallback enum variants
Date: Thu, 13 Nov 2025 16:09:29 +0100 [thread overview]
Message-ID: <20251113150934.611263-6-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20251113150934.611263-1-s.hanreich@proxmox.com>
pve-api-types introduced a fallback variant for all enums returned by
the Proxmox VE API. Add code for handling those new variants to the
use sites of those enums.
For AMD SEV and BIOS it is sufficient to print the unknown values,
since the Comboboxes prevent the re-submission of unknown values
anyway, due to the force_selection property being set to true.
For the OS type, we cannot uniquely identify if an OS is Windows or
not, since it is possible for an unknown value to be either Windows or
something else. For that case, the respective input field (machine
type), that needs this information to render content, is simply
disabled.
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
.../qemu_property/qemu_amd_sev_property.rs | 1 +
.../pve/qemu_property/qemu_bios_property.rs | 1 +
.../qemu_property/qemu_machine_property.rs | 20 +++++++++++--------
3 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/src/form/pve/qemu_property/qemu_amd_sev_property.rs b/src/form/pve/qemu_property/qemu_amd_sev_property.rs
index 72d2dfd..30be125 100644
--- a/src/form/pve/qemu_property/qemu_amd_sev_property.rs
+++ b/src/form/pve/qemu_property/qemu_amd_sev_property.rs
@@ -118,6 +118,7 @@ pub fn qemu_amd_sev_property(mobile: bool) -> EditableProperty {
PveQemuSevFmtType::Std => "AMD SEV",
PveQemuSevFmtType::Es => "AMD SEV-ES",
PveQemuSevFmtType::Snp => "AMD SEV-SNP",
+ PveQemuSevFmtType::UnknownEnumValue(value) => &format!("unknown '{value}'"),
};
format!("{text} ({v})").into()
}
diff --git a/src/form/pve/qemu_property/qemu_bios_property.rs b/src/form/pve/qemu_property/qemu_bios_property.rs
index 1ae78b3..4acfda4 100644
--- a/src/form/pve/qemu_property/qemu_bios_property.rs
+++ b/src/form/pve/qemu_property/qemu_bios_property.rs
@@ -59,6 +59,7 @@ pub fn qemu_bios_property(mobile: bool) -> EditableProperty {
Ok(bios) => match bios {
QemuConfigBios::Seabios => "SeaBIOS".into(),
QemuConfigBios::Ovmf => "OVMF (UEFI)".into(),
+ QemuConfigBios::UnknownEnumValue(value) => format!("unknown '{value}'").into(),
},
Err(_) => v.into(),
},
diff --git a/src/form/pve/qemu_property/qemu_machine_property.rs b/src/form/pve/qemu_property/qemu_machine_property.rs
index 31ace00..02c1bdb 100644
--- a/src/form/pve/qemu_property/qemu_machine_property.rs
+++ b/src/form/pve/qemu_property/qemu_machine_property.rs
@@ -15,7 +15,7 @@ use crate::form::pve::QemuMachineVersionSelector;
use crate::pve_api_types::QemuMachineType;
use crate::{EditableProperty, PropertyEditorState, RenderPropertyInputPanelFn};
-fn ostype_is_windows(ostype: &QemuConfigOstype) -> bool {
+fn ostype_is_windows(ostype: &QemuConfigOstype) -> Option<bool> {
match ostype {
QemuConfigOstype::Wxp
| QemuConfigOstype::W2k
@@ -25,11 +25,12 @@ fn ostype_is_windows(ostype: &QemuConfigOstype) -> bool {
| QemuConfigOstype::Win7
| QemuConfigOstype::Win8
| QemuConfigOstype::Win10
- | QemuConfigOstype::Win11 => true,
+ | QemuConfigOstype::Win11 => Some(true),
QemuConfigOstype::L24
| QemuConfigOstype::L26
| QemuConfigOstype::Solaris
- | QemuConfigOstype::Other => false,
+ | QemuConfigOstype::Other => Some(false),
+ QemuConfigOstype::UnknownEnumValue(_) => None,
}
}
@@ -91,12 +92,14 @@ fn input_panel(mobile: bool) -> RenderPropertyInputPanelFn {
};
let add_version_selector = |panel: &mut InputPanel, ty| {
- let disabled = machine_type != ty;
+ let is_windows = ostype_is_windows(&ostype);
+ let disabled = machine_type != ty || is_windows.is_none();
let name = get_version_prop_name(ty.to_string());
+
let field = QemuMachineVersionSelector::new(ty)
.name(name)
- .disabled(machine_type != ty)
- .required(ostype_is_windows(&ostype))
+ .disabled(disabled)
+ .required(is_windows.unwrap_or_default())
.submit(false);
panel.add_field_with_options(
FieldPosition::Left,
@@ -181,8 +184,9 @@ pub fn qemu_machine_property(mobile: bool) -> EditableProperty {
serde_json::from_value(record["ostype"].clone()).ok();
let ostype = ostype.unwrap_or(QemuConfigOstype::Other);
match (v.as_str(), ostype_is_windows(&ostype)) {
- (None | Some("pc"), true) => "pc-i440fx-5.1".into(),
- (Some("q35"), true) => "pc-q35-5.1".into(),
+ (_, None) => format!("unknown ostype: {v}").into(),
+ (None | Some("pc"), Some(true)) => "pc-i440fx-5.1".into(),
+ (Some("q35"), Some(true)) => "pc-q35-5.1".into(),
(Some(machine), _) => machine.into(),
(None, _) => placeholder().into(),
}
--
2.47.3
_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel
next prev parent reply other threads:[~2025-11-13 15:09 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-13 15:09 [pdm-devel] [RFC proxmox{, -yew-comp, -datacenter-manager}/yew-mobile-gui v2 0/7] Add fallback variant to enum properties in Proxmox VE Rust API types Stefan Hanreich
2025-11-13 15:09 ` [pdm-devel] [PATCH proxmox v2 1/4] pve-api-types: add FixedString type Stefan Hanreich
2025-11-13 15:09 ` [pdm-devel] [PATCH proxmox v2 2/4] pve-api-types: generate fallback variant for enums Stefan Hanreich
2025-11-13 15:09 ` [pdm-devel] [PATCH proxmox v2 3/4] pve-api-types: regenerate Stefan Hanreich
2025-11-13 15:09 ` [pdm-devel] [PATCH proxmox v2 4/4] pve-api-types: sdn: handle fallback variant Stefan Hanreich
2025-11-13 15:09 ` Stefan Hanreich [this message]
2025-11-13 15:09 ` [pdm-devel] [PATCH proxmox-datacenter-manager v2 1/1] tree-wide: handle new unknown enum variants Stefan Hanreich
2025-11-13 15:09 ` [pdm-devel] [PATCH pve-yew-mobile-gui v2 1/1] tree-wide: handle fallback enum values Stefan Hanreich
2025-11-13 20:33 ` [pdm-devel] [RFC proxmox{, -yew-comp, -datacenter-manager}/yew-mobile-gui v2 0/7] Add fallback variant to enum properties in Proxmox VE Rust API types Thomas Lamprecht
2025-11-13 21:28 ` [pdm-devel] applied-series: " Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251113150934.611263-6-s.hanreich@proxmox.com \
--to=s.hanreich@proxmox.com \
--cc=pdm-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.