public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 4/4] api2/tape/changer: reorganize api
Date: Mon, 25 Jan 2021 16:30:57 +0100	[thread overview]
Message-ID: <20210125153057.30061-4-d.csapak@proxmox.com> (raw)
In-Reply-To: <20210125153057.30061-1-d.csapak@proxmox.com>

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>
---
 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<ScsiTapeChanger> = 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<Vec<TapeDeviceInfo>, 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<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,
+            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(&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 {
         ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
         _ => unreachable!(),
-- 
2.20.1





  parent reply	other threads:[~2021-01-25 15:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-25 15:30 [pbs-devel] [PATCH proxmox-backup 1/4] docs/tape: fix some typos and improve wording Dominik Csapak
2021-01-25 15:30 ` [pbs-devel] [PATCH proxmox-backup 2/4] tape: fix typos Dominik Csapak
2021-01-26 11:42   ` Dietmar Maurer
2021-01-25 15:30 ` [pbs-devel] [PATCH proxmox-backup 3/4] api2/types/tape/drive: add changer_slot Dominik Csapak
2021-01-26 11:43   ` Dietmar Maurer
2021-01-26 12:10     ` Dominik Csapak
2021-01-26 14:19       ` Dietmar Maurer
2021-01-25 15:30 ` Dominik Csapak [this message]
2021-01-26 11:48   ` [pbs-devel] [PATCH proxmox-backup 4/4] api2/tape/changer: reorganize api Dietmar Maurer
2021-01-26 11:42 ` [pbs-devel] [PATCH proxmox-backup 1/4] docs/tape: fix some typos and improve wording Dietmar Maurer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210125153057.30061-4-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal