From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id C73C81FF0AA for ; Fri, 21 Aug 2026 14:32:06 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id C7C0B215B8; Fri, 21 Aug 2026 14:32:05 +0200 (CEST) From: Dominik Csapak To: pdm-devel@lists.proxmox.com Subject: [PATCH datacenter-manager v3 3/9] lib: api types: add guest specific getter to ResourceView Date: Fri, 21 Aug 2026 14:30:15 +0200 Message-ID: <20260821123201.3035643-4-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260821123201.3035643-1-d.csapak@proxmox.com> References: <20260821123201.3035643-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.827 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: E3IIDX5LMAH5EWWPHMH3AZ3Q4B63P6EN X-Message-ID-Hash: E3IIDX5LMAH5EWWPHMH3AZ3Q4B63P6EN X-MailFrom: d.csapak@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: This is useful for the UI to get the VMID and guest type independent of the exact resource type. Signed-off-by: Dominik Csapak --- 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 564e2fc2..de2a93b4 100644 --- a/lib/pdm-api-types/src/resource.rs +++ b/lib/pdm-api-types/src/resource.rs @@ -247,6 +247,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 { + 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 { + match self { + ResourceView::PveQemu(_) => Some(GuestType::Qemu), + ResourceView::PveLxc(_) => Some(GuestType::Lxc), + _ => None, + } + } + /// Returns the resource type, e.g. Node, Qemu, etc. pub fn resource_type(&self) -> ResourceType { match self { 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( 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