[pbs-devel] [PATCH proxmox-backup 4/4] api2/tape/changer: reorganize api

Dominik Csapak d.csapak at proxmox.com
Mon Jan 25 16:30:57 CET 2021


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 at 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






More information about the pbs-devel mailing list