[pdm-devel] [PATCH proxmox-datacenter-manager 02/12] pdm-api-types: add types for remote upgrade summary
Shannon Sterz
s.sterz at proxmox.com
Fri Oct 17 12:15:29 CEST 2025
On Wed Oct 15, 2025 at 2:47 PM CEST, Lukas Wagner wrote:
> This type contains the number of available updates per remote node,
> without any details. This is useful for a global "give me the update
> availability for all managed nodes" API endpoint.
>
> Signed-off-by: Lukas Wagner <l.wagner at proxmox.com>
> ---
> lib/pdm-api-types/src/lib.rs | 2 +
> lib/pdm-api-types/src/remote_updates.rs | 126 ++++++++++++++++++++++++
> 2 files changed, 128 insertions(+)
> create mode 100644 lib/pdm-api-types/src/remote_updates.rs
>
> diff --git a/lib/pdm-api-types/src/lib.rs b/lib/pdm-api-types/src/lib.rs
> index a3566142..2fb61ef7 100644
> --- a/lib/pdm-api-types/src/lib.rs
> +++ b/lib/pdm-api-types/src/lib.rs
> @@ -96,6 +96,8 @@ pub use openid::*;
>
> pub mod remotes;
>
> +pub mod remote_updates;
> +
> pub mod resource;
>
> pub mod rrddata;
> diff --git a/lib/pdm-api-types/src/remote_updates.rs b/lib/pdm-api-types/src/remote_updates.rs
> new file mode 100644
> index 00000000..d04a7a79
> --- /dev/null
> +++ b/lib/pdm-api-types/src/remote_updates.rs
> @@ -0,0 +1,126 @@
> +use std::{
> + collections::HashMap,
> + ops::{Deref, DerefMut},
> +};
> +
nit: i think we prefer module level imports these days. so this should
be
use std::collections::HashMap;
use std::ops::{Deref, DerefMut};
but no hard feelings from my side and certainly not a blocker
> +use proxmox_schema::{api, ApiType, ObjectSchema};
> +use serde::{Deserialize, Serialize};
> +
nit: ordering of use statements should be std -> generic crates (serde,
anyhow etc.) -> proxmox* -> project; each separate by an empty line, to
my knowledge.
so:
```
use serde::{Deserialize, Serialize};
use proxmox_schema::{api, ApiType, ObjectSchema};
```
again not a
blocker, just saw it and thought id mention it
> +use crate::remotes::RemoteType;
> +
> +#[api]
> +#[derive(Clone, Debug, Default, Deserialize, Serialize)]
> +#[serde(rename_all = "kebab-case")]
> +/// Update summary for all remotes.
> +pub struct UpdateSummary {
> + /// Map containing the update summary each remote.
> + pub remotes: RemoteUpdateSummaryWrapper,
> +}
> +
> +// This is a hack to allow actual 'maps' (mapping remote name to per-remote data)
> +// within the realms of our API macro.
> +#[derive(Clone, Debug, Default, Deserialize, Serialize)]
> +#[serde(rename_all = "kebab-case")]
> +pub struct RemoteUpdateSummaryWrapper {
> + #[serde(flatten)]
> + remotes: HashMap<String, RemoteUpdateSummary>,
> +}
just wondering whether you have considered changing this to
pub struct RemoteUpdateSummaryWrapper(HashMap<String, RemoteUpdateSummary>);
would save you a `flatten` from what i can tell?
> +impl ApiType for RemoteUpdateSummaryWrapper {
> + const API_SCHEMA: proxmox_schema::Schema =
> + ObjectSchema::new("Map of per-remote update summaries", &[])
> + .additional_properties(true)
> + .schema();
> +}
> +
> +impl Deref for RemoteUpdateSummaryWrapper {
> + type Target = HashMap<String, RemoteUpdateSummary>;
> +
> + fn deref(&self) -> &Self::Target {
> + &self.remotes
> + }
> +}
> +
> +impl DerefMut for RemoteUpdateSummaryWrapper {
> + fn deref_mut(&mut self) -> &mut Self::Target {
> + &mut self.remotes
> + }
> +}
> +
> +#[api]
> +#[derive(Clone, Debug, Deserialize, Serialize)]
> +#[serde(rename_all = "kebab-case")]
> +/// Update summary for a single remote.
> +pub struct RemoteUpdateSummary {
> + /// Map containing the update summary for each node of this remote.
> + pub nodes: NodeUpdateSummaryWrapper,
> + pub remote_type: RemoteType,
> + pub status: RemoteUpdateStatus,
> +}
> +
> +#[api]
> +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
> +#[serde(rename_all = "kebab-case")]
> +/// Status for the entire remote.
> +pub enum RemoteUpdateStatus {
> + /// Successfully polled remote.
> + Success,
> + /// Remote could not be polled.
> + Error,
> + /// Remote has not been polled yet.
> + Unknown,
> +}
> +
> +#[derive(Clone, Debug, Default, Deserialize, Serialize)]
> +#[serde(rename_all = "kebab-case")]
> +pub struct NodeUpdateSummaryWrapper {
> + #[serde(flatten)]
> + nodes: HashMap<String, NodeUpdateSummary>,
> +}
> +
> +impl ApiType for NodeUpdateSummaryWrapper {
> + const API_SCHEMA: proxmox_schema::Schema =
> + ObjectSchema::new("Map of per-node update summaries", &[])
> + .additional_properties(true)
> + .schema();
> +}
> +
> +impl Deref for NodeUpdateSummaryWrapper {
> + type Target = HashMap<String, NodeUpdateSummary>;
> +
> + fn deref(&self) -> &Self::Target {
> + &self.nodes
> + }
> +}
> +
> +impl DerefMut for NodeUpdateSummaryWrapper {
> + fn deref_mut(&mut self) -> &mut Self::Target {
> + &mut self.nodes
> + }
> +}
> +
> +#[api]
> +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
> +#[serde(rename_all = "kebab-case")]
> +/// Status for the entire remote.
> +pub enum NodeUpdateStatus {
> + /// Successfully polled node.
> + Success,
> + /// Node could not be polled.
> + Error,
> +}
> +
> +#[api]
> +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
> +#[serde(rename_all = "kebab-case")]
> +/// Per-node update summary.
> +pub struct NodeUpdateSummary {
> + /// Number of available updates.
> + pub number_of_updates: u32,
> + /// Unix timestamp of the last refresh.
> + pub last_refresh: i64,
> + /// Status
> + pub status: NodeUpdateStatus,
> + /// Status message (e.g. error message)
> + pub status_message: Option<String>,
> +}
More information about the pdm-devel
mailing list