1 use anyhow
::{bail, Error}
;
12 use crate::api2
::types
::{
13 PROXMOX_SAFE_ID_FORMAT
,
17 pub const VAULT_NAME_SCHEMA
: Schema
= StringSchema
::new("Vault name.")
18 .format(&PROXMOX_SAFE_ID_FORMAT
)
23 #[derive(Debug, PartialEq, Clone)]
25 pub enum MediaLocation
{
26 /// Ready for use (inside tape library)
28 /// Local available, but need to be mounted (insert into tape
31 /// Media is inside a Vault
35 proxmox
::forward_deserialize_to_from_str
!(MediaLocation
);
36 proxmox
::forward_serialize_to_display
!(MediaLocation
);
38 impl proxmox
::api
::schema
::ApiType
for MediaLocation
{
39 const API_SCHEMA
: Schema
= StringSchema
::new(
40 "Media location (e.g. 'offline', 'online-<changer_name>', 'vault-<vault_name>')")
41 .format(&ApiStringFormat
::VerifyFn(|text
| {
42 let location
: MediaLocation
= text
.parse()?
;
44 MediaLocation
::Online(ref changer
) => {
45 parse_simple_value(changer
, &CHANGER_NAME_SCHEMA
)?
;
47 MediaLocation
::Vault(ref vault
) => {
48 parse_simple_value(vault
, &VAULT_NAME_SCHEMA
)?
;
50 MediaLocation
::Offline
=> { /* OK */}
58 impl std
::fmt
::Display
for MediaLocation
{
60 fn fmt(&self, f
: &mut std
::fmt
::Formatter
<'_
>) -> std
::fmt
::Result
{
62 MediaLocation
::Offline
=> {
65 MediaLocation
::Online(changer
) => {
66 write
!(f
, "online-{}", changer
)
68 MediaLocation
::Vault(vault
) => {
69 write
!(f
, "vault-{}", vault
)
75 impl std
::str::FromStr
for MediaLocation
{
78 fn from_str(s
: &str) -> Result
<Self, Self::Err
> {
80 return Ok(MediaLocation
::Offline
);
82 if let Some(changer
) = s
.strip_prefix("online-") {
83 return Ok(MediaLocation
::Online(changer
.to_string()));
85 if let Some(vault
) = s
.strip_prefix("vault-") {
86 return Ok(MediaLocation
::Vault(vault
.to_string()));
89 bail
!("MediaLocation parse error");