2020-12-14 06:55:57 +00:00
|
|
|
use anyhow::{Error};
|
|
|
|
use serde_json::Value;
|
|
|
|
|
|
|
|
use proxmox::{
|
|
|
|
api::{
|
|
|
|
api,
|
|
|
|
cli::*,
|
|
|
|
RpcEnvironment,
|
|
|
|
ApiHandler,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
use proxmox_backup::{
|
|
|
|
api2::{
|
|
|
|
self,
|
|
|
|
types::{
|
|
|
|
MEDIA_POOL_NAME_SCHEMA,
|
|
|
|
MediaStatus,
|
|
|
|
MediaListEntry,
|
|
|
|
},
|
|
|
|
},
|
2020-12-14 07:58:40 +00:00
|
|
|
tape::complete_media_changer_id,
|
2020-12-14 06:55:57 +00:00
|
|
|
config::{
|
|
|
|
media_pool::complete_pool_name,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
pub fn media_commands() -> CommandLineInterface {
|
|
|
|
|
|
|
|
let cmd_def = CliCommandMap::new()
|
|
|
|
.insert(
|
|
|
|
"list",
|
|
|
|
CliCommand::new(&API_METHOD_LIST_MEDIA)
|
|
|
|
.completion_cb("pool", complete_pool_name)
|
|
|
|
)
|
2020-12-14 07:58:40 +00:00
|
|
|
.insert(
|
2020-12-14 08:30:32 +00:00
|
|
|
"destroy",
|
2020-12-14 07:58:40 +00:00
|
|
|
CliCommand::new(&api2::tape::media::API_METHOD_DESTROY_MEDIA)
|
|
|
|
.arg_param(&["changer-id"])
|
|
|
|
.completion_cb("changer-id", complete_media_changer_id)
|
|
|
|
)
|
2020-12-14 06:55:57 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
cmd_def.into()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
pool: {
|
|
|
|
schema: MEDIA_POOL_NAME_SCHEMA,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
"output-format": {
|
|
|
|
schema: OUTPUT_FORMAT,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// List pool media
|
|
|
|
async fn list_media(
|
|
|
|
param: Value,
|
|
|
|
rpcenv: &mut dyn RpcEnvironment,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
|
|
|
|
let output_format = get_output_format(¶m);
|
|
|
|
let info = &api2::tape::media::API_METHOD_LIST_MEDIA;
|
|
|
|
let mut data = match info.handler {
|
|
|
|
ApiHandler::Async(handler) => (handler)(param, info, rpcenv).await?,
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
|
|
|
|
fn render_status(_value: &Value, record: &Value) -> Result<String, Error> {
|
|
|
|
let record: MediaListEntry = serde_json::from_value(record.clone())?;
|
|
|
|
Ok(match record.status {
|
|
|
|
MediaStatus::Damaged | MediaStatus::Retired => {
|
|
|
|
serde_json::to_value(&record.status)?
|
|
|
|
.as_str().unwrap()
|
|
|
|
.to_string()
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
if record.expired {
|
|
|
|
String::from("expired")
|
|
|
|
} else {
|
|
|
|
serde_json::to_value(&record.status)?
|
|
|
|
.as_str().unwrap()
|
|
|
|
.to_string()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
let options = default_table_format_options()
|
|
|
|
.sortby("pool", false)
|
|
|
|
.sortby("media-set-uuid", false)
|
|
|
|
.sortby("seq-nr", false)
|
|
|
|
.sortby("changer-id", false)
|
|
|
|
.column(ColumnConfig::new("changer-id"))
|
|
|
|
.column(ColumnConfig::new("pool"))
|
|
|
|
.column(ColumnConfig::new("media-set-name"))
|
|
|
|
.column(ColumnConfig::new("seq-nr"))
|
|
|
|
.column(ColumnConfig::new("status").renderer(render_status))
|
2020-12-16 09:45:58 +00:00
|
|
|
.column(ColumnConfig::new("location"))
|
2020-12-14 06:55:57 +00:00
|
|
|
.column(ColumnConfig::new("uuid"))
|
|
|
|
.column(ColumnConfig::new("media-set-uuid"))
|
|
|
|
;
|
|
|
|
|
2020-12-18 11:26:07 +00:00
|
|
|
format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
|
2020-12-14 06:55:57 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|