From 781da7f6f0d7844d2b896351d6d990a1df447a48 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Thu, 14 Jan 2021 11:51:23 +0100 Subject: [PATCH] tape: add --inventorize flag to read-label API/CLI --- src/api2/tape/drive.rs | 20 +++++++++++++++++--- src/bin/proxmox-tape.rs | 7 ++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/api2/tape/drive.rs b/src/api2/tape/drive.rs index f124b7c6..bac19847 100644 --- a/src/api2/tape/drive.rs +++ b/src/api2/tape/drive.rs @@ -462,6 +462,10 @@ fn write_media_label( drive: { schema: DRIVE_NAME_SCHEMA, }, + inventorize: { + description: "Inventorize media", + optional: true, + }, }, }, returns: { @@ -469,7 +473,10 @@ fn write_media_label( }, )] /// Read media label -pub async fn read_label(drive: String) -> Result { +pub async fn read_label( + drive: String, + inventorize: Option, +) -> Result { let (config, _digest) = config::drive::config()?; @@ -480,7 +487,7 @@ pub async fn read_label(drive: String) -> Result { let media_id = match media_id { Some(media_id) => { - let mut flat = MediaIdFlat { + let mut flat = MediaIdFlat { uuid: media_id.label.uuid.to_string(), label_text: media_id.label.label_text.clone(), ctime: media_id.label.ctime, @@ -489,12 +496,19 @@ pub async fn read_label(drive: String) -> Result { pool: None, seq_nr: None, }; - if let Some(set) = media_id.media_set_label { + if let Some(ref set) = media_id.media_set_label { flat.pool = Some(set.pool.clone()); flat.seq_nr = Some(set.seq_nr); flat.media_set_uuid = Some(set.uuid.to_string()); flat.media_set_ctime = Some(set.ctime); } + + if let Some(true) = inventorize { + let state_path = Path::new(TAPE_STATUS_DIR); + let mut inventory = Inventory::load(state_path)?; + inventory.store(media_id, false)?; + } + flat } None => { diff --git a/src/bin/proxmox-tape.rs b/src/bin/proxmox-tape.rs index ee35be23..c869cdf5 100644 --- a/src/bin/proxmox-tape.rs +++ b/src/bin/proxmox-tape.rs @@ -386,7 +386,12 @@ async fn label_media( schema: DRIVE_NAME_SCHEMA, optional: true, }, - "output-format": { + inventorize: { + description: "Inventorize media", + type: bool, + optional: true, + }, + "output-format": { schema: OUTPUT_FORMAT, optional: true, },