diff --git a/src/api2/tape/drive.rs b/src/api2/tape/drive.rs index 8e224d28..1e792f58 100644 --- a/src/api2/tape/drive.rs +++ b/src/api2/tape/drive.rs @@ -1181,7 +1181,7 @@ pub const SUBDIRS: SubdirMap = &sorted!([ ( "erase-media", &Router::new() - .put(&API_METHOD_ERASE_MEDIA) + .post(&API_METHOD_ERASE_MEDIA) ), ( "inventory", @@ -1222,7 +1222,7 @@ pub const SUBDIRS: SubdirMap = &sorted!([ ( "rewind", &Router::new() - .put(&API_METHOD_REWIND) + .post(&API_METHOD_REWIND) ), ( "status", diff --git a/src/bin/proxmox-tape.rs b/src/bin/proxmox-tape.rs index 016267b3..76658e67 100644 --- a/src/bin/proxmox-tape.rs +++ b/src/bin/proxmox-tape.rs @@ -138,27 +138,28 @@ pub fn lookup_drive_name( optional: true, default: true, }, - }, + "output-format": { + schema: OUTPUT_FORMAT, + optional: true, + }, + }, }, )] /// Erase media -async fn erase_media( - mut param: Value, - rpcenv: &mut dyn RpcEnvironment, -) -> Result<(), Error> { +async fn erase_media(param: Value) -> Result<(), Error> { + + let output_format = get_output_format(¶m); let (config, _digest) = config::drive::config()?; - param["drive"] = lookup_drive_name(¶m, &config)?.into(); + let drive = lookup_drive_name(¶m, &config)?; - let info = &api2::tape::drive::API_METHOD_ERASE_MEDIA; + let mut client = connect_to_localhost()?; - let result = match info.handler { - ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, - _ => unreachable!(), - }; + let path = format!("api2/json/tape/drive/{}/erase-media", drive); + let result = client.post(&path, Some(param)).await?; - wait_for_local_worker(result.as_str().unwrap()).await?; + view_task_result(client, result, &output_format).await?; Ok(()) } @@ -170,27 +171,28 @@ async fn erase_media( schema: DRIVE_NAME_SCHEMA, optional: true, }, + "output-format": { + schema: OUTPUT_FORMAT, + optional: true, + }, }, }, )] /// Rewind tape -async fn rewind( - mut param: Value, - rpcenv: &mut dyn RpcEnvironment, -) -> Result<(), Error> { +async fn rewind(param: Value) -> Result<(), Error> { + + let output_format = get_output_format(¶m); let (config, _digest) = config::drive::config()?; - param["drive"] = lookup_drive_name(¶m, &config)?.into(); + let drive = lookup_drive_name(¶m, &config)?; - let info = &api2::tape::drive::API_METHOD_REWIND; + let mut client = connect_to_localhost()?; - let result = match info.handler { - ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, - _ => unreachable!(), - }; + let path = format!("api2/json/tape/drive/{}/rewind", drive); + let result = client.post(&path, Some(param)).await?; - wait_for_local_worker(result.as_str().unwrap()).await?; + view_task_result(client, result, &output_format).await?; Ok(()) }