From: Lukas Wagner <l.wagner@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH datacenter-manager 2/3] clippy: pdm-client: use parameter type for pve_list_storages
Date: Wed, 20 May 2026 15:13:46 +0200 [thread overview]
Message-ID: <20260520131348.332987-3-l.wagner@proxmox.com> (raw)
In-Reply-To: <20260520131348.332987-1-l.wagner@proxmox.com>
This API had a quite excessive number of parameters, some of which also
had the same type. A parameter type for the filter options reduces the
potential for errors. The `formats` parameters was kept as a distinct
function parameter and renamed to `include_formats`, to better convey
the meaning.
Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
lib/pdm-client/src/lib.rs | 43 +++++++++++++++++++--------
ui/src/widget/pve_storage_selector.rs | 19 ++++++++----
2 files changed, 43 insertions(+), 19 deletions(-)
diff --git a/lib/pdm-client/src/lib.rs b/lib/pdm-client/src/lib.rs
index 76b33ef8..c97c9db9 100644
--- a/lib/pdm-client/src/lib.rs
+++ b/lib/pdm-client/src/lib.rs
@@ -97,6 +97,20 @@ impl<T: HttpApiClient> std::ops::DerefMut for PdmClient<T> {
}
}
+/// Filter for [`PdmClient::pve_list_storages`].
+#[derive(Clone, Debug, Default, Eq, PartialEq)]
+pub struct PveListStoragesFilter {
+ /// Only list stores which support this content type.
+ pub content: Vec<StorageContent>,
+ /// Only list stores which are enabled (not disabled in config).
+ pub enabled: Option<bool>,
+ /// Only list status for specified storage
+ pub storage: Option<String>,
+ // If target is different to 'node', we only list shared storages which are accessible on
+ // this 'node' and the specified 'target' node.
+ pub target: Option<String>,
+}
+
impl<T: HttpApiClient> PdmClient<T> {
pub async fn list_remotes(&self) -> Result<Vec<Remote>, Error> {
Ok(self
@@ -1103,28 +1117,31 @@ impl<T: HttpApiClient> PdmClient<T> {
Ok(self.0.get(&path).await?.expect_json()?.data)
}
+ /// List storages for a given PVE remote node.
+ ///
+ /// The storages can be filtered using the `filter` parameter, for details see
+ /// [`PveListStoragesFilter`]. If `include_supported_disk_image_formats` is set
+ /// to true, the result will include information about supported disk image types
+ /// for each storage.
pub async fn pve_list_storages(
&self,
remote: &str,
node: &str,
- content: Option<Vec<StorageContent>>,
- enabled: Option<bool>,
- format: Option<bool>,
- storage: Option<String>,
- target: Option<String>,
+ filter: PveListStoragesFilter,
+ include_supported_disk_image_formats: bool,
) -> Result<Vec<StorageInfo>, Error> {
let mut builder = ApiPathBuilder::new(format!(
"/api2/extjs/pve/remotes/{remote}/nodes/{node}/storage"
))
- .maybe_arg("enabled", &enabled)
- .maybe_arg("format", &format)
- .maybe_arg("storage", &storage)
- .maybe_arg("target", &target);
- if let Some(content) = content {
- for ty in content {
- builder = builder.arg("content", ty);
- }
+ .arg("format", include_supported_disk_image_formats)
+ .maybe_arg("enabled", &filter.enabled)
+ .maybe_arg("storage", &filter.storage)
+ .maybe_arg("target", &filter.target);
+
+ for ty in filter.content {
+ builder = builder.arg("content", ty);
}
+
let path = builder.build();
Ok(self.0.get(&path).await?.expect_json()?.data)
diff --git a/ui/src/widget/pve_storage_selector.rs b/ui/src/widget/pve_storage_selector.rs
index 488175ab..f43234dc 100644
--- a/ui/src/widget/pve_storage_selector.rs
+++ b/ui/src/widget/pve_storage_selector.rs
@@ -22,7 +22,10 @@ use pwt::{
};
use pwt_macros::{builder, widget};
-use pdm_client::types::{StorageContent, StorageInfo};
+use pdm_client::{
+ types::{StorageContent, StorageInfo},
+ PveListStoragesFilter,
+};
#[widget(comp=PveStorageSelectorComp, @input)]
#[derive(Clone, Properties, PartialEq)]
@@ -85,15 +88,19 @@ impl PveStorageSelectorComp {
content: Option<Vec<StorageContent>>,
target: Option<AttrValue>,
) -> Result<Vec<StorageInfo>, Error> {
+ let filter = PveListStoragesFilter {
+ content: content.unwrap_or_default(),
+ enabled: Some(true),
+ target: target.as_ref().map(AttrValue::to_string),
+ ..Default::default()
+ };
+
let mut storages = crate::pdm_client()
.pve_list_storages(
&remote,
&node.unwrap_or(AttrValue::from("localhost")),
- content,
- Some(true),
- Some(true),
- None,
- target.as_ref().map(AttrValue::to_string),
+ filter,
+ true,
)
.await?;
--
2.47.3
next prev parent reply other threads:[~2026-05-20 13:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-20 13:13 [PATCH datacenter-manager 0/3] various clippy fixes Lukas Wagner
2026-05-20 13:13 ` [PATCH datacenter-manager 1/3] clippy: cli: acme: redundant field names in struct initialization Lukas Wagner
2026-05-20 13:13 ` Lukas Wagner [this message]
2026-05-20 13:13 ` [PATCH datacenter-manager 3/3] clippy: sdn-client: fix 'large size difference between variants' for error type Lukas Wagner
2026-05-21 12:57 ` Wolfgang Bumiller
2026-05-21 13:00 ` partially-applied: [PATCH datacenter-manager 0/3] various clippy fixes Wolfgang Bumiller
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=20260520131348.332987-3-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