From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 1217A6B07D for ; Mon, 25 Jan 2021 16:31:01 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0EA66CED1 for ; Mon, 25 Jan 2021 16:31:01 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 0F54DCEAC for ; Mon, 25 Jan 2021 16:30:59 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id C5C2A460E9 for ; Mon, 25 Jan 2021 16:30:58 +0100 (CET) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Mon, 25 Jan 2021 16:30:57 +0100 Message-Id: <20210125153057.30061-4-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210125153057.30061-1-d.csapak@proxmox.com> References: <20210125153057.30061-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.262 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup 4/4] api2/tape/changer: reorganize api X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Jan 2021 15:31:01 -0000 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 --- src/api2/config/changer.rs | 14 +------ src/api2/tape/changer.rs | 65 +++++++++++++++++++++++++++++++-- src/api2/tape/mod.rs | 5 +++ src/bin/proxmox_tape/changer.rs | 2 +- 4 files changed, 69 insertions(+), 17 deletions(-) diff --git a/src/api2/config/changer.rs b/src/api2/config/changer.rs index 3a838504..67c41856 100644 --- a/src/api2/config/changer.rs +++ b/src/api2/config/changer.rs @@ -24,7 +24,6 @@ use crate::{ tape::{ linux_tape_changer_list, check_drive_path, - lookup_drive, }, }; @@ -126,14 +125,12 @@ pub fn list_changers( let (config, digest) = config::drive::config()?; - let linux_changers = linux_tape_changer_list(); - let changer_list: Vec = config.convert_to_typed_array("changer")?; let mut list = Vec::new(); for changer in changer_list { - let mut entry = DriveListEntry { + list.push(DriveListEntry { name: changer.name, path: changer.path.clone(), changer: None, @@ -141,14 +138,7 @@ pub fn list_changers( 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); + }); } rpcenv["digest"] = proxmox::tools::digest_to_hex(&digest).into(); diff --git a/src/api2/tape/changer.rs b/src/api2/tape/changer.rs index da620c4a..3c9662b4 100644 --- a/src/api2/tape/changer.rs +++ b/src/api2/tape/changer.rs @@ -10,6 +10,7 @@ use crate::{ config, api2::types::{ CHANGER_NAME_SCHEMA, + DriveListEntry, ScsiTapeChanger, TapeDeviceInfo, MtxStatusEntry, @@ -25,6 +26,7 @@ use crate::{ ScsiMediaChange, mtx_status_to_online_set, }, + lookup_drive, }, }; @@ -155,14 +157,69 @@ pub fn scan_changers(_param: Value) -> Result, Error> { 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, Error> { + + let (config, _digest) = config::drive::config()?; + + let linux_changers = linux_tape_changer_list(); + + let changer_list: Vec = 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, + changer_slot: 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 = &[ ( - "scan", + "status", + &Router::new() + .get(&API_METHOD_GET_STATUS) + ), + ( + "transfer", &Router::new() - .get(&API_METHOD_SCAN_CHANGERS) + .post(&API_METHOD_TRANSFER) ), ]; -pub const ROUTER: Router = Router::new() +const ITEM_ROUTER: Router = Router::new() .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); diff --git a/src/api2/tape/mod.rs b/src/api2/tape/mod.rs index 8241fa05..6fbf902a 100644 --- a/src/api2/tape/mod.rs +++ b/src/api2/tape/mod.rs @@ -16,6 +16,11 @@ pub const SUBDIRS: SubdirMap = &[ ("drive", &drive::ROUTER), ("media", &media::ROUTER), ("restore", &restore::ROUTER), + ( + "scan-changers", + &Router::new() + .get(&changer::API_METHOD_SCAN_CHANGERS), + ), ]; pub const ROUTER: Router = Router::new() diff --git a/src/bin/proxmox_tape/changer.rs b/src/bin/proxmox_tape/changer.rs index db7a8b9c..0479771e 100644 --- a/src/bin/proxmox_tape/changer.rs +++ b/src/bin/proxmox_tape/changer.rs @@ -113,7 +113,7 @@ fn list_changers( ) -> Result<(), Error> { let output_format = get_output_format(¶m); - let info = &api2::config::changer::API_METHOD_LIST_CHANGERS; + let info = &api2::tape::changer::API_METHOD_LIST_CHANGERS; let mut data = match info.handler { ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, _ => unreachable!(), -- 2.20.1