From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 3BA531FF15E for ; Fri, 18 Oct 2024 12:00:52 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 89E5D3007E; Fri, 18 Oct 2024 12:01:27 +0200 (CEST) From: Gabriel Goller To: pbs-devel@lists.proxmox.com Date: Fri, 18 Oct 2024 12:01:22 +0200 Message-Id: <20241018100122.206452-1-g.goller@proxmox.com> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.042 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. [datastore.rs] Subject: [pbs-devel] [PATCH proxmox-backup] fix #5801: backup_manager: make api call on datastore update X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" When updating the datastore config using `proxmox-backup-manager` we need to make an api-call, because the api-route starts a tokio task to update the proxy-cache and the client will kill the task if we don't wait. With an api-call the tokio task will be executed on the api process and runs in the background while the endpoint handler has already returned. Signed-off-by: Gabriel Goller --- Note: this is not so nice, ideally we would like to call every endpoint handler directly, but I'm afraid we don't have another choice here. src/bin/proxmox_backup_manager/datastore.rs | 63 ++++++++++++++++++--- 1 file changed, 56 insertions(+), 7 deletions(-) diff --git a/src/bin/proxmox_backup_manager/datastore.rs b/src/bin/proxmox_backup_manager/datastore.rs index 383bcd242955..3a349451f62a 100644 --- a/src/bin/proxmox_backup_manager/datastore.rs +++ b/src/bin/proxmox_backup_manager/datastore.rs @@ -1,15 +1,17 @@ -use anyhow::Error; -use serde_json::Value; - +use pbs_api_types::{ + DataStoreConfig, DataStoreConfigUpdater, DATASTORE_SCHEMA, PROXMOX_CONFIG_DIGEST_SCHEMA, +}; +use pbs_client::view_task_result; use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; use proxmox_schema::api; -use pbs_api_types::{DataStoreConfig, DATASTORE_SCHEMA, PROXMOX_CONFIG_DIGEST_SCHEMA}; -use pbs_client::view_task_result; - use proxmox_backup::api2; +use proxmox_backup::api2::config::datastore::DeletableProperty; use proxmox_backup::client_helpers::connect_to_localhost; +use anyhow::Error; +use serde_json::Value; + #[api( input: { properties: { @@ -139,6 +141,53 @@ async fn delete_datastore(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Ok(()) } +#[api( + protected: true, + input: { + properties: { + name: { + schema: DATASTORE_SCHEMA, + }, + update: { + type: DataStoreConfigUpdater, + flatten: true, + }, + delete: { + description: "List of properties to delete.", + type: Array, + optional: true, + items: { + type: DeletableProperty, + } + }, + digest: { + optional: true, + schema: PROXMOX_CONFIG_DIGEST_SCHEMA, + }, + "output-format": { + schema: OUTPUT_FORMAT, + optional: true, + }, + }, + }, +)] +/// Update datastore configuration. +async fn update_datastore(name: String, mut param: Value) -> Result<(), Error> { + let output_format = extract_output_format(&mut param); + let client = connect_to_localhost()?; + + let result = client + .put( + format!("api2/json/config/datastore/{name}").as_str(), + Some(param), + ) + .await?; + + view_task_result(&client, result, &output_format).await?; + + Ok(()) +} + pub fn datastore_commands() -> CommandLineInterface { let cmd_def = CliCommandMap::new() .insert("list", CliCommand::new(&API_METHOD_LIST_DATASTORES)) @@ -154,7 +203,7 @@ pub fn datastore_commands() -> CommandLineInterface { ) .insert( "update", - CliCommand::new(&api2::config::datastore::API_METHOD_UPDATE_DATASTORE) + CliCommand::new(&API_METHOD_UPDATE_DATASTORE) .arg_param(&["name"]) .completion_cb("name", pbs_config::datastore::complete_datastore_name) .completion_cb( -- 2.39.5 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel