From: Lukas Wagner <l.wagner@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH datacenter-manager v2 07/20] remote iterator: pass remote config reader explicitly
Date: Thu, 20 Aug 2026 16:52:07 +0200 [thread overview]
Message-ID: <20260820145220.418032-8-l.wagner@proxmox.com> (raw)
In-Reply-To: <20260820145220.418032-1-l.wagner@proxmox.com>
This will be useful later once we get a reference to the remote config
implementation via the application context object. Also, it gently
nudges developers to think about the previously hidden dependency.
Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
lib/pdm-config/src/remotes.rs | 2 +-
server/src/api/pbs/mod.rs | 10 ++++------
server/src/api/pve/firewall.rs | 3 ++-
server/src/api/pve/mod.rs | 3 ++-
server/src/api/remotes/mod.rs | 5 +++--
server/src/api/remotes/updates.rs | 3 ++-
server/src/api/sdn/controllers.rs | 2 +-
server/src/api/sdn/vnets.rs | 2 +-
server/src/api/sdn/zones.rs | 2 +-
server/src/api/subscriptions/mod.rs | 10 ++++++----
10 files changed, 23 insertions(+), 19 deletions(-)
diff --git a/lib/pdm-config/src/remotes.rs b/lib/pdm-config/src/remotes.rs
index 47754e9b..4db6be20 100644
--- a/lib/pdm-config/src/remotes.rs
+++ b/lib/pdm-config/src/remotes.rs
@@ -21,7 +21,7 @@ pub const REMOTES_CFG_LOCKFILE: &str = configdir!("/.remotes.lock");
static INSTANCE: OnceLock<Box<dyn RemoteConfig + Send + Sync>> = OnceLock::new();
-fn instance() -> &'static (dyn RemoteConfig + Send + Sync) {
+pub fn instance() -> &'static (dyn RemoteConfig + Send + Sync) {
// Not initializing the remote config instance is
// entirely in our responsibility and not something we can recover from,
// so it should be okay to panic in this case.
diff --git a/server/src/api/pbs/mod.rs b/server/src/api/pbs/mod.rs
index 1fc75c34..41ee2c08 100644
--- a/server/src/api/pbs/mod.rs
+++ b/server/src/api/pbs/mod.rs
@@ -13,11 +13,9 @@ use pdm_api_types::{
Authid, HOST_OPTIONAL_PORT_FORMAT, PRIV_RESOURCE_AUDIT, PRIV_SYS_MODIFY, RemoteUpid,
};
-use crate::{
- connection::{self, probe_tls_connection},
- pbs_client::{self, PbsClient, get_remote},
-};
-
+use crate::api::remotes::RemoteIterator;
+use crate::connection::{self, probe_tls_connection};
+use crate::pbs_client::{self, PbsClient, get_remote};
use crate::remote_tasks;
mod node;
@@ -96,7 +94,7 @@ pub async fn new_remote_upid(
)]
/// Return the list of PBS remotes
fn list_remotes() -> Result<Vec<RemoteListEntry>, Error> {
- Ok(super::remotes::RemoteIterator::new()?
+ Ok(RemoteIterator::new(pdm_config::remotes::instance())?
.remote_type(RemoteType::Pbs)
.into_names()
.map(|name| RemoteListEntry { remote: name })
diff --git a/server/src/api/pve/firewall.rs b/server/src/api/pve/firewall.rs
index 5a6a209e..b381a14e 100644
--- a/server/src/api/pve/firewall.rs
+++ b/server/src/api/pve/firewall.rs
@@ -17,6 +17,7 @@ use pdm_api_types::{NODE_SCHEMA, VMID_SCHEMA};
use pdm_api_types::{PRIV_RESOURCE_AUDIT, PRIV_RESOURCE_MODIFY, PRIV_SYS_MODIFY};
use super::{connect_to_remote_by_id, find_node_for_vm};
+use crate::api::remotes::RemoteIterator;
use crate::connection::PveClient;
use crate::parallel_fetcher::ParallelFetcher;
@@ -249,7 +250,7 @@ async fn fetch_node_firewall_status(
pub async fn pve_firewall_status(
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<Vec<RemoteFirewallStatus>, Error> {
- let pve_remotes: Vec<Remote> = crate::api::remotes::RemoteIterator::new()?
+ let pve_remotes: Vec<Remote> = RemoteIterator::new(pdm_config::remotes::instance())?
.remote_type(pdm_api_types::remotes::RemoteType::Pve)
.into_remotes()
.collect();
diff --git a/server/src/api/pve/mod.rs b/server/src/api/pve/mod.rs
index 0970f2ff..4f6f7215 100644
--- a/server/src/api/pve/mod.rs
+++ b/server/src/api/pve/mod.rs
@@ -30,6 +30,7 @@ use pve_api_types::{ClusterResourceKind, ClusterResourceType};
use super::resources::{map_pve_lxc, map_pve_node, map_pve_qemu, map_pve_storage};
+use crate::api::remotes::RemoteIterator;
use crate::connection::PveClient;
use crate::connection::{self, probe_tls_connection};
use crate::remote_tasks;
@@ -142,7 +143,7 @@ pub fn connect_to_remote_by_id(id: &str) -> Result<Arc<PveClient>, Error> {
)]
/// Return the list of PVE remotes
fn list_remotes() -> Result<Vec<RemoteListEntry>, Error> {
- Ok(super::remotes::RemoteIterator::new()?
+ Ok(RemoteIterator::new(pdm_config::remotes::instance())?
.remote_type(RemoteType::Pve)
.into_names()
.map(|name| RemoteListEntry { remote: name })
diff --git a/server/src/api/remotes/mod.rs b/server/src/api/remotes/mod.rs
index 5c9fdccf..d039e6da 100644
--- a/server/src/api/remotes/mod.rs
+++ b/server/src/api/remotes/mod.rs
@@ -4,6 +4,7 @@ use std::collections::HashSet;
use std::error::Error as _;
use anyhow::{Context, Error, bail, format_err};
+use pdm_config::remotes::RemoteConfig;
use serde::{Deserialize, Serialize};
use proxmox_access_control::CachedUserInfo;
@@ -129,8 +130,8 @@ pub struct RemoteIterator {
impl RemoteIterator {
/// Load the remote config and create an unfiltered iterator.
- pub fn new() -> Result<Self, Error> {
- let (config, _) = pdm_config::remotes::config()?;
+ pub fn new(config_impl: &dyn RemoteConfig) -> Result<Self, Error> {
+ let (config, _) = config_impl.read()?;
Ok(Self {
remotes: config.into_iter().collect(),
})
diff --git a/server/src/api/remotes/updates.rs b/server/src/api/remotes/updates.rs
index d5b6d2dd..0945478b 100644
--- a/server/src/api/remotes/updates.rs
+++ b/server/src/api/remotes/updates.rs
@@ -17,6 +17,7 @@ use proxmox_router::{
use proxmox_schema::api;
use proxmox_sortable_macro::sortable;
+use crate::api::remotes::RemoteIterator;
use crate::{connection, remote_updates};
use super::get_remote;
@@ -88,7 +89,7 @@ pub fn refresh_remote_update_summaries(rpcenv: &mut dyn RpcEnvironment) -> Resul
http_bail!(FORBIDDEN, "user has no access to resources");
}
- let remotes: Vec<Remote> = super::RemoteIterator::new()?
+ let remotes: Vec<Remote> = RemoteIterator::new(pdm_config::remotes::instance())?
.all_privs(&user_info, &auth_id, PRIV_RESOURCE_MODIFY)
.into_remotes()
.collect();
diff --git a/server/src/api/sdn/controllers.rs b/server/src/api/sdn/controllers.rs
index c90e44c9..060fef72 100644
--- a/server/src/api/sdn/controllers.rs
+++ b/server/src/api/sdn/controllers.rs
@@ -75,7 +75,7 @@ pub async fn list_controllers(
http_bail!(FORBIDDEN, "user has no access to resources");
}
- let mut iter = RemoteIterator::new()?
+ let mut iter = RemoteIterator::new(pdm_config::remotes::instance())?
.remote_type(RemoteType::Pve)
.any_privs(&user_info, &auth_id, PRIV_RESOURCE_AUDIT);
if let Some(ref filter) = remotes {
diff --git a/server/src/api/sdn/vnets.rs b/server/src/api/sdn/vnets.rs
index ede7b539..30d431bc 100644
--- a/server/src/api/sdn/vnets.rs
+++ b/server/src/api/sdn/vnets.rs
@@ -76,7 +76,7 @@ async fn list_vnets(
http_bail!(FORBIDDEN, "user has no access to resources");
}
- let mut iter = RemoteIterator::new()?
+ let mut iter = RemoteIterator::new(pdm_config::remotes::instance())?
.remote_type(RemoteType::Pve)
.any_privs(&user_info, &auth_id, PRIV_RESOURCE_AUDIT);
if let Some(ref filter) = remotes {
diff --git a/server/src/api/sdn/zones.rs b/server/src/api/sdn/zones.rs
index da471ba9..d37dc46c 100644
--- a/server/src/api/sdn/zones.rs
+++ b/server/src/api/sdn/zones.rs
@@ -82,7 +82,7 @@ pub async fn list_zones(
http_bail!(FORBIDDEN, "user has no access to resources");
}
- let mut iter = RemoteIterator::new()?
+ let mut iter = RemoteIterator::new(pdm_config::remotes::instance())?
.remote_type(RemoteType::Pve)
.any_privs(&user_info, &auth_id, PRIV_RESOURCE_AUDIT);
if let Some(ref filter) = remotes {
diff --git a/server/src/api/subscriptions/mod.rs b/server/src/api/subscriptions/mod.rs
index 48b15b98..81582945 100644
--- a/server/src/api/subscriptions/mod.rs
+++ b/server/src/api/subscriptions/mod.rs
@@ -29,6 +29,7 @@ use pdm_api_types::{
Authid, NODE_SCHEMA, PRIV_RESOURCE_AUDIT, PRIV_RESOURCE_MODIFY, PRIV_SYS_AUDIT, PRIV_SYS_MODIFY,
};
+use crate::api::remotes::RemoteIterator;
use crate::api::resources::{
get_subscription_info_for_remote, invalidate_subscription_info_for_remote,
};
@@ -1431,10 +1432,11 @@ async fn collect_node_status(
.parse()?;
let user_info = CachedUserInfo::new()?;
- let visible_remotes: Vec<(String, Remote)> = crate::api::remotes::RemoteIterator::new()?
- .any_privs(&user_info, &auth_id, PRIV_RESOURCE_AUDIT)
- .into_iter()
- .collect();
+ let visible_remotes: Vec<(String, Remote)> =
+ RemoteIterator::new(pdm_config::remotes::instance())?
+ .any_privs(&user_info, &auth_id, PRIV_RESOURCE_AUDIT)
+ .into_iter()
+ .collect();
let (keys_config, _) = pdm_config::subscriptions::config()?;
--
2.47.3
next prev parent reply other threads:[~2026-08-20 14:52 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-20 14:52 [PATCH datacenter-manager/proxmox v2 00/20] inject application context via API macro for easier integration testing Lukas Wagner
2026-08-20 14:52 ` [PATCH proxmox v2 01/20] router: introduce shared state Lukas Wagner
2026-08-20 14:52 ` [PATCH proxmox v2 02/20] rest-server: allow to inject " Lukas Wagner
2026-08-20 14:52 ` [PATCH proxmox v2 03/20] api-macro: support shared state extraction type Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 04/20] context: promote context to a dir-style module Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 05/20] pdm-config: remotes: rename trait methods to read/write/lock Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 06/20] pdm-config: subscriptions: " Lukas Wagner
2026-08-20 14:52 ` Lukas Wagner [this message]
2026-08-20 14:52 ` [PATCH datacenter-manager v2 08/20] context: introduce a ContextFactory to build application context Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 09/20] context: establish PdmApplication object Lukas Wagner
2026-08-21 9:52 ` Thomas Ellmenreich
2026-08-21 12:26 ` Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 10/20] context: register PdmApplication in router Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 11/20] parallel fetcher: pass arguments to closure in a single type Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 12/20] parallel fetcher: support a custom client factory Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 13/20] api: sdn: use PdmApplication handle for accessing remotes Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 14/20] tests: add helpers for building API-handler-level integration tests Lukas Wagner
2026-08-21 9:57 ` Thomas Ellmenreich
2026-08-21 12:25 ` Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 15/20] tests: add example tests for SDN API routes Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 16/20] api-cache: add wrapper type Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 17/20] context: provide api-cache on the app object Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 18/20] api: subscriptions: use PdmApplication instead of globals Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 19/20] pdm-config: subscriptions: drop unused accessor functions Lukas Wagner
2026-08-20 14:52 ` [PATCH datacenter-manager v2 20/20] tests: add example tests for remote subscription management Lukas Wagner
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=20260820145220.418032-8-l.wagner@proxmox.com \
--to=l.wagner@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