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 781D41FF09F for ; Tue, 01 Dec 2026 16:15:36 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 08DEE20A75; Tue, 01 Dec 2026 16:15:36 +0100 (CET) From: Dominik Csapak To: pdm-devel@lists.proxmox.com Subject: [PATCH datacenter-manager 2/4] api: remotes: report whether a remote is a cluster in the list Date: Tue, 1 Dec 2026 16:12:06 +0100 Message-ID: <20261201151531.3348382-3-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261201151531.3348382-1-d.csapak@proxmox.com> References: <20261201151531.3348382-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.243 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: DYBB7ZP2DALNPG6KEEVU6TFCGRGRPWC3 X-Message-ID-Hash: DYBB7ZP2DALNPG6KEEVU6TFCGRGRPWC3 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: so that clients like the UI get it together with the rest of the remote list, which is polled regularly anyway. Since `Remote` is the section config type, add a new `ListedRemote` type that flattens it and adds the optional 'cluster' property, which is omitted for PVE remotes as long as none of their endpoints answered. PBS remotes are never clusters. `ListedRemote` derefs to `Remote`, so that users can access the config properties directly. Existing clients that deserialize the list into `Remote` keep working, since the new property is ignored. Signed-off-by: Dominik Csapak --- lib/pdm-api-types/src/remotes.rs | 20 ++++++++++++++++++++ server/src/api/remotes/mod.rs | 18 +++++++++++++----- server/tests/test_remote_home.rs | 2 +- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/lib/pdm-api-types/src/remotes.rs b/lib/pdm-api-types/src/remotes.rs index e6b5f47f..d583e608 100644 --- a/lib/pdm-api-types/src/remotes.rs +++ b/lib/pdm-api-types/src/remotes.rs @@ -164,6 +164,26 @@ impl Remote { } } +#[api(properties: { remote: { flatten: true, type: Remote } })] +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] +#[serde(rename_all = "kebab-case")] +/// A remote in the list of remotes, with what was last learned about it. +pub struct ListedRemote { + #[serde(flatten)] + pub remote: Remote, + /// Whether the remote is a cluster. Unknown until one of its endpoints answered. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub cluster: Option, +} + +impl std::ops::Deref for ListedRemote { + type Target = Remote; + + fn deref(&self) -> &Self::Target { + &self.remote + } +} + #[api] #[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq, Eq)] #[serde(rename_all = "kebab-case")] diff --git a/server/src/api/remotes/mod.rs b/server/src/api/remotes/mod.rs index 7b218f98..bb30b243 100644 --- a/server/src/api/remotes/mod.rs +++ b/server/src/api/remotes/mod.rs @@ -23,8 +23,8 @@ use proxmox_time::{epoch_i64, epoch_to_rfc2822}; use pbs_api_types::{Tokenname, Userid}; use pdm_api_types::folders::FOLDER_PATH_SCHEMA; use pdm_api_types::remotes::{ - CREATE_TOKEN_SCHEMA, DeletableRemoteProperty, REMOTE_ID_SCHEMA, Remote, RemoteType, - RemoteUpdater, TlsProbeOutcome, + CREATE_TOKEN_SCHEMA, DeletableRemoteProperty, ListedRemote, REMOTE_ID_SCHEMA, Remote, + RemoteType, RemoteUpdater, TlsProbeOutcome, }; use pdm_api_types::rrddata::RemoteDatapoint; use pdm_api_types::{ @@ -33,6 +33,7 @@ use pdm_api_types::{ use pve_api_types::ClusterOptionsTokenPolicy; use crate::metric_collection::trigger_remote_metric_collection; +use crate::remote_cache::RemoteMappingCache; use crate::{connection, pbs_client, remote_error}; use super::pve; @@ -310,7 +311,7 @@ impl IntoIterator for RemoteIterator { description: "The list of configured remotes.", type: Array, items: { - type: Remote, + type: ListedRemote, }, }, )] @@ -319,15 +320,22 @@ pub fn list_remotes( folder: Option, rpcenv: &mut dyn RpcEnvironment, #[state] app: PdmApplication, -) -> Result, Error> { +) -> Result, Error> { let scope = ReadScope::resolve(rpcenv, &app, None, folder.as_deref())?; let (remotes, digest) = scope.access().remote_config()?; rpcenv["digest"] = digest.to_hex().into(); + let cache = RemoteMappingCache::get(); Ok(remotes .into_iter() .filter(|(name, _)| scope.lists_remote(name)) - .map(|(_, remote)| visible_config(remote, scope.access())) + .map(|(_, remote)| ListedRemote { + cluster: match remote.ty { + RemoteType::Pve => cache.is_cluster(&remote.id), + RemoteType::Pbs => Some(false), + }, + remote: visible_config(remote, scope.access()), + }) .collect()) } diff --git a/server/tests/test_remote_home.rs b/server/tests/test_remote_home.rs index 0f4a703a..a9f75bf0 100644 --- a/server/tests/test_remote_home.rs +++ b/server/tests/test_remote_home.rs @@ -155,7 +155,7 @@ async fn remote_reads_hide_the_token_and_placement_from_non_admins() -> Result<( set_admin(false); let env = &mut common::rpcenv_as(MANAGER, app); for remote in [ - list_remotes(None, env, app.clone())?.pop().unwrap(), + list_remotes(None, env, app.clone())?.pop().unwrap().remote, remote_config("onboard".into(), env, app.clone())?, ] { assert!(remote.token.is_empty()); -- 2.47.3