tape: add comment to media pool config
This commit is contained in:
parent
5a4233f07b
commit
db04d10d14
|
@ -16,6 +16,7 @@ use crate::{
|
||||||
MEDIA_SET_ALLOCATION_POLICY_SCHEMA,
|
MEDIA_SET_ALLOCATION_POLICY_SCHEMA,
|
||||||
MEDIA_RETENTION_POLICY_SCHEMA,
|
MEDIA_RETENTION_POLICY_SCHEMA,
|
||||||
TAPE_ENCRYPTION_KEY_FINGERPRINT_SCHEMA,
|
TAPE_ENCRYPTION_KEY_FINGERPRINT_SCHEMA,
|
||||||
|
SINGLE_LINE_COMMENT_SCHEMA,
|
||||||
MediaPoolConfig,
|
MediaPoolConfig,
|
||||||
},
|
},
|
||||||
config,
|
config,
|
||||||
|
@ -25,56 +26,29 @@ use crate::{
|
||||||
protected: true,
|
protected: true,
|
||||||
input: {
|
input: {
|
||||||
properties: {
|
properties: {
|
||||||
name: {
|
config: {
|
||||||
schema: MEDIA_POOL_NAME_SCHEMA,
|
type: MediaPoolConfig,
|
||||||
},
|
flatten: true,
|
||||||
allocation: {
|
|
||||||
schema: MEDIA_SET_ALLOCATION_POLICY_SCHEMA,
|
|
||||||
optional: true,
|
|
||||||
},
|
|
||||||
retention: {
|
|
||||||
schema: MEDIA_RETENTION_POLICY_SCHEMA,
|
|
||||||
optional: true,
|
|
||||||
},
|
|
||||||
template: {
|
|
||||||
schema: MEDIA_SET_NAMING_TEMPLATE_SCHEMA,
|
|
||||||
optional: true,
|
|
||||||
},
|
|
||||||
encrypt: {
|
|
||||||
schema: TAPE_ENCRYPTION_KEY_FINGERPRINT_SCHEMA,
|
|
||||||
optional: true,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)]
|
)]
|
||||||
/// Create a new media pool
|
/// Create a new media pool
|
||||||
pub fn create_pool(
|
pub fn create_pool(
|
||||||
name: String,
|
config: MediaPoolConfig,
|
||||||
allocation: Option<String>,
|
|
||||||
retention: Option<String>,
|
|
||||||
template: Option<String>,
|
|
||||||
encrypt: Option<String>,
|
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
|
||||||
let _lock = config::media_pool::lock()?;
|
let _lock = config::media_pool::lock()?;
|
||||||
|
|
||||||
let (mut config, _digest) = config::media_pool::config()?;
|
let (mut section_config, _digest) = config::media_pool::config()?;
|
||||||
|
|
||||||
if config.sections.get(&name).is_some() {
|
if section_config.sections.get(&config.name).is_some() {
|
||||||
bail!("Media pool '{}' already exists", name);
|
bail!("Media pool '{}' already exists", config.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
let item = MediaPoolConfig {
|
section_config.set_data(&config.name, "pool", &config)?;
|
||||||
name: name.clone(),
|
|
||||||
allocation,
|
|
||||||
retention,
|
|
||||||
template,
|
|
||||||
encrypt,
|
|
||||||
};
|
|
||||||
|
|
||||||
config.set_data(&name, "pool", &item)?;
|
config::media_pool::save_config(§ion_config)?;
|
||||||
|
|
||||||
config::media_pool::save_config(&config)?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -137,6 +111,8 @@ pub enum DeletableProperty {
|
||||||
template,
|
template,
|
||||||
/// Delete encryption fingerprint
|
/// Delete encryption fingerprint
|
||||||
encrypt,
|
encrypt,
|
||||||
|
/// Delete comment
|
||||||
|
comment,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[api(
|
#[api(
|
||||||
|
@ -162,6 +138,10 @@ pub enum DeletableProperty {
|
||||||
schema: TAPE_ENCRYPTION_KEY_FINGERPRINT_SCHEMA,
|
schema: TAPE_ENCRYPTION_KEY_FINGERPRINT_SCHEMA,
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
|
comment: {
|
||||||
|
optional: true,
|
||||||
|
schema: SINGLE_LINE_COMMENT_SCHEMA,
|
||||||
|
},
|
||||||
delete: {
|
delete: {
|
||||||
description: "List of properties to delete.",
|
description: "List of properties to delete.",
|
||||||
type: Array,
|
type: Array,
|
||||||
|
@ -180,6 +160,7 @@ pub fn update_pool(
|
||||||
retention: Option<String>,
|
retention: Option<String>,
|
||||||
template: Option<String>,
|
template: Option<String>,
|
||||||
encrypt: Option<String>,
|
encrypt: Option<String>,
|
||||||
|
comment: Option<String>,
|
||||||
delete: Option<Vec<DeletableProperty>>,
|
delete: Option<Vec<DeletableProperty>>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
|
||||||
|
@ -196,6 +177,7 @@ pub fn update_pool(
|
||||||
DeletableProperty::retention => { data.retention = None; },
|
DeletableProperty::retention => { data.retention = None; },
|
||||||
DeletableProperty::template => { data.template = None; },
|
DeletableProperty::template => { data.template = None; },
|
||||||
DeletableProperty::encrypt => { data.encrypt = None; },
|
DeletableProperty::encrypt => { data.encrypt = None; },
|
||||||
|
DeletableProperty::comment => { data.comment = None; },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -205,6 +187,15 @@ pub fn update_pool(
|
||||||
if template.is_some() { data.template = template; }
|
if template.is_some() { data.template = template; }
|
||||||
if encrypt.is_some() { data.encrypt = encrypt; }
|
if encrypt.is_some() { data.encrypt = encrypt; }
|
||||||
|
|
||||||
|
if let Some(comment) = comment {
|
||||||
|
let comment = comment.trim();
|
||||||
|
if comment.is_empty() {
|
||||||
|
data.comment = None;
|
||||||
|
} else {
|
||||||
|
data.comment = Some(comment.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
config.set_data(&name, "pool", &data)?;
|
config.set_data(&name, "pool", &data)?;
|
||||||
|
|
||||||
config::media_pool::save_config(&config)?;
|
config::media_pool::save_config(&config)?;
|
||||||
|
|
|
@ -23,6 +23,7 @@ use crate::{
|
||||||
api2::types::{
|
api2::types::{
|
||||||
PROXMOX_SAFE_ID_FORMAT,
|
PROXMOX_SAFE_ID_FORMAT,
|
||||||
SINGLE_LINE_COMMENT_FORMAT,
|
SINGLE_LINE_COMMENT_FORMAT,
|
||||||
|
SINGLE_LINE_COMMENT_SCHEMA,
|
||||||
TAPE_ENCRYPTION_KEY_FINGERPRINT_SCHEMA,
|
TAPE_ENCRYPTION_KEY_FINGERPRINT_SCHEMA,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -131,6 +132,10 @@ impl std::str::FromStr for RetentionPolicy {
|
||||||
schema: TAPE_ENCRYPTION_KEY_FINGERPRINT_SCHEMA,
|
schema: TAPE_ENCRYPTION_KEY_FINGERPRINT_SCHEMA,
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
|
comment: {
|
||||||
|
optional: true,
|
||||||
|
schema: SINGLE_LINE_COMMENT_SCHEMA,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
)]
|
)]
|
||||||
#[derive(Serialize,Deserialize)]
|
#[derive(Serialize,Deserialize)]
|
||||||
|
@ -155,4 +160,6 @@ pub struct MediaPoolConfig {
|
||||||
/// If set, encrypt all data using the specified key.
|
/// If set, encrypt all data using the specified key.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
pub encrypt: Option<String>,
|
pub encrypt: Option<String>,
|
||||||
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
|
pub comment: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue