]> git.proxmox.com Git - proxmox-backup.git/blame - pbs-api-types/src/tape/changer.rs
changer config cleanup: use Updater
[proxmox-backup.git] / pbs-api-types / src / tape / changer.rs
CommitLineData
065df128
DM
1//! Types for tape changer API
2
3use serde::{Deserialize, Serialize};
4
5use proxmox::api::{
6 api,
38ae42b1
DM
7 schema::{
8 Schema,
9 ApiStringFormat,
10 ArraySchema,
11 IntegerSchema,
12 StringSchema,
5af3bcf0 13 Updater,
38ae42b1 14 },
065df128
DM
15};
16
1ce8e905 17use crate::{
b5b99a52
DM
18 PROXMOX_SAFE_ID_FORMAT,
19 OptionalDeviceIdentification,
20};
065df128
DM
21
22pub const CHANGER_NAME_SCHEMA: Schema = StringSchema::new("Tape Changer Identifier.")
23 .format(&PROXMOX_SAFE_ID_FORMAT)
24 .min_length(3)
25 .max_length(32)
26 .schema();
27
28pub const SCSI_CHANGER_PATH_SCHEMA: Schema = StringSchema::new(
12299b33 29 "Path to Linux generic SCSI device (e.g. '/dev/sg4')")
065df128
DM
30 .schema();
31
32pub const MEDIA_LABEL_SCHEMA: Schema = StringSchema::new("Media Label/Barcode.")
33 .format(&PROXMOX_SAFE_ID_FORMAT)
12299b33 34 .min_length(2)
065df128
DM
35 .max_length(32)
36 .schema();
37
38ae42b1
DM
38pub const SLOT_ARRAY_SCHEMA: Schema = ArraySchema::new(
39 "Slot list.", &IntegerSchema::new("Slot number")
40 .minimum(1)
41 .schema())
42 .schema();
43
6252df4c 44pub const EXPORT_SLOT_LIST_SCHEMA: Schema = StringSchema::new("\
38ae42b1
DM
45A list of slot numbers, comma separated. Those slots are reserved for
46Import/Export, i.e. any media in those slots are considered to be
47'offline'.
6252df4c 48")
38ae42b1
DM
49.format(&ApiStringFormat::PropertyString(&SLOT_ARRAY_SCHEMA))
50.schema();
51
065df128
DM
52#[api(
53 properties: {
54 name: {
55 schema: CHANGER_NAME_SCHEMA,
56 },
57 path: {
58 schema: SCSI_CHANGER_PATH_SCHEMA,
59 },
38ae42b1
DM
60 "export-slots": {
61 schema: EXPORT_SLOT_LIST_SCHEMA,
62 optional: true,
63 },
64 },
065df128 65)]
5af3bcf0 66#[derive(Serialize,Deserialize,Updater)]
38ae42b1 67#[serde(rename_all = "kebab-case")]
065df128
DM
68/// SCSI tape changer
69pub struct ScsiTapeChanger {
5af3bcf0 70 #[updater(skip)]
065df128
DM
71 pub name: String,
72 pub path: String,
38ae42b1
DM
73 #[serde(skip_serializing_if="Option::is_none")]
74 pub export_slots: Option<String>,
065df128
DM
75}
76
b5b99a52
DM
77#[api(
78 properties: {
79 config: {
80 type: ScsiTapeChanger,
81 },
82 info: {
83 type: OptionalDeviceIdentification,
84 },
85 },
86)]
87#[derive(Serialize,Deserialize)]
88#[serde(rename_all = "kebab-case")]
89/// Changer config with optional device identification attributes
90pub struct ChangerListEntry {
91 #[serde(flatten)]
92 pub config: ScsiTapeChanger,
93 #[serde(flatten)]
94 pub info: OptionalDeviceIdentification,
95}
96
065df128
DM
97#[api()]
98#[derive(Serialize,Deserialize)]
e0362b0d 99#[serde(rename_all = "kebab-case")]
065df128
DM
100/// Mtx Entry Kind
101pub enum MtxEntryKind {
102 /// Drive
103 Drive,
104 /// Slot
105 Slot,
e0362b0d
DM
106 /// Import/Export Slot
107 ImportExport,
065df128
DM
108}
109
110#[api(
111 properties: {
112 "entry-kind": {
113 type: MtxEntryKind,
114 },
8446fbca 115 "label-text": {
065df128
DM
116 schema: MEDIA_LABEL_SCHEMA,
117 optional: true,
118 },
119 },
120)]
121#[derive(Serialize,Deserialize)]
122#[serde(rename_all = "kebab-case")]
123/// Mtx Status Entry
124pub struct MtxStatusEntry {
125 pub entry_kind: MtxEntryKind,
126 /// The ID of the slot or drive
127 pub entry_id: u64,
128 /// The media label (volume tag) if the slot/drive is full
129 #[serde(skip_serializing_if="Option::is_none")]
8446fbca 130 pub label_text: Option<String>,
065df128
DM
131 /// The slot the drive was loaded from
132 #[serde(skip_serializing_if="Option::is_none")]
133 pub loaded_slot: Option<u64>,
8be48ddf
DC
134 /// The current state of the drive
135 #[serde(skip_serializing_if="Option::is_none")]
136 pub state: Option<String>,
065df128 137}