tape: use type Uuid instead of String
This commit is contained in:
parent
2b191385ea
commit
f490dda05a
|
@ -538,7 +538,7 @@ pub async fn read_label(
|
||||||
let media_id = match media_id {
|
let media_id = match media_id {
|
||||||
Some(media_id) => {
|
Some(media_id) => {
|
||||||
let mut flat = MediaIdFlat {
|
let mut flat = MediaIdFlat {
|
||||||
uuid: media_id.label.uuid.to_string(),
|
uuid: media_id.label.uuid.clone(),
|
||||||
label_text: media_id.label.label_text.clone(),
|
label_text: media_id.label.label_text.clone(),
|
||||||
ctime: media_id.label.ctime,
|
ctime: media_id.label.ctime,
|
||||||
media_set_ctime: None,
|
media_set_ctime: None,
|
||||||
|
@ -550,7 +550,7 @@ pub async fn read_label(
|
||||||
if let Some(ref set) = media_id.media_set_label {
|
if let Some(ref set) = media_id.media_set_label {
|
||||||
flat.pool = Some(set.pool.clone());
|
flat.pool = Some(set.pool.clone());
|
||||||
flat.seq_nr = Some(set.seq_nr);
|
flat.seq_nr = Some(set.seq_nr);
|
||||||
flat.media_set_uuid = Some(set.uuid.to_string());
|
flat.media_set_uuid = Some(set.uuid.clone());
|
||||||
flat.media_set_ctime = Some(set.ctime);
|
flat.media_set_ctime = Some(set.ctime);
|
||||||
flat.encryption_key_fingerprint = set
|
flat.encryption_key_fingerprint = set
|
||||||
.encryption_key_fingerprint
|
.encryption_key_fingerprint
|
||||||
|
@ -678,7 +678,7 @@ pub async fn inventory(
|
||||||
let label_text = label_text.to_string();
|
let label_text = label_text.to_string();
|
||||||
|
|
||||||
if let Some(media_id) = inventory.find_media_by_label_text(&label_text) {
|
if let Some(media_id) = inventory.find_media_by_label_text(&label_text) {
|
||||||
list.push(LabelUuidMap { label_text, uuid: Some(media_id.label.uuid.to_string()) });
|
list.push(LabelUuidMap { label_text, uuid: Some(media_id.label.uuid.clone()) });
|
||||||
} else {
|
} else {
|
||||||
list.push(LabelUuidMap { label_text, uuid: None });
|
list.push(LabelUuidMap { label_text, uuid: None });
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ use serde::{Serialize, Deserialize};
|
||||||
use proxmox::{
|
use proxmox::{
|
||||||
api::{api, Router, SubdirMap},
|
api::{api, Router, SubdirMap},
|
||||||
list_subdirs_api_method,
|
list_subdirs_api_method,
|
||||||
|
tools::Uuid,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -17,6 +18,8 @@ use crate::{
|
||||||
BACKUP_TYPE_SCHEMA,
|
BACKUP_TYPE_SCHEMA,
|
||||||
MEDIA_POOL_NAME_SCHEMA,
|
MEDIA_POOL_NAME_SCHEMA,
|
||||||
MEDIA_LABEL_SCHEMA,
|
MEDIA_LABEL_SCHEMA,
|
||||||
|
MEDIA_UUID_SCHEMA,
|
||||||
|
MEDIA_SET_UUID_SCHEMA,
|
||||||
MediaPoolConfig,
|
MediaPoolConfig,
|
||||||
MediaListEntry,
|
MediaListEntry,
|
||||||
MediaStatus,
|
MediaStatus,
|
||||||
|
@ -92,7 +95,7 @@ pub async fn list_media(pool: Option<String>) -> Result<Vec<MediaListEntry>, Err
|
||||||
let expired = pool.media_is_expired(&media, current_time);
|
let expired = pool.media_is_expired(&media, current_time);
|
||||||
|
|
||||||
let media_set_uuid = media.media_set_label()
|
let media_set_uuid = media.media_set_label()
|
||||||
.map(|set| set.uuid.to_string());
|
.map(|set| set.uuid.clone());
|
||||||
|
|
||||||
let seq_nr = media.media_set_label()
|
let seq_nr = media.media_set_label()
|
||||||
.map(|set| set.seq_nr);
|
.map(|set| set.seq_nr);
|
||||||
|
@ -111,7 +114,7 @@ pub async fn list_media(pool: Option<String>) -> Result<Vec<MediaListEntry>, Err
|
||||||
};
|
};
|
||||||
|
|
||||||
list.push(MediaListEntry {
|
list.push(MediaListEntry {
|
||||||
uuid: media.uuid().to_string(),
|
uuid: media.uuid().clone(),
|
||||||
label_text: media.label_text().to_string(),
|
label_text: media.label_text().to_string(),
|
||||||
ctime: media.ctime(),
|
ctime: media.ctime(),
|
||||||
pool: Some(pool_name.to_string()),
|
pool: Some(pool_name.to_string()),
|
||||||
|
@ -140,7 +143,7 @@ pub async fn list_media(pool: Option<String>) -> Result<Vec<MediaListEntry>, Err
|
||||||
}
|
}
|
||||||
|
|
||||||
list.push(MediaListEntry {
|
list.push(MediaListEntry {
|
||||||
uuid: media_id.label.uuid.to_string(),
|
uuid: media_id.label.uuid.clone(),
|
||||||
ctime: media_id.label.ctime,
|
ctime: media_id.label.ctime,
|
||||||
label_text: media_id.label.label_text.to_string(),
|
label_text: media_id.label.label_text.to_string(),
|
||||||
location,
|
location,
|
||||||
|
@ -212,13 +215,11 @@ pub fn destroy_media(label_text: String, force: Option<bool>,) -> Result<(), Err
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
"media": {
|
"media": {
|
||||||
description: "Filter by media UUID.",
|
schema: MEDIA_UUID_SCHEMA,
|
||||||
type: String,
|
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
"media-set": {
|
"media-set": {
|
||||||
description: "Filter by media set UUID.",
|
schema: MEDIA_SET_UUID_SCHEMA,
|
||||||
type: String,
|
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
"backup-type": {
|
"backup-type": {
|
||||||
|
@ -237,8 +238,8 @@ pub fn destroy_media(label_text: String, force: Option<bool>,) -> Result<(), Err
|
||||||
pub struct MediaContentListFilter {
|
pub struct MediaContentListFilter {
|
||||||
pub pool: Option<String>,
|
pub pool: Option<String>,
|
||||||
pub label_text: Option<String>,
|
pub label_text: Option<String>,
|
||||||
pub media: Option<String>,
|
pub media: Option<Uuid>,
|
||||||
pub media_set: Option<String>,
|
pub media_set: Option<Uuid>,
|
||||||
pub backup_type: Option<String>,
|
pub backup_type: Option<String>,
|
||||||
pub backup_id: Option<String>,
|
pub backup_id: Option<String>,
|
||||||
}
|
}
|
||||||
|
@ -270,9 +271,6 @@ pub fn list_content(
|
||||||
let status_path = Path::new(TAPE_STATUS_DIR);
|
let status_path = Path::new(TAPE_STATUS_DIR);
|
||||||
let inventory = Inventory::load(status_path)?;
|
let inventory = Inventory::load(status_path)?;
|
||||||
|
|
||||||
let media_uuid = filter.media.and_then(|s| s.parse().ok());
|
|
||||||
let media_set_uuid = filter.media_set.and_then(|s| s.parse().ok());
|
|
||||||
|
|
||||||
let mut list = Vec::new();
|
let mut list = Vec::new();
|
||||||
|
|
||||||
for media_id in inventory.list_used_media() {
|
for media_id in inventory.list_used_media() {
|
||||||
|
@ -286,11 +284,11 @@ pub fn list_content(
|
||||||
if &set.pool != pool { continue; }
|
if &set.pool != pool { continue; }
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ref media_uuid) = media_uuid {
|
if let Some(ref media_uuid) = filter.media {
|
||||||
if &media_id.label.uuid != media_uuid { continue; }
|
if &media_id.label.uuid != media_uuid { continue; }
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ref media_set_uuid) = media_set_uuid {
|
if let Some(ref media_set_uuid) = filter.media_set {
|
||||||
if &set.uuid != media_set_uuid { continue; }
|
if &set.uuid != media_set_uuid { continue; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,11 +311,11 @@ pub fn list_content(
|
||||||
}
|
}
|
||||||
|
|
||||||
list.push(MediaContentEntry {
|
list.push(MediaContentEntry {
|
||||||
uuid: media_id.label.uuid.to_string(),
|
uuid: media_id.label.uuid.clone(),
|
||||||
label_text: media_id.label.label_text.to_string(),
|
label_text: media_id.label.label_text.to_string(),
|
||||||
pool: set.pool.clone(),
|
pool: set.pool.clone(),
|
||||||
media_set_name: media_set_name.clone(),
|
media_set_name: media_set_name.clone(),
|
||||||
media_set_uuid: set.uuid.to_string(),
|
media_set_uuid: set.uuid.clone(),
|
||||||
seq_nr: set.seq_nr,
|
seq_nr: set.seq_nr,
|
||||||
snapshot: snapshot.to_owned(),
|
snapshot: snapshot.to_owned(),
|
||||||
backup_time: backup_dir.backup_time(),
|
backup_time: backup_dir.backup_time(),
|
||||||
|
|
|
@ -316,7 +316,7 @@ pub const DATASTORE_SCHEMA: Schema = StringSchema::new("Datastore name.")
|
||||||
.schema();
|
.schema();
|
||||||
|
|
||||||
pub const MEDIA_SET_UUID_SCHEMA: Schema =
|
pub const MEDIA_SET_UUID_SCHEMA: Schema =
|
||||||
StringSchema::new("MediaSet Uuid.")
|
StringSchema::new("MediaSet Uuid (We use the all-zero Uuid to reseve an empty media for a specific pool).")
|
||||||
.format(&UUID_FORMAT)
|
.format(&UUID_FORMAT)
|
||||||
.schema();
|
.schema();
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
use ::serde::{Deserialize, Serialize};
|
use ::serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use proxmox::api::api;
|
use proxmox::{
|
||||||
|
api::api,
|
||||||
|
tools::Uuid,
|
||||||
|
};
|
||||||
|
|
||||||
use super::{
|
use crate::api2::types::{
|
||||||
|
MEDIA_UUID_SCHEMA,
|
||||||
|
MEDIA_SET_UUID_SCHEMA,
|
||||||
MediaStatus,
|
MediaStatus,
|
||||||
MediaLocation,
|
MediaLocation,
|
||||||
};
|
};
|
||||||
|
@ -15,6 +20,13 @@ use super::{
|
||||||
status: {
|
status: {
|
||||||
type: MediaStatus,
|
type: MediaStatus,
|
||||||
},
|
},
|
||||||
|
uuid: {
|
||||||
|
schema: MEDIA_UUID_SCHEMA,
|
||||||
|
},
|
||||||
|
"media-set-uuid": {
|
||||||
|
schema: MEDIA_SET_UUID_SCHEMA,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
)]
|
)]
|
||||||
#[derive(Serialize,Deserialize)]
|
#[derive(Serialize,Deserialize)]
|
||||||
|
@ -23,8 +35,7 @@ use super::{
|
||||||
pub struct MediaListEntry {
|
pub struct MediaListEntry {
|
||||||
/// Media label text (or Barcode)
|
/// Media label text (or Barcode)
|
||||||
pub label_text: String,
|
pub label_text: String,
|
||||||
/// Media Uuid
|
pub uuid: Uuid,
|
||||||
pub uuid: String,
|
|
||||||
/// Creation time stamp
|
/// Creation time stamp
|
||||||
pub ctime: i64,
|
pub ctime: i64,
|
||||||
pub location: MediaLocation,
|
pub location: MediaLocation,
|
||||||
|
@ -36,9 +47,8 @@ pub struct MediaListEntry {
|
||||||
/// Media set name
|
/// Media set name
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
pub media_set_name: Option<String>,
|
pub media_set_name: Option<String>,
|
||||||
/// Media set uuid
|
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
pub media_set_uuid: Option<String>,
|
pub media_set_uuid: Option<Uuid>,
|
||||||
/// Media set seq_nr
|
/// Media set seq_nr
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
pub seq_nr: Option<u64>,
|
pub seq_nr: Option<u64>,
|
||||||
|
@ -50,13 +60,23 @@ pub struct MediaListEntry {
|
||||||
pub pool: Option<String>,
|
pub pool: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[api()]
|
#[api(
|
||||||
|
properties: {
|
||||||
|
uuid: {
|
||||||
|
schema: MEDIA_UUID_SCHEMA,
|
||||||
|
},
|
||||||
|
"media-set-uuid": {
|
||||||
|
schema: MEDIA_SET_UUID_SCHEMA,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)]
|
||||||
#[derive(Serialize,Deserialize)]
|
#[derive(Serialize,Deserialize)]
|
||||||
#[serde(rename_all = "kebab-case")]
|
#[serde(rename_all = "kebab-case")]
|
||||||
/// Media label info
|
/// Media label info
|
||||||
pub struct MediaIdFlat {
|
pub struct MediaIdFlat {
|
||||||
/// Unique ID
|
/// Unique ID
|
||||||
pub uuid: String,
|
pub uuid: Uuid,
|
||||||
/// Media label text (or Barcode)
|
/// Media label text (or Barcode)
|
||||||
pub label_text: String,
|
pub label_text: String,
|
||||||
/// Creation time stamp
|
/// Creation time stamp
|
||||||
|
@ -65,9 +85,8 @@ pub struct MediaIdFlat {
|
||||||
/// MediaSet Pool
|
/// MediaSet Pool
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
pub pool: Option<String>,
|
pub pool: Option<String>,
|
||||||
/// MediaSet Uuid. We use the all-zero Uuid to reseve an empty media for a specific pool
|
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
pub media_set_uuid: Option<String>,
|
pub media_set_uuid: Option<Uuid>,
|
||||||
/// MediaSet media sequence number
|
/// MediaSet media sequence number
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
pub seq_nr: Option<u64>,
|
pub seq_nr: Option<u64>,
|
||||||
|
@ -79,7 +98,14 @@ pub struct MediaIdFlat {
|
||||||
pub encryption_key_fingerprint: Option<String>,
|
pub encryption_key_fingerprint: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[api()]
|
#[api(
|
||||||
|
properties: {
|
||||||
|
uuid: {
|
||||||
|
schema: MEDIA_UUID_SCHEMA,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)]
|
||||||
#[derive(Serialize,Deserialize)]
|
#[derive(Serialize,Deserialize)]
|
||||||
#[serde(rename_all = "kebab-case")]
|
#[serde(rename_all = "kebab-case")]
|
||||||
/// Label with optional Uuid
|
/// Label with optional Uuid
|
||||||
|
@ -87,10 +113,19 @@ pub struct LabelUuidMap {
|
||||||
/// Changer label text (or Barcode)
|
/// Changer label text (or Barcode)
|
||||||
pub label_text: String,
|
pub label_text: String,
|
||||||
/// Associated Uuid (if any)
|
/// Associated Uuid (if any)
|
||||||
pub uuid: Option<String>,
|
pub uuid: Option<Uuid>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[api()]
|
#[api(
|
||||||
|
properties: {
|
||||||
|
uuid: {
|
||||||
|
schema: MEDIA_UUID_SCHEMA,
|
||||||
|
},
|
||||||
|
"media-set-uuid": {
|
||||||
|
schema: MEDIA_SET_UUID_SCHEMA,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)]
|
||||||
#[derive(Serialize,Deserialize)]
|
#[derive(Serialize,Deserialize)]
|
||||||
#[serde(rename_all = "kebab-case")]
|
#[serde(rename_all = "kebab-case")]
|
||||||
/// Media content list entry
|
/// Media content list entry
|
||||||
|
@ -98,11 +133,11 @@ pub struct MediaContentEntry {
|
||||||
/// Media label text (or Barcode)
|
/// Media label text (or Barcode)
|
||||||
pub label_text: String,
|
pub label_text: String,
|
||||||
/// Media Uuid
|
/// Media Uuid
|
||||||
pub uuid: String,
|
pub uuid: Uuid,
|
||||||
/// Media set name
|
/// Media set name
|
||||||
pub media_set_name: String,
|
pub media_set_name: String,
|
||||||
/// Media set uuid
|
/// Media set uuid
|
||||||
pub media_set_uuid: String,
|
pub media_set_uuid: Uuid,
|
||||||
/// Media set seq_nr
|
/// Media set seq_nr
|
||||||
pub seq_nr: u64,
|
pub seq_nr: u64,
|
||||||
/// Media Pool
|
/// Media Pool
|
||||||
|
|
Loading…
Reference in New Issue