From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 31CDE1FF17A for ; Tue, 11 Nov 2025 11:50:28 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id ED9B36497; Tue, 11 Nov 2025 11:51:13 +0100 (CET) From: Lukas Wagner To: pdm-devel@lists.proxmox.com Date: Tue, 11 Nov 2025 11:50:53 +0100 Message-ID: <20251111105059.148997-3-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251111105059.148997-1-l.wagner@proxmox.com> References: <20251111105059.148997-1-l.wagner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1762858243283 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.028 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [tasks.rs, mod.rs] Subject: [pdm-devel] [PATCH datacenter-manager 2/8] pdm-api-types: remote upid: make upid field private X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" Shielding members behind a getter is beneficial in most cases. This makes it easier to change the internal representation of the type later. Signed-off-by: Lukas Wagner --- lib/pdm-api-types/src/remote_upid.rs | 12 +++++++++++- server/src/api/pve/tasks.rs | 18 +++++++++--------- server/src/remote_tasks/mod.rs | 2 +- server/src/remote_tasks/task_cache.rs | 2 +- server/src/sdn_client.rs | 2 +- ui/src/tasks.rs | 4 ++-- 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/lib/pdm-api-types/src/remote_upid.rs b/lib/pdm-api-types/src/remote_upid.rs index bf7c1797..6b0f8461 100644 --- a/lib/pdm-api-types/src/remote_upid.rs +++ b/lib/pdm-api-types/src/remote_upid.rs @@ -13,7 +13,7 @@ pub const REMOTE_UPID_SCHEMA: Schema = StringSchema::new("A remote UPID") pub struct RemoteUpid { remote: String, /// This is usually a pve upid, but may also be a pbs upid, they have distinct formats. - pub upid: String, + upid: String, } impl RemoteUpid { @@ -24,6 +24,16 @@ impl RemoteUpid { pub fn into_remote(self) -> String { self.remote } + + /// Get the raw UPID. + pub fn upid(&self) -> &str { + &self.upid + } + + /// Get the raw UPID, consuming self. + pub fn into_upid(self) -> String { + self.upid + } } impl ApiType for RemoteUpid { diff --git a/server/src/api/pve/tasks.rs b/server/src/api/pve/tasks.rs index 0371fa00..9f04a448 100644 --- a/server/src/api/pve/tasks.rs +++ b/server/src/api/pve/tasks.rs @@ -89,13 +89,13 @@ async fn stop_task(remote: String, upid: RemoteUpid) -> Result<(), Error> { let pve = get_remote(&remotes, upid.remote())?; let pve_upid: PveUpid = upid - .upid + .upid() .parse() - .map_err(|err| format_err!("invalid upid for PVE: {} - {err}", upid.upid))?; + .map_err(|err| format_err!("invalid upid for PVE: {} - {err}", upid.upid()))?; let pve = connect(pve)?; - Ok(pve.stop_task(&pve_upid.node, &upid.upid).await?) + Ok(pve.stop_task(&pve_upid.node, upid.upid()).await?) } #[api( @@ -135,14 +135,14 @@ pub async fn get_task_status( let pve = get_remote(&remotes, upid.remote())?; let pve_upid: PveUpid = upid - .upid + .upid() .parse() - .map_err(|err| format_err!("invalid upid for PVE: {} - {err}", upid.upid))?; + .map_err(|err| format_err!("invalid upid for PVE: {} - {err}", upid.upid()))?; let pve = connect(pve)?; loop { - let status = pve.get_task_status(&pve_upid.node, &upid.upid).await?; + let status = pve.get_task_status(&pve_upid.node, upid.upid()).await?; if !wait || !status.is_running() { break Ok(status); } @@ -218,14 +218,14 @@ async fn read_task_log( let pve = get_remote(&remotes, upid.remote())?; let pve_upid: PveUpid = upid - .upid + .upid() .parse() - .map_err(|err| format_err!("invalid upid for PVE: {} - {err}", upid.upid))?; + .map_err(|err| format_err!("invalid upid for PVE: {} - {err}", upid.upid()))?; let pve = connect(pve)?; let response = pve - .get_task_log(&pve_upid.node, &upid.upid, download, limit, start) + .get_task_log(&pve_upid.node, upid.upid(), download, limit, start) .await?; for (key, value) in response.attribs { diff --git a/server/src/remote_tasks/mod.rs b/server/src/remote_tasks/mod.rs index c4939742..37e689e0 100644 --- a/server/src/remote_tasks/mod.rs +++ b/server/src/remote_tasks/mod.rs @@ -53,7 +53,7 @@ pub async fn get_tasks( } } // TODO: Handle PBS tasks - let pve_upid: Result = task.upid.upid.parse(); + let pve_upid: Result = task.upid.upid().parse(); match pve_upid { Ok(pve_upid) => Some(TaskListItem { upid: task.upid.to_string(), diff --git a/server/src/remote_tasks/task_cache.rs b/server/src/remote_tasks/task_cache.rs index 040266ad..cb3b6687 100644 --- a/server/src/remote_tasks/task_cache.rs +++ b/server/src/remote_tasks/task_cache.rs @@ -407,7 +407,7 @@ impl WritableTaskCache { // TODO:: Handle PBS tasks correctly. // TODO: This is awkward, maybe overhaul RemoteUpid type to make this easier - match task.upid.upid.parse::() { + match task.upid.upid().parse::() { Ok(upid) => { let node = &upid.node; let remote = task.upid.remote(); diff --git a/server/src/sdn_client.rs b/server/src/sdn_client.rs index f88d2a52..6b6bdfa9 100644 --- a/server/src/sdn_client.rs +++ b/server/src/sdn_client.rs @@ -334,7 +334,7 @@ impl LockedSdnClients { loop { tokio::time::sleep(Self::POLLING_INTERVAL).await; - let status = client.get_task_status(&node, &upid.upid).await?; + let status = client.get_task_status(&node, upid.upid()).await?; if !status.is_running() { if status.finished_successfully() == Some(true) { diff --git a/ui/src/tasks.rs b/ui/src/tasks.rs index 4ff29755..41a8648d 100644 --- a/ui/src/tasks.rs +++ b/ui/src/tasks.rs @@ -112,9 +112,9 @@ pub fn register_pve_tasks() { /// If it's a [`RemoteUpid`], prefixes it with the remote name pub fn format_optional_remote_upid(upid: &str, include_remote: bool) -> String { if let Ok(remote_upid) = upid.parse::() { - let description = match remote_upid.upid.parse::() { + let description = match remote_upid.upid().parse::() { Ok(upid) => format_task_description(&upid.worker_type, upid.worker_id.as_deref()), - Err(_) => format_upid(&remote_upid.upid), + Err(_) => format_upid(&remote_upid.upid()), }; if include_remote { format!("{} - {}", remote_upid.remote(), description) -- 2.47.3 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel