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 225EF1FF16B for ; Fri, 26 Sep 2025 09:27:25 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 105F792ED; Fri, 26 Sep 2025 09:27:54 +0200 (CEST) From: Dominik Csapak To: pdm-devel@lists.proxmox.com Date: Fri, 26 Sep 2025 09:20:21 +0200 Message-ID: <20250926072749.560801-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250926072749.560801-1-d.csapak@proxmox.com> References: <20250926072749.560801-1-d.csapak@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.027 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 01/11] server: api: return list of pve/pbs 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" for the paths /{pve,pbs}/remotes/ This api call is announced as a subdirectory, but had no api call assigned. Introduce a new basic api type for this. Signed-off-by: Dominik Csapak --- lib/pdm-api-types/src/remotes.rs | 13 +++++++++++++ server/src/api/pbs/mod.rs | 30 ++++++++++++++++++++++++++++-- server/src/api/pve/mod.rs | 30 ++++++++++++++++++++++++++++-- 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/lib/pdm-api-types/src/remotes.rs b/lib/pdm-api-types/src/remotes.rs index 7e67eec8..63189438 100644 --- a/lib/pdm-api-types/src/remotes.rs +++ b/lib/pdm-api-types/src/remotes.rs @@ -189,3 +189,16 @@ pub enum TlsProbeOutcome { /// The certificate is untrusted with the given hostname/fingerprint UntrustedCertificate(proxmox_acme_api::CertificateInfo), } + +#[api( + properties: { + "remote": { schema: REMOTE_ID_SCHEMA }, + }, +)] +/// The information required to connect to a remote instance. +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] +#[serde(rename_all = "kebab-case")] +pub struct RemoteListEntry { + /// An id for this entry. + pub remote: String, +} diff --git a/server/src/api/pbs/mod.rs b/server/src/api/pbs/mod.rs index 2e203cac..4473c6c8 100644 --- a/server/src/api/pbs/mod.rs +++ b/server/src/api/pbs/mod.rs @@ -6,7 +6,9 @@ use proxmox_schema::api; use proxmox_schema::property_string::PropertyString; use proxmox_sortable_macro::sortable; -use pdm_api_types::remotes::{NodeUrl, Remote, RemoteType, TlsProbeOutcome, REMOTE_ID_SCHEMA}; +use pdm_api_types::remotes::{ + NodeUrl, Remote, RemoteListEntry, RemoteType, TlsProbeOutcome, REMOTE_ID_SCHEMA, +}; use pdm_api_types::{Authid, HOST_OPTIONAL_PORT_FORMAT, PRIV_RESOURCE_AUDIT, PRIV_SYS_MODIFY}; use crate::{ @@ -27,7 +29,9 @@ const SUBDIRS: SubdirMap = &sorted!([ ("probe-tls", &Router::new().post(&API_METHOD_PROBE_TLS)), ]); -const REMOTES_ROUTER: Router = Router::new().match_all("remote", &MAIN_ROUTER); +const REMOTES_ROUTER: Router = Router::new() + .get(&API_METHOD_LIST_REMOTES) + .match_all("remote", &MAIN_ROUTER); pub const MAIN_ROUTER: Router = Router::new() .get(&list_subdirs_api_method!(REMOTE_SUBDIRS)) @@ -56,6 +60,28 @@ const DATASTORE_ITEM_SUBDIRS: SubdirMap = &sorted!([ ), ]); +#[api( + returns: { + type: Array, + description: "List of PBS remotes", + items: { + type: pdm_api_types::remotes::RemoteListEntry, + }, + }, +)] +/// Return the list of PBS remotes +fn list_remotes() -> Result, Error> { + let (remotes, _) = pdm_config::remotes::config()?; + let remotes = remotes + .into_iter() + .filter_map(|(remote, Remote { ty, .. })| match ty { + RemoteType::Pbs => Some(RemoteListEntry { remote }), + RemoteType::Pve => None, + }) + .collect(); + Ok(remotes) +} + #[api( input: { properties: { diff --git a/server/src/api/pve/mod.rs b/server/src/api/pve/mod.rs index edafdded..0de82323 100644 --- a/server/src/api/pve/mod.rs +++ b/server/src/api/pve/mod.rs @@ -13,7 +13,9 @@ use proxmox_schema::property_string::PropertyString; use proxmox_section_config::typed::SectionConfigData; use proxmox_sortable_macro::sortable; -use pdm_api_types::remotes::{NodeUrl, Remote, RemoteType, TlsProbeOutcome, REMOTE_ID_SCHEMA}; +use pdm_api_types::remotes::{ + NodeUrl, Remote, RemoteListEntry, RemoteType, TlsProbeOutcome, REMOTE_ID_SCHEMA, +}; use pdm_api_types::resource::PveResource; use pdm_api_types::{ Authid, RemoteUpid, HOST_OPTIONAL_PORT_FORMAT, PRIV_RESOURCE_AUDIT, PRIV_RESOURCE_DELETE, @@ -54,7 +56,9 @@ const SUBDIRS: SubdirMap = &sorted!([ ) ]); -pub const REMOTES_ROUTER: Router = Router::new().match_all("remote", &MAIN_ROUTER); +pub const REMOTES_ROUTER: Router = Router::new() + .get(&API_METHOD_LIST_REMOTES) + .match_all("remote", &MAIN_ROUTER); const MAIN_ROUTER: Router = Router::new() .get(&list_subdirs_api_method!(REMOTE_SUBDIRS)) @@ -111,6 +115,28 @@ fn connect_to_remote( connect(get_remote(config, id)?) } +#[api( + returns: { + type: Array, + description: "List of PVE remotes", + items: { + type: RemoteListEntry, + }, + }, +)] +/// Return the list of PVE remotes +fn list_remotes() -> Result, Error> { + let (remotes, _) = pdm_config::remotes::config()?; + let remotes = remotes + .into_iter() + .filter_map(|(remote, Remote { ty, .. })| match ty { + RemoteType::Pve => Some(RemoteListEntry { remote }), + RemoteType::Pbs => None, + }) + .collect(); + Ok(remotes) +} + #[api( input: { properties: { -- 2.47.3 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel