public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH datacenter-manager 3/8] lib: api-types: add 'vmid' getter to ResourceView
Date: Fri, 14 Aug 2026 15:43:59 +0200	[thread overview]
Message-ID: <20260814134548.3446943-4-d.csapak@proxmox.com> (raw)
In-Reply-To: <20260814134548.3446943-1-d.csapak@proxmox.com>

This is useful for the UI to get the VMID independent of the guest type.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 lib/pdm-api-types/src/resource.rs | 18 ++++++++++++++++++
 ui/src/lib.rs                     | 10 +++++-----
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/lib/pdm-api-types/src/resource.rs b/lib/pdm-api-types/src/resource.rs
index 92d05cbc..18177dab 100644
--- a/lib/pdm-api-types/src/resource.rs
+++ b/lib/pdm-api-types/src/resource.rs
@@ -243,6 +243,24 @@ impl<'a> ResourceView<'a> {
         Some(node)
     }
 
+    /// Returns the VMID if the resource has one. Returns `None` for non guest resources.
+    pub fn vmid(&self) -> Option<u32> {
+        match self {
+            ResourceView::PveQemu(qemu) => Some(qemu.vmid),
+            ResourceView::PveLxc(lxc) => Some(lxc.vmid),
+            _ => None,
+        }
+    }
+
+    /// Returns the guest type if the resource has one. Returns `None` for non guest resources.
+    pub fn guest_type(&self) -> Option<GuestType> {
+        match self {
+            ResourceView::PveQemu(_) => Some(GuestType::Qemu),
+            ResourceView::PveLxc(_) => Some(GuestType::Lxc),
+            _ => None,
+        }
+    }
+
     pub fn resource_type(&self) -> ResourceType {
         match self {
             ResourceView::PveStorage(_) => ResourceType::PveStorage,
diff --git a/ui/src/lib.rs b/ui/src/lib.rs
index 6e89f044..d42ef42f 100644
--- a/ui/src/lib.rs
+++ b/ui/src/lib.rs
@@ -3,7 +3,7 @@ use gloo_utils::window;
 use js_sys::{Array, JsString, Object};
 use pdm_api_types::remote_updates::RemoteUpdateSummary;
 use pdm_api_types::remotes::RemoteType;
-use pdm_api_types::resource::{PveLxcResource, PveQemuResource};
+use pdm_api_types::resource::AsResourceView;
 use pdm_api_types::subscription::PdmSubscriptionInfo;
 use proxmox_deb_version::Version;
 use pwt::props::ContainerBuilder;
@@ -190,11 +190,11 @@ pub(crate) fn navigate_to<C: yew::Component>(
     if let Some(nav) = link.navigator() {
         let (prefix, id) = resource
             .and_then(|resource| {
+                if let Some(vmid) = resource.as_resource_view().vmid() {
+                    return Some((true, format!("guest+{vmid}")));
+                }
+
                 Some(match resource {
-                    pdm_client::types::Resource::PveQemu(PveQemuResource { vmid, .. })
-                    | pdm_client::types::Resource::PveLxc(PveLxcResource { vmid, .. }) => {
-                        (true, format!("guest+{vmid}"))
-                    }
                     pdm_client::types::Resource::PveNode(node) => {
                         (true, format!("node+{}", node.node))
                     }
-- 
2.47.3





  parent reply	other threads:[~2026-08-14 13:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-14 13:43 [PATCH datacenter-manager 0/8] refactor and partially fix #7371 Dominik Csapak
2026-08-14 13:43 ` [PATCH datacenter-manager 1/8] lib: add new ResourceView type and move accessors there Dominik Csapak
2026-08-14 13:43 ` [PATCH datacenter-manager 2/8] lib: api types: resource: add 'node' helper to ResourceView Dominik Csapak
2026-08-14 13:43 ` Dominik Csapak [this message]
2026-08-14 13:44 ` [PATCH datacenter-manager 4/8] ui: pve: factor out the pve-manager version extraction Dominik Csapak
2026-08-14 13:44 ` [PATCH datacenter-manager 5/8] ui: renderer: use ResourceView for rendering Dominik Csapak
2026-08-14 13:44 ` [PATCH datacenter-manager 6/8] ui: pve: tree: reuse `PveResource` for `PveTreeNode` Dominik Csapak
2026-08-14 13:44 ` [PATCH datacenter-manager 7/8] ui: pve: show ha maintenance mode for nodes Dominik Csapak
2026-08-14 13:44 ` [PATCH datacenter-manager 8/8] ui: pve: node selector: show maintenance badge with node name Dominik Csapak

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=20260814134548.3446943-4-d.csapak@proxmox.com \
    --to=d.csapak@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal