api2/tape/changer: reorganize api

add a changer listing here (copied from api2/config/changer)
and put the status and transfer api calls below that

puts the changer scan into the top level tape api
and removes the (now redundant) info from the config api path

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2021-01-25 16:30:57 +01:00 committed by Dietmar Maurer
parent bbf01b644c
commit 740dc9d1d4
4 changed files with 68 additions and 17 deletions

View File

@ -24,7 +24,6 @@ use crate::{
tape::{ tape::{
linux_tape_changer_list, linux_tape_changer_list,
check_drive_path, check_drive_path,
lookup_drive,
}, },
}; };
@ -126,28 +125,19 @@ pub fn list_changers(
let (config, digest) = config::drive::config()?; let (config, digest) = config::drive::config()?;
let linux_changers = linux_tape_changer_list();
let changer_list: Vec<ScsiTapeChanger> = config.convert_to_typed_array("changer")?; let changer_list: Vec<ScsiTapeChanger> = config.convert_to_typed_array("changer")?;
let mut list = Vec::new(); let mut list = Vec::new();
for changer in changer_list { for changer in changer_list {
let mut entry = DriveListEntry { list.push(DriveListEntry {
name: changer.name, name: changer.name,
path: changer.path.clone(), path: changer.path.clone(),
changer: None, changer: None,
vendor: None, vendor: None,
model: None, model: None,
serial: None, serial: None,
}; });
if let Some(info) = lookup_drive(&linux_changers, &changer.path) {
entry.vendor = Some(info.vendor.clone());
entry.model = Some(info.model.clone());
entry.serial = Some(info.serial.clone());
}
list.push(entry);
} }
rpcenv["digest"] = proxmox::tools::digest_to_hex(&digest).into(); rpcenv["digest"] = proxmox::tools::digest_to_hex(&digest).into();

View File

@ -10,6 +10,7 @@ use crate::{
config, config,
api2::types::{ api2::types::{
CHANGER_NAME_SCHEMA, CHANGER_NAME_SCHEMA,
DriveListEntry,
ScsiTapeChanger, ScsiTapeChanger,
TapeDeviceInfo, TapeDeviceInfo,
MtxStatusEntry, MtxStatusEntry,
@ -25,6 +26,7 @@ use crate::{
ScsiMediaChange, ScsiMediaChange,
mtx_status_to_online_set, mtx_status_to_online_set,
}, },
lookup_drive,
}, },
}; };
@ -155,14 +157,68 @@ pub fn scan_changers(_param: Value) -> Result<Vec<TapeDeviceInfo>, Error> {
Ok(list) Ok(list)
} }
#[api(
input: {
properties: {},
},
returns: {
description: "The list of configured changers with model information.",
type: Array,
items: {
type: DriveListEntry,
},
},
)]
/// List changers
pub fn list_changers(
_param: Value,
) -> Result<Vec<DriveListEntry>, Error> {
let (config, _digest) = config::drive::config()?;
let linux_changers = linux_tape_changer_list();
let changer_list: Vec<ScsiTapeChanger> = config.convert_to_typed_array("changer")?;
let mut list = Vec::new();
for changer in changer_list {
let mut entry = DriveListEntry {
name: changer.name,
path: changer.path.clone(),
changer: None,
vendor: None,
model: None,
serial: None,
};
if let Some(info) = lookup_drive(&linux_changers, &changer.path) {
entry.vendor = Some(info.vendor.clone());
entry.model = Some(info.model.clone());
entry.serial = Some(info.serial.clone());
}
list.push(entry);
}
Ok(list)
}
const SUBDIRS: SubdirMap = &[ const SUBDIRS: SubdirMap = &[
( (
"scan", "status",
&Router::new() &Router::new()
.get(&API_METHOD_SCAN_CHANGERS) .get(&API_METHOD_GET_STATUS)
),
(
"transfer",
&Router::new()
.post(&API_METHOD_TRANSFER)
), ),
]; ];
pub const ROUTER: Router = Router::new() const ITEM_ROUTER: Router = Router::new()
.get(&list_subdirs_api_method!(SUBDIRS)) .get(&list_subdirs_api_method!(SUBDIRS))
.subdirs(SUBDIRS); .subdirs(&SUBDIRS);
pub const ROUTER: Router = Router::new()
.get(&API_METHOD_LIST_CHANGERS)
.match_all("name", &ITEM_ROUTER);

View File

@ -16,6 +16,11 @@ pub const SUBDIRS: SubdirMap = &[
("drive", &drive::ROUTER), ("drive", &drive::ROUTER),
("media", &media::ROUTER), ("media", &media::ROUTER),
("restore", &restore::ROUTER), ("restore", &restore::ROUTER),
(
"scan-changers",
&Router::new()
.get(&changer::API_METHOD_SCAN_CHANGERS),
),
]; ];
pub const ROUTER: Router = Router::new() pub const ROUTER: Router = Router::new()

View File

@ -113,7 +113,7 @@ fn list_changers(
) -> Result<(), Error> { ) -> Result<(), Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
let info = &api2::config::changer::API_METHOD_LIST_CHANGERS; let info = &api2::tape::changer::API_METHOD_LIST_CHANGERS;
let mut data = match info.handler { let mut data = match info.handler {
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
_ => unreachable!(), _ => unreachable!(),