From 065df12872953f07abdec78b20618daeb44e3d47 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Sun, 13 Dec 2020 09:31:02 +0100 Subject: [PATCH] tape: split api type definitions for changers into extra file --- src/api2/types/tape/changer.rs | 80 ++++++++++++++++++++++++++++++++++ src/api2/types/tape/drive.rs | 76 ++------------------------------ src/api2/types/tape/mod.rs | 3 ++ 3 files changed, 87 insertions(+), 72 deletions(-) create mode 100644 src/api2/types/tape/changer.rs diff --git a/src/api2/types/tape/changer.rs b/src/api2/types/tape/changer.rs new file mode 100644 index 00000000..349a1d25 --- /dev/null +++ b/src/api2/types/tape/changer.rs @@ -0,0 +1,80 @@ +//! Types for tape changer API + +use serde::{Deserialize, Serialize}; + +use proxmox::api::{ + api, + schema::{Schema, StringSchema}, +}; + +use crate::api2::types::PROXMOX_SAFE_ID_FORMAT; + +pub const CHANGER_NAME_SCHEMA: Schema = StringSchema::new("Tape Changer Identifier.") + .format(&PROXMOX_SAFE_ID_FORMAT) + .min_length(3) + .max_length(32) + .schema(); + +pub const SCSI_CHANGER_PATH_SCHEMA: Schema = StringSchema::new( + "Path to Linux generic SCSI device (i.e. '/dev/sg4')") + .schema(); + +pub const MEDIA_LABEL_SCHEMA: Schema = StringSchema::new("Media Label/Barcode.") + .format(&PROXMOX_SAFE_ID_FORMAT) + .min_length(3) + .max_length(32) + .schema(); + +#[api( + properties: { + name: { + schema: CHANGER_NAME_SCHEMA, + }, + path: { + schema: SCSI_CHANGER_PATH_SCHEMA, + }, + } +)] +#[derive(Serialize,Deserialize)] +/// SCSI tape changer +pub struct ScsiTapeChanger { + pub name: String, + pub path: String, +} + +#[api()] +#[derive(Serialize,Deserialize)] +#[serde(rename_all = "lowercase")] +/// Mtx Entry Kind +pub enum MtxEntryKind { + /// Drive + Drive, + /// Slot + Slot, +} + +#[api( + properties: { + "entry-kind": { + type: MtxEntryKind, + }, + "changer-id": { + schema: MEDIA_LABEL_SCHEMA, + optional: true, + }, + }, +)] +#[derive(Serialize,Deserialize)] +#[serde(rename_all = "kebab-case")] +/// Mtx Status Entry +pub struct MtxStatusEntry { + pub entry_kind: MtxEntryKind, + /// The ID of the slot or drive + pub entry_id: u64, + /// The media label (volume tag) if the slot/drive is full + #[serde(skip_serializing_if="Option::is_none")] + pub changer_id: Option, + /// The slot the drive was loaded from + #[serde(skip_serializing_if="Option::is_none")] + pub loaded_slot: Option, +} diff --git a/src/api2/types/tape/drive.rs b/src/api2/types/tape/drive.rs index be7dcf5c..b3a68ba1 100644 --- a/src/api2/types/tape/drive.rs +++ b/src/api2/types/tape/drive.rs @@ -7,7 +7,10 @@ use proxmox::api::{ schema::{Schema, IntegerSchema, StringSchema}, }; -use crate::api2::types::PROXMOX_SAFE_ID_FORMAT; +use crate::api2::types::{ + PROXMOX_SAFE_ID_FORMAT, + CHANGER_NAME_SCHEMA, +}; pub const DRIVE_NAME_SCHEMA: Schema = StringSchema::new("Drive Identifier.") .format(&PROXMOX_SAFE_ID_FORMAT) @@ -15,26 +18,10 @@ pub const DRIVE_NAME_SCHEMA: Schema = StringSchema::new("Drive Identifier.") .max_length(32) .schema(); -pub const CHANGER_NAME_SCHEMA: Schema = StringSchema::new("Tape Changer Identifier.") - .format(&PROXMOX_SAFE_ID_FORMAT) - .min_length(3) - .max_length(32) - .schema(); - pub const LINUX_DRIVE_PATH_SCHEMA: Schema = StringSchema::new( "The path to a LINUX non-rewinding SCSI tape device (i.e. '/dev/nst0')") .schema(); -pub const SCSI_CHANGER_PATH_SCHEMA: Schema = StringSchema::new( - "Path to Linux generic SCSI device (i.e. '/dev/sg4')") - .schema(); - -pub const MEDIA_LABEL_SCHEMA: Schema = StringSchema::new("Media Label/Barcode.") - .format(&PROXMOX_SAFE_ID_FORMAT) - .min_length(3) - .max_length(32) - .schema(); - pub const CHANGER_DRIVE_ID_SCHEMA: Schema = IntegerSchema::new( "Associated changer drive number (requires option changer)") .minimum(0) @@ -91,24 +78,6 @@ pub struct LinuxTapeDrive { pub changer_drive_id: Option, } -#[api( - properties: { - name: { - schema: CHANGER_NAME_SCHEMA, - }, - path: { - schema: SCSI_CHANGER_PATH_SCHEMA, - }, - } -)] -#[derive(Serialize,Deserialize)] -/// SCSI tape changer -pub struct ScsiTapeChanger { - pub name: String, - pub path: String, -} - - #[api()] #[derive(Serialize,Deserialize)] /// Drive list entry @@ -130,40 +99,3 @@ pub struct DriveListEntry { #[serde(skip_serializing_if="Option::is_none")] pub serial: Option, } - -#[api()] -#[derive(Serialize,Deserialize)] -#[serde(rename_all = "lowercase")] -/// Mtx Entry Kind -pub enum MtxEntryKind { - /// Drive - Drive, - /// Slot - Slot, -} - -#[api( - properties: { - "entry-kind": { - type: MtxEntryKind, - }, - "changer-id": { - schema: MEDIA_LABEL_SCHEMA, - optional: true, - }, - }, -)] -#[derive(Serialize,Deserialize)] -#[serde(rename_all = "kebab-case")] -/// Mtx Status Entry -pub struct MtxStatusEntry { - pub entry_kind: MtxEntryKind, - /// The ID of the slot or drive - pub entry_id: u64, - /// The media label (volume tag) if the slot/drive is full - #[serde(skip_serializing_if="Option::is_none")] - pub changer_id: Option, - /// The slot the drive was loaded from - #[serde(skip_serializing_if="Option::is_none")] - pub loaded_slot: Option, -} diff --git a/src/api2/types/tape/mod.rs b/src/api2/types/tape/mod.rs index 58abecc6..7128206b 100644 --- a/src/api2/types/tape/mod.rs +++ b/src/api2/types/tape/mod.rs @@ -3,6 +3,9 @@ mod device; pub use device::*; +mod changer; +pub use changer::*; + mod drive; pub use drive::*;