[pdm-devel] [PATCH datacenter-manager v4 01/10] pdm-api-types: resources: add helper methods for fields
Wolfgang Bumiller
w.bumiller at proxmox.com
Tue Sep 2 16:29:28 CEST 2025
On Thu, Aug 28, 2025 at 03:16:00PM +0200, Dominik Csapak wrote:
> namely 'resource_type' and 'status'. All resources have those fields
> in one way or another, so adding a helper that one does not have to
> use `match` on every call site makes code there shorter.
>
> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
> no changes in v4
> lib/pdm-api-types/src/resource.rs | 27 +++++++++++++++++++++++++++
> 1 file changed, 27 insertions(+)
>
> diff --git a/lib/pdm-api-types/src/resource.rs b/lib/pdm-api-types/src/resource.rs
> index 6227855..0dfadd5 100644
> --- a/lib/pdm-api-types/src/resource.rs
> +++ b/lib/pdm-api-types/src/resource.rs
> @@ -62,6 +62,33 @@ impl Resource {
> Resource::PbsDatastore(r) => r.name.as_str(),
> }
> }
> +
> + pub fn resource_type(&self) -> &str {
^ This may be nicer as simple `enum` with a `Display`/`FromStr`
implementation.
> + match self {
> + Resource::PveStorage(_) => "storage",
> + Resource::PveQemu(_) => "qemu",
> + Resource::PveLxc(_) => "lxc",
> + Resource::PveNode(_) | Resource::PbsNode(_) => "node",
> + Resource::PbsDatastore(_) => "datastore",
> + }
> + }
> +
> + pub fn status(&self) -> &str {
> + match self {
> + Resource::PveStorage(r) => r.status.as_str(),
> + Resource::PveQemu(r) => r.status.as_str(),
> + Resource::PveLxc(r) => r.status.as_str(),
> + Resource::PveNode(r) => r.status.as_str(),
> + Resource::PbsNode(r) => {
> + if r.uptime > 0 {
> + "online"
> + } else {
> + "offline"
> + }
> + }
> + Resource::PbsDatastore(_) => "online",
> + }
> + }
> }
>
> #[api(
> --
> 2.47.2
More information about the pdm-devel
mailing list