all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pdm-devel] [PATCH datacenter-manager 1/2] ui: use better schema handling of `keyAlias` property strings
@ 2025-01-16  9:22 Dominik Csapak
  2025-01-16  9:22 ` [pdm-devel] [PATCH datacenter-manager 2/2] ui: use new `iter()` method of ArrayMap properties Dominik Csapak
  2025-01-16  9:58 ` [pdm-devel] applied: [PATCH datacenter-manager 1/2] ui: use better schema handling of `keyAlias` property strings Dietmar Maurer
  0 siblings, 2 replies; 3+ messages in thread
From: Dominik Csapak @ 2025-01-16  9:22 UTC (permalink / raw)
  To: pdm-devel

proxmox-schema can now handle that and we can remove the empty
ObjectSchema hack.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 ui/src/widget/pve_migrate_mapping.rs | 39 ++++++++++++++--------------
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/ui/src/widget/pve_migrate_mapping.rs b/ui/src/widget/pve_migrate_mapping.rs
index 79d15cf..928b746 100644
--- a/ui/src/widget/pve_migrate_mapping.rs
+++ b/ui/src/widget/pve_migrate_mapping.rs
@@ -4,7 +4,7 @@ use anyhow::{bail, Error};
 use serde_json::Value;
 use yew::{html::IntoPropValue, virtual_dom::Key, AttrValue, Properties};
 
-use proxmox_schema::{ObjectSchema, Schema};
+use proxmox_schema::property_string::PropertyString;
 use pwt::{
     props::{ContainerBuilder, CssBorderBuilder, ExtractPrimaryKey, FieldBuilder, WidgetBuilder},
     state::Store,
@@ -19,7 +19,7 @@ use pwt::{
 };
 use pwt_macros::{builder, widget};
 
-use pdm_client::types::StorageContent;
+use pdm_client::types::{LxcConfigNet, QemuConfigNet, StorageContent};
 
 use crate::pve::{
     utils::{foreach_drive_lxc, foreach_drive_qemu},
@@ -115,11 +115,6 @@ pub struct PveMigrateMapComp {
     _async_pool: AsyncPool,
 }
 
-// HACK!, our rust schema does not support `keyAlias`  yet, so we parse it into a generic value`
-static NET_WORKAROUND_SCHEMA: Schema = ObjectSchema::new("", &[])
-    .additional_properties(true)
-    .schema();
-
 impl PveMigrateMapComp {
     async fn load_storages(
         remote: AttrValue,
@@ -158,12 +153,15 @@ impl PveMigrateMapComp {
 
                 let mut networks = HashSet::new();
 
-                let nets = serde_json::to_value(&config.net)?;
-                for (_key, net) in nets.as_object().unwrap() {
-                    let net = NET_WORKAROUND_SCHEMA.parse_property_string(net.as_str().unwrap())?;
-
-                    if let Some(bridge) = net.get("bridge") {
-                        networks.insert(bridge.as_str().unwrap().to_string());
+                for (idx, net) in config.net.iter() {
+                    let key = format!("net{idx}");
+                    match net.parse::<PropertyString<QemuConfigNet>>() {
+                        Ok(net) => {
+                            if let Some(bridge) = net.into_inner().bridge {
+                                networks.insert(bridge);
+                            }
+                        }
+                        Err(err) => log::error!("could not parse {key}: {err}"),
                     }
                 }
 
@@ -204,12 +202,15 @@ impl PveMigrateMapComp {
 
                 let mut networks = HashSet::new();
 
-                let nets = serde_json::to_value(&config.net)?;
-                for (_key, net) in nets.as_object().unwrap() {
-                    let net = NET_WORKAROUND_SCHEMA.parse_property_string(net.as_str().unwrap())?;
-
-                    if let Some(bridge) = net.get("bridge") {
-                        networks.insert(bridge.as_str().unwrap().to_string());
+                for (idx, net) in (&*config.net).into_iter() {
+                    let key = format!("net{idx}");
+                    match net.parse::<PropertyString<LxcConfigNet>>() {
+                        Ok(net) => {
+                            if let Some(bridge) = net.into_inner().bridge {
+                                networks.insert(bridge);
+                            }
+                        }
+                        Err(err) => log::error!("could not parse {key}: {err}"),
                     }
                 }
 
-- 
2.39.5



_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-01-16  9:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-16  9:22 [pdm-devel] [PATCH datacenter-manager 1/2] ui: use better schema handling of `keyAlias` property strings Dominik Csapak
2025-01-16  9:22 ` [pdm-devel] [PATCH datacenter-manager 2/2] ui: use new `iter()` method of ArrayMap properties Dominik Csapak
2025-01-16  9:58 ` [pdm-devel] applied: [PATCH datacenter-manager 1/2] ui: use better schema handling of `keyAlias` property strings Dietmar Maurer

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.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal