tape: changer status command: make changer name optional
This commit is contained in:
parent
46a1863f88
commit
482c6e33dd
@ -73,7 +73,7 @@ pub async fn wait_for_local_worker(upid_str: &str) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn lookup_drive_name(
|
||||
pub fn lookup_drive_name(
|
||||
param: &Value,
|
||||
config: &SectionConfigData,
|
||||
) -> Result<String, Error> {
|
||||
|
@ -1,4 +1,4 @@
|
||||
use anyhow::{Error};
|
||||
use anyhow::{bail, Error};
|
||||
use serde_json::Value;
|
||||
|
||||
use proxmox::{
|
||||
@ -7,6 +7,7 @@ use proxmox::{
|
||||
cli::*,
|
||||
RpcEnvironment,
|
||||
ApiHandler,
|
||||
section_config::SectionConfigData,
|
||||
},
|
||||
};
|
||||
|
||||
@ -19,8 +20,10 @@ use proxmox_backup::{
|
||||
},
|
||||
tape::{
|
||||
complete_changer_path,
|
||||
media_changer,
|
||||
},
|
||||
config::{
|
||||
self,
|
||||
drive::{
|
||||
complete_drive_name,
|
||||
complete_changer_name,
|
||||
@ -28,6 +31,24 @@ use proxmox_backup::{
|
||||
},
|
||||
};
|
||||
|
||||
pub fn lookup_changer_name(
|
||||
param: &Value,
|
||||
config: &SectionConfigData,
|
||||
) -> Result<String, Error> {
|
||||
|
||||
if let Some(name) = param["name"].as_str() {
|
||||
return Ok(String::from(name));
|
||||
}
|
||||
|
||||
if let Ok(drive) = crate::lookup_drive_name(&Value::Null, config) {
|
||||
if let Ok(Some((_, name))) = media_changer(config, &drive) {
|
||||
return Ok(name);
|
||||
}
|
||||
}
|
||||
|
||||
bail!("unable to get (default) changer name");
|
||||
}
|
||||
|
||||
pub fn changer_commands() -> CommandLineInterface {
|
||||
|
||||
let cmd_def = CliCommandMap::new()
|
||||
@ -188,18 +209,23 @@ fn get_config(
|
||||
schema: OUTPUT_FORMAT,
|
||||
optional: true,
|
||||
},
|
||||
name: {
|
||||
name: {
|
||||
schema: CHANGER_NAME_SCHEMA,
|
||||
optional: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
)]
|
||||
/// Get tape changer status
|
||||
async fn get_status(
|
||||
param: Value,
|
||||
mut param: Value,
|
||||
rpcenv: &mut dyn RpcEnvironment,
|
||||
) -> Result<(), Error> {
|
||||
|
||||
let (config, _digest) = config::drive::config()?;
|
||||
|
||||
param["name"] = lookup_changer_name(¶m, &config)?.into();
|
||||
|
||||
let output_format = get_output_format(¶m);
|
||||
let info = &api2::tape::changer::API_METHOD_GET_STATUS;
|
||||
let mut data = match info.handler {
|
||||
@ -218,7 +244,7 @@ async fn get_status(
|
||||
Ok(text)
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
let options = default_table_format_options()
|
||||
.sortby("entry-kind", false)
|
||||
.sortby("entry-id", false)
|
||||
|
Loading…
Reference in New Issue
Block a user