[pdm-devel] [RFC datacenter-manager 6/8] pdm-api-types: remote upid: allow to get native UPID type
Lukas Wagner
l.wagner at proxmox.com
Tue Nov 11 11:50:57 CET 2025
In some places where RemoteUpids are handled, the native UPID type needs
to be accessed, e.g. to access some of its fields. This commit adds the
`native_upid` function, which will parse the raw UPID based on the type
and return the native, product-specific UPID type.
Signed-off-by: Lukas Wagner <l.wagner at proxmox.com>
---
lib/pdm-api-types/src/remote_upid.rs | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/lib/pdm-api-types/src/remote_upid.rs b/lib/pdm-api-types/src/remote_upid.rs
index 32106e42..10d3c1dc 100644
--- a/lib/pdm-api-types/src/remote_upid.rs
+++ b/lib/pdm-api-types/src/remote_upid.rs
@@ -20,6 +20,12 @@ pub struct RemoteUpid {
upid: String,
}
+/// Type containing the parsed, native UPID for each type of remote.
+pub enum NativeUpid {
+ PveUpid(pve_api_types::PveUpid),
+ PbsUpid(pbs_api_types::UPID),
+}
+
impl RemoteUpid {
/// Create a new remote UPID.
pub fn new(remote: String, remote_type: RemoteType, upid: String) -> Self {
@@ -54,6 +60,16 @@ impl RemoteUpid {
self.remote_type
}
+ /// Get the parsed, native UPID type.
+ ///
+ /// This function will return an error if the UPID could not be parsed.
+ pub fn native_upid(&self) -> Result<NativeUpid, Error> {
+ Ok(match self.remote_type() {
+ RemoteType::Pve => NativeUpid::PveUpid(self.upid.parse()?),
+ RemoteType::Pbs => NativeUpid::PbsUpid(self.upid.parse()?),
+ })
+ }
+
fn deduce_type(raw_upid: &str) -> Result<RemoteType, Error> {
if raw_upid.parse::<pve_api_types::PveUpid>().is_ok() {
Ok(RemoteType::Pve)
--
2.47.3
More information about the pdm-devel
mailing list