tape: changer status command: make changer name optional

This commit is contained in:
Dietmar Maurer 2021-01-07 15:12:19 +01:00
parent 46a1863f88
commit 482c6e33dd
2 changed files with 31 additions and 5 deletions

View File

@ -73,7 +73,7 @@ pub async fn wait_for_local_worker(upid_str: &str) -> Result<(), Error> {
Ok(()) Ok(())
} }
fn lookup_drive_name( pub fn lookup_drive_name(
param: &Value, param: &Value,
config: &SectionConfigData, config: &SectionConfigData,
) -> Result<String, Error> { ) -> Result<String, Error> {

View File

@ -1,4 +1,4 @@
use anyhow::{Error}; use anyhow::{bail, Error};
use serde_json::Value; use serde_json::Value;
use proxmox::{ use proxmox::{
@ -7,6 +7,7 @@ use proxmox::{
cli::*, cli::*,
RpcEnvironment, RpcEnvironment,
ApiHandler, ApiHandler,
section_config::SectionConfigData,
}, },
}; };
@ -19,8 +20,10 @@ use proxmox_backup::{
}, },
tape::{ tape::{
complete_changer_path, complete_changer_path,
media_changer,
}, },
config::{ config::{
self,
drive::{ drive::{
complete_drive_name, complete_drive_name,
complete_changer_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 { pub fn changer_commands() -> CommandLineInterface {
let cmd_def = CliCommandMap::new() let cmd_def = CliCommandMap::new()
@ -188,18 +209,23 @@ fn get_config(
schema: OUTPUT_FORMAT, schema: OUTPUT_FORMAT,
optional: true, optional: true,
}, },
name: { name: {
schema: CHANGER_NAME_SCHEMA, schema: CHANGER_NAME_SCHEMA,
optional: true,
}, },
}, },
}, },
)] )]
/// Get tape changer status /// Get tape changer status
async fn get_status( async fn get_status(
param: Value, mut param: Value,
rpcenv: &mut dyn RpcEnvironment, rpcenv: &mut dyn RpcEnvironment,
) -> Result<(), Error> { ) -> Result<(), Error> {
let (config, _digest) = config::drive::config()?;
param["name"] = lookup_changer_name(&param, &config)?.into();
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
let info = &api2::tape::changer::API_METHOD_GET_STATUS; let info = &api2::tape::changer::API_METHOD_GET_STATUS;
let mut data = match info.handler { let mut data = match info.handler {