diff --git a/src/bin/proxmox-backup-client.rs b/src/bin/proxmox-backup-client.rs index 28eabaee..dfb944f0 100644 --- a/src/bin/proxmox-backup-client.rs +++ b/src/bin/proxmox-backup-client.rs @@ -552,7 +552,7 @@ async fn start_garbage_collection(param: Value) -> Result { record_repository(&repo); - view_task_result(client, result, &output_format).await?; + view_task_result(&mut client, result, &output_format).await?; Ok(Value::Null) } diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs index a3a53d04..6b074d6d 100644 --- a/src/bin/proxmox-backup-manager.rs +++ b/src/bin/proxmox-backup-manager.rs @@ -40,7 +40,7 @@ async fn start_garbage_collection(param: Value) -> Result { let result = client.post(&path, None).await?; - view_task_result(client, result, &output_format).await?; + view_task_result(&mut client, result, &output_format).await?; Ok(Value::Null) } @@ -164,9 +164,9 @@ async fn task_log(param: Value) -> Result { let upid = tools::required_string_param(¶m, "upid")?; - let client = connect_to_localhost()?; + let mut client = connect_to_localhost()?; - display_task_log(client, upid, true).await?; + display_task_log(&mut client, upid, true).await?; Ok(Value::Null) } @@ -258,7 +258,7 @@ async fn pull_datastore( let result = client.post("api2/json/pull", Some(args)).await?; - view_task_result(client, result, &output_format).await?; + view_task_result(&mut client, result, &output_format).await?; Ok(Value::Null) } @@ -292,7 +292,7 @@ async fn verify( let result = client.post(&path, Some(args)).await?; - view_task_result(client, result, &output_format).await?; + view_task_result(&mut client, result, &output_format).await?; Ok(Value::Null) } diff --git a/src/bin/proxmox-tape.rs b/src/bin/proxmox-tape.rs index 0176fd74..31e24ca3 100644 --- a/src/bin/proxmox-tape.rs +++ b/src/bin/proxmox-tape.rs @@ -120,7 +120,7 @@ async fn erase_media(param: Value) -> Result<(), Error> { let path = format!("api2/json/tape/drive/{}/erase-media", drive); let result = client.post(&path, Some(param)).await?; - view_task_result(client, result, &output_format).await?; + view_task_result(&mut client, result, &output_format).await?; Ok(()) } @@ -153,7 +153,7 @@ async fn rewind(param: Value) -> Result<(), Error> { let path = format!("api2/json/tape/drive/{}/rewind", drive); let result = client.post(&path, Some(param)).await?; - view_task_result(client, result, &output_format).await?; + view_task_result(&mut client, result, &output_format).await?; Ok(()) } @@ -186,7 +186,7 @@ async fn eject_media(param: Value) -> Result<(), Error> { let path = format!("api2/json/tape/drive/{}/eject-media", drive); let result = client.post(&path, Some(param)).await?; - view_task_result(client, result, &output_format).await?; + view_task_result(&mut client, result, &output_format).await?; Ok(()) } @@ -343,7 +343,7 @@ async fn label_media(param: Value) -> Result<(), Error> { let path = format!("api2/json/tape/drive/{}/label-media", drive); let result = client.post(&path, Some(param)).await?; - view_task_result(client, result, &output_format).await?; + view_task_result(&mut client, result, &output_format).await?; Ok(()) } @@ -428,7 +428,6 @@ async fn inventory( read_labels: Option, read_all_labels: Option, param: Value, - rpcenv: &mut dyn RpcEnvironment, ) -> Result<(), Error> { let output_format = get_output_format(¶m); @@ -438,28 +437,25 @@ async fn inventory( let do_read = read_labels.unwrap_or(false) || read_all_labels.unwrap_or(false); + let mut client = connect_to_localhost()?; + + let path = format!("api2/json/tape/drive/{}/inventory", drive); + if do_read { - let mut param = json!({ - "drive": &drive, - }); + + let mut param = json!({}); if let Some(true) = read_all_labels { param["read-all-labels"] = true.into(); } - let info = &api2::tape::drive::API_METHOD_UPDATE_INVENTORY; - let result = match info.handler { - ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, - _ => unreachable!(), - }; - wait_for_local_worker(result.as_str().unwrap()).await?; + + let result = client.put(&path, Some(param)).await?; // update inventory + view_task_result(&mut client, result, &output_format).await?; } - let info = &api2::tape::drive::API_METHOD_INVENTORY; + let mut result = client.get(&path, None).await?; + let mut data = result["data"].take(); - let param = json!({ "drive": &drive }); - let mut data = match info.handler { - ApiHandler::Async(handler) => (handler)(param, info, rpcenv).await?, - _ => unreachable!(), - }; + let info = &api2::tape::drive::API_METHOD_INVENTORY; let options = default_table_format_options() .column(ColumnConfig::new("label-text")) @@ -796,7 +792,7 @@ async fn backup(param: Value) -> Result<(), Error> { let result = client.post("api2/json/tape/backup", Some(param)).await?; - view_task_result(client, result, &output_format).await?; + view_task_result(&mut client, result, &output_format).await?; Ok(()) } diff --git a/src/bin/proxmox_backup_client/task.rs b/src/bin/proxmox_backup_client/task.rs index e4adaf58..dc71ab27 100644 --- a/src/bin/proxmox_backup_client/task.rs +++ b/src/bin/proxmox_backup_client/task.rs @@ -96,9 +96,9 @@ async fn task_log(param: Value) -> Result { let repo = extract_repository_from_value(¶m)?; let upid = tools::required_string_param(¶m, "upid")?; - let client = connect(&repo)?; + let mut client = connect(&repo)?; - display_task_log(client, upid, true).await?; + display_task_log(&mut client, upid, true).await?; Ok(Value::Null) } diff --git a/src/client/task_log.rs b/src/client/task_log.rs index 64fac163..695e6f3b 100644 --- a/src/client/task_log.rs +++ b/src/client/task_log.rs @@ -24,7 +24,7 @@ use crate::{ /// the user presses CTRL-C. Two interrupts cause an immediate end of /// the loop. The task may still run in that case. pub async fn display_task_log( - mut client: HttpClient, + client: &mut HttpClient, upid_str: &str, strip_date: bool, ) -> Result<(), Error> { @@ -106,7 +106,7 @@ pub async fn display_task_log( /// Display task result (upid), or view task log - depending on output format pub async fn view_task_result( - client: HttpClient, + client: &mut HttpClient, result: Value, output_format: &str, ) -> Result<(), Error> {