From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 0FC581FF187 for ; Tue, 2 Dec 2025 11:00:28 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3F2D3A967; Tue, 2 Dec 2025 11:00:53 +0100 (CET) From: Dominik Csapak To: pdm-devel@lists.proxmox.com Date: Tue, 2 Dec 2025 11:00:03 +0100 Message-ID: <20251202100012.1328096-5-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251202100012.1328096-1-d.csapak@proxmox.com> References: <20251202100012.1328096-1-d.csapak@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.030 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pdm-devel] [PATCH datacenter-manager 2/4] lib/server: pve: add api call to get the cached version info from remotes X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" this is useful when we e.g. want to feature gate some things in the ui. This way we don't have to get the whole update information for all remotes, and we don't have to query all nodes of the remotes for their versions. Should we need it in the future, we can do the analagous api call for pbs too. Signed-off-by: Dominik Csapak --- lib/pdm-client/src/lib.rs | 6 ++++++ server/src/api/pve/mod.rs | 21 +++++++++++++++++++++ server/src/remote_updates.rs | 22 +++++++++++++++++++++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/lib/pdm-client/src/lib.rs b/lib/pdm-client/src/lib.rs index 11bedb64..f8d6062a 100644 --- a/lib/pdm-client/src/lib.rs +++ b/lib/pdm-client/src/lib.rs @@ -3,6 +3,7 @@ use std::collections::HashMap; use std::time::Duration; +use pdm_api_types::remote_updates::RemoteUpdateSummary; use pdm_api_types::remotes::{RemoteType, TlsProbeOutcome}; use pdm_api_types::resource::{PveResource, RemoteResources, ResourceType, TopEntities}; use pdm_api_types::rrddata::{ @@ -554,6 +555,11 @@ impl PdmClient { Ok(self.0.get(&query).await?.expect_json()?.data) } + pub async fn pve_cluster_updates(&self, remote: &str) -> Result { + let url = format!("/api2/extjs/pve/remotes/{remote}/updates"); + Ok(self.0.get(&url).await?.expect_json()?.data) + } + pub async fn pve_cluster_status( &self, remote: &str, diff --git a/server/src/api/pve/mod.rs b/server/src/api/pve/mod.rs index 310c6d08..97dc3970 100644 --- a/server/src/api/pve/mod.rs +++ b/server/src/api/pve/mod.rs @@ -13,6 +13,7 @@ use proxmox_schema::property_string::PropertyString; use proxmox_section_config::typed::SectionConfigData; use proxmox_sortable_macro::sortable; +use pdm_api_types::remote_updates::RemoteUpdateSummary; use pdm_api_types::remotes::{ NodeUrl, Remote, RemoteListEntry, RemoteType, TlsProbeOutcome, REMOTE_ID_SCHEMA, }; @@ -32,6 +33,7 @@ use super::resources::{map_pve_lxc, map_pve_node, map_pve_qemu, map_pve_storage} use crate::connection::PveClient; use crate::connection::{self, probe_tls_connection}; use crate::remote_tasks; +use crate::remote_updates::get_available_updates_for_remote; mod firewall; mod lxc; @@ -75,6 +77,7 @@ const REMOTE_SUBDIRS: SubdirMap = &sorted!([ ("resources", &RESOURCES_ROUTER), ("cluster-status", &STATUS_ROUTER), ("tasks", &tasks::ROUTER), + ("updates", &Router::new().get(&API_METHOD_GET_UPDATES)), ]); const NODES_ROUTER: Router = Router::new() @@ -530,3 +533,21 @@ pub async fn get_options(remote: String) -> Result { Ok(options) } + +#[api( + input: { + properties: { + remote: { schema: REMOTE_ID_SCHEMA }, + }, + }, + access: { + // correct permission? + permission: &Permission::Privilege(&["resource", "{remote}"], PRIV_RESOURCE_AUDIT, false), + }, +)] +/// Return the cached update information about a remote. +pub fn get_updates(remote: String) -> Result { + let update_summary = get_available_updates_for_remote(&remote)?; + + Ok(update_summary) +} diff --git a/server/src/remote_updates.rs b/server/src/remote_updates.rs index 7e57b56e..e772eef5 100644 --- a/server/src/remote_updates.rs +++ b/server/src/remote_updates.rs @@ -1,7 +1,7 @@ use std::fs::File; use std::io::ErrorKind; -use anyhow::Error; +use anyhow::{bail, Error}; use serde::{Deserialize, Serialize}; use proxmox_apt_api_types::{APTRepositoriesResult, APTRepositoryHandle, APTUpdateInfo}; @@ -136,6 +136,26 @@ pub fn get_available_updates_summary() -> Result { Ok(summary) } +/// Return cached update information from specific remote +pub fn get_available_updates_for_remote(remote: &str) -> Result { + let (config, _digest) = pdm_config::remotes::config()?; + + if let Some(remote) = config.get(remote) { + let cache_content = get_cached_summary_or_default()?; + Ok(cache_content + .remotes + .get(&remote.id) + .cloned() + .unwrap_or_else(|| RemoteUpdateSummary { + nodes: NodeUpdateSummaryWrapper::default(), + remote_type: remote.ty, + status: RemoteUpdateStatus::Unknown, + })) + } else { + bail!("no such remote '{remote}'"); + } +} + fn get_cached_summary_or_default() -> Result { match File::open(UPDATE_CACHE) { Ok(file) => { -- 2.47.3 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel