tape: proxmox-tape inventory: call API

This commit is contained in:
Dietmar Maurer 2021-01-29 11:21:57 +01:00
parent 5243df4712
commit e68269fcaf
5 changed files with 27 additions and 31 deletions

View File

@ -552,7 +552,7 @@ async fn start_garbage_collection(param: Value) -> Result<Value, Error> {
record_repository(&repo); record_repository(&repo);
view_task_result(client, result, &output_format).await?; view_task_result(&mut client, result, &output_format).await?;
Ok(Value::Null) Ok(Value::Null)
} }

View File

@ -40,7 +40,7 @@ async fn start_garbage_collection(param: Value) -> Result<Value, Error> {
let result = client.post(&path, None).await?; 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) Ok(Value::Null)
} }
@ -164,9 +164,9 @@ async fn task_log(param: Value) -> Result<Value, Error> {
let upid = tools::required_string_param(&param, "upid")?; let upid = tools::required_string_param(&param, "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) Ok(Value::Null)
} }
@ -258,7 +258,7 @@ async fn pull_datastore(
let result = client.post("api2/json/pull", Some(args)).await?; 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) Ok(Value::Null)
} }
@ -292,7 +292,7 @@ async fn verify(
let result = client.post(&path, Some(args)).await?; 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) Ok(Value::Null)
} }

View File

@ -120,7 +120,7 @@ async fn erase_media(param: Value) -> Result<(), Error> {
let path = format!("api2/json/tape/drive/{}/erase-media", drive); let path = format!("api2/json/tape/drive/{}/erase-media", drive);
let result = client.post(&path, Some(param)).await?; 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(()) Ok(())
} }
@ -153,7 +153,7 @@ async fn rewind(param: Value) -> Result<(), Error> {
let path = format!("api2/json/tape/drive/{}/rewind", drive); let path = format!("api2/json/tape/drive/{}/rewind", drive);
let result = client.post(&path, Some(param)).await?; 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(()) Ok(())
} }
@ -186,7 +186,7 @@ async fn eject_media(param: Value) -> Result<(), Error> {
let path = format!("api2/json/tape/drive/{}/eject-media", drive); let path = format!("api2/json/tape/drive/{}/eject-media", drive);
let result = client.post(&path, Some(param)).await?; 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(()) Ok(())
} }
@ -343,7 +343,7 @@ async fn label_media(param: Value) -> Result<(), Error> {
let path = format!("api2/json/tape/drive/{}/label-media", drive); let path = format!("api2/json/tape/drive/{}/label-media", drive);
let result = client.post(&path, Some(param)).await?; 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(()) Ok(())
} }
@ -428,7 +428,6 @@ async fn inventory(
read_labels: Option<bool>, read_labels: Option<bool>,
read_all_labels: Option<bool>, read_all_labels: Option<bool>,
param: Value, param: Value,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<(), Error> { ) -> Result<(), Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
@ -438,28 +437,25 @@ async fn inventory(
let do_read = read_labels.unwrap_or(false) || read_all_labels.unwrap_or(false); 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 { if do_read {
let mut param = json!({
"drive": &drive, let mut param = json!({});
});
if let Some(true) = read_all_labels { if let Some(true) = read_all_labels {
param["read-all-labels"] = true.into(); param["read-all-labels"] = true.into();
} }
let info = &api2::tape::drive::API_METHOD_UPDATE_INVENTORY;
let result = match info.handler { let result = client.put(&path, Some(param)).await?; // update inventory
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, view_task_result(&mut client, result, &output_format).await?;
_ => unreachable!(),
};
wait_for_local_worker(result.as_str().unwrap()).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 info = &api2::tape::drive::API_METHOD_INVENTORY;
let mut data = match info.handler {
ApiHandler::Async(handler) => (handler)(param, info, rpcenv).await?,
_ => unreachable!(),
};
let options = default_table_format_options() let options = default_table_format_options()
.column(ColumnConfig::new("label-text")) .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?; 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(()) Ok(())
} }

View File

@ -96,9 +96,9 @@ async fn task_log(param: Value) -> Result<Value, Error> {
let repo = extract_repository_from_value(&param)?; let repo = extract_repository_from_value(&param)?;
let upid = tools::required_string_param(&param, "upid")?; let upid = tools::required_string_param(&param, "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) Ok(Value::Null)
} }

View File

@ -24,7 +24,7 @@ use crate::{
/// the user presses CTRL-C. Two interrupts cause an immediate end of /// the user presses CTRL-C. Two interrupts cause an immediate end of
/// the loop. The task may still run in that case. /// the loop. The task may still run in that case.
pub async fn display_task_log( pub async fn display_task_log(
mut client: HttpClient, client: &mut HttpClient,
upid_str: &str, upid_str: &str,
strip_date: bool, strip_date: bool,
) -> Result<(), Error> { ) -> Result<(), Error> {
@ -106,7 +106,7 @@ pub async fn display_task_log(
/// Display task result (upid), or view task log - depending on output format /// Display task result (upid), or view task log - depending on output format
pub async fn view_task_result( pub async fn view_task_result(
client: HttpClient, client: &mut HttpClient,
result: Value, result: Value,
output_format: &str, output_format: &str,
) -> Result<(), Error> { ) -> Result<(), Error> {