[pdm-devel] [PATCH proxmox-datacenter-manager 2/9] connection: add access to "raw" client
Stefan Hanreich
s.hanreich at proxmox.com
Thu Nov 13 11:39:31 CET 2025
since both PveClient and PbsClient wrap a Client afaict, would it be
better to add a method to them that allows for obtaining a reference to
that one? But I assume it's simply easier for this feature to be able to
obtain a raw client for a remote, without having to distinguish remote
types everywhere?
On 11/11/25 9:29 AM, Fabian Grünbichler wrote:
> needed for websocket connections and similar lower level access.
>
> Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
> ---
>
> Notes:
> unchanged
>
> server/src/connection.rs | 11 +++++++++++
> server/src/metric_collection/collection_task.rs | 5 +++++
> server/src/test_support/fake_remote.rs | 5 +++++
> 3 files changed, 21 insertions(+)
>
> diff --git a/server/src/connection.rs b/server/src/connection.rs
> index e749c1a..1c0069e 100644
> --- a/server/src/connection.rs
> +++ b/server/src/connection.rs
> @@ -252,6 +252,9 @@ pub trait ClientFactory {
> ///
> /// Note: currently does not support two factor authentication.
> async fn make_pbs_client_and_login(&self, remote: &Remote) -> Result<Box<PbsClient>, Error>;
> +
> + /// Create a new API client for raw acess to the given remote
> + fn make_raw_client(&self, remote: &Remote) -> Result<Box<Client>, Error>;
> }
>
> /// Default production client factory
> @@ -346,6 +349,10 @@ impl ClientFactory for DefaultClientFactory {
> ConnectionCache::get().make_pve_client(remote)
> }
>
> + fn make_raw_client(&self, remote: &Remote) -> Result<Box<Client>, Error> {
> + Ok(Box::new(crate::connection::connect(remote, None)?))
> + }
> +
> fn make_pbs_client(&self, remote: &Remote) -> Result<Box<PbsClient>, Error> {
> let client = crate::connection::connect(remote, None)?;
> Ok(Box::new(PbsClient(client)))
> @@ -418,6 +425,10 @@ pub fn make_pbs_client(remote: &Remote) -> Result<Box<PbsClient>, Error> {
> instance().make_pbs_client(remote)
> }
>
> +pub fn make_raw_client(remote: &Remote) -> Result<Box<Client>, Error> {
> + instance().make_raw_client(remote)
> +}
> +
> /// Create a new API client for PVE remotes.
> ///
> /// In case the remote has a user configured (instead of an API token), it will connect and get a
> diff --git a/server/src/metric_collection/collection_task.rs b/server/src/metric_collection/collection_task.rs
> index a6c8443..cc1a460 100644
> --- a/server/src/metric_collection/collection_task.rs
> +++ b/server/src/metric_collection/collection_task.rs
> @@ -387,6 +387,7 @@ pub(super) mod tests {
> use http::StatusCode;
>
> use pdm_api_types::Authid;
> + use proxmox_client::Client;
> use pve_api_types::{ClusterMetrics, ClusterMetricsData};
>
> use crate::{
> @@ -430,6 +431,10 @@ pub(super) mod tests {
> bail!("not implemented")
> }
>
> + fn make_raw_client(&self, _remote: &Remote) -> Result<Box<Client>, Error> {
> + bail!("not implemented")
> + }
> +
> async fn make_pve_client_and_login(
> &self,
> _remote: &Remote,
> diff --git a/server/src/test_support/fake_remote.rs b/server/src/test_support/fake_remote.rs
> index cd2ccf6..62dd869 100644
> --- a/server/src/test_support/fake_remote.rs
> +++ b/server/src/test_support/fake_remote.rs
> @@ -5,6 +5,7 @@ use serde::Deserialize;
>
> use pdm_api_types::{remotes::Remote, Authid, ConfigDigest};
> use pdm_config::remotes::RemoteConfig;
> +use proxmox_client::Client;
> use proxmox_product_config::ApiLockGuard;
> use proxmox_section_config::typed::SectionConfigData;
> use pve_api_types::{
> @@ -100,6 +101,10 @@ impl ClientFactory for FakeClientFactory {
> bail!("not implemented")
> }
>
> + fn make_raw_client(&self, _remote: &Remote) -> Result<Box<Client>, Error> {
> + bail!("not implemented")
> + }
> +
> async fn make_pve_client_and_login(&self, _remote: &Remote) -> Result<Arc<PveClient>, Error> {
> bail!("not implemented")
> }
More information about the pdm-devel
mailing list