src/config/datastore.rs: add gc-schedule property

This commit is contained in:
Dietmar Maurer 2020-05-20 08:38:10 +02:00
parent a67b70c154
commit 42fdbe5112
3 changed files with 31 additions and 1 deletions

View File

@ -27,6 +27,10 @@ use crate::config::acl::{PRIV_DATASTORE_AUDIT, PRIV_DATASTORE_MODIFY};
path: { path: {
schema: datastore::DIR_NAME_SCHEMA, schema: datastore::DIR_NAME_SCHEMA,
}, },
"gc-schedule": {
optional: true,
schema: GC_SCHEDULE_SCHEMA,
},
comment: { comment: {
optional: true, optional: true,
schema: SINGLE_LINE_COMMENT_SCHEMA, schema: SINGLE_LINE_COMMENT_SCHEMA,
@ -61,6 +65,10 @@ pub fn list_datastores(
optional: true, optional: true,
schema: SINGLE_LINE_COMMENT_SCHEMA, schema: SINGLE_LINE_COMMENT_SCHEMA,
}, },
"gc-schedule": {
optional: true,
schema: GC_SCHEDULE_SCHEMA,
},
path: { path: {
schema: datastore::DIR_NAME_SCHEMA, schema: datastore::DIR_NAME_SCHEMA,
}, },
@ -122,11 +130,14 @@ pub fn read_datastore(name: String) -> Result<Value, Error> {
#[api()] #[api()]
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
#[serde(rename_all="kebab-case")]
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
/// Deletable property name /// Deletable property name
pub enum DeletableProperty { pub enum DeletableProperty {
/// Delete the comment property. /// Delete the comment property.
comment, comment,
/// Delete the garbage collection schedule.
gc_schedule,
} }
#[api( #[api(
@ -140,6 +151,10 @@ pub enum DeletableProperty {
optional: true, optional: true,
schema: SINGLE_LINE_COMMENT_SCHEMA, schema: SINGLE_LINE_COMMENT_SCHEMA,
}, },
"gc-schedule": {
optional: true,
schema: GC_SCHEDULE_SCHEMA,
},
delete: { delete: {
description: "List of properties to delete.", description: "List of properties to delete.",
type: Array, type: Array,
@ -162,6 +177,7 @@ pub enum DeletableProperty {
pub fn update_datastore( pub fn update_datastore(
name: String, name: String,
comment: Option<String>, comment: Option<String>,
gc_schedule: Option<String>,
delete: Option<Vec<DeletableProperty>>, delete: Option<Vec<DeletableProperty>>,
digest: Option<String>, digest: Option<String>,
) -> Result<(), Error> { ) -> Result<(), Error> {
@ -182,6 +198,7 @@ pub fn update_datastore(
for delete_prop in delete { for delete_prop in delete {
match delete_prop { match delete_prop {
DeletableProperty::comment => { data.comment = None; }, DeletableProperty::comment => { data.comment = None; },
DeletableProperty::gc_schedule => { data.gc_schedule = None; },
} }
} }
} }
@ -195,6 +212,8 @@ pub fn update_datastore(
} }
} }
if gc_schedule.is_some() { data.gc_schedule = gc_schedule; }
config.set_data(&name, "datastore", &data)?; config.set_data(&name, "datastore", &data)?;
datastore::save_config(&config)?; datastore::save_config(&config)?;

View File

@ -287,6 +287,11 @@ pub const DATASTORE_SCHEMA: Schema = StringSchema::new("Datastore name.")
.max_length(32) .max_length(32)
.schema(); .schema();
pub const GC_SCHEDULE_SCHEMA: Schema = StringSchema::new(
"Run garbage collection job at specified schedule.")
.format(&ApiStringFormat::VerifyFn(crate::tools::systemd::time::verify_calendar_event))
.schema();
pub const REMOTE_ID_SCHEMA: Schema = StringSchema::new("Remote ID.") pub const REMOTE_ID_SCHEMA: Schema = StringSchema::new("Remote ID.")
.format(&PROXMOX_SAFE_ID_FORMAT) .format(&PROXMOX_SAFE_ID_FORMAT)
.min_length(3) .min_length(3)

View File

@ -22,7 +22,6 @@ lazy_static! {
} }
// fixme: define better schemas // fixme: define better schemas
pub const DIR_NAME_SCHEMA: Schema = StringSchema::new("Directory name").schema(); pub const DIR_NAME_SCHEMA: Schema = StringSchema::new("Directory name").schema();
#[api( #[api(
@ -31,17 +30,24 @@ pub const DIR_NAME_SCHEMA: Schema = StringSchema::new("Directory name").schema()
optional: true, optional: true,
schema: SINGLE_LINE_COMMENT_SCHEMA, schema: SINGLE_LINE_COMMENT_SCHEMA,
}, },
"gc-schedule": {
schema: GC_SCHEDULE_SCHEMA,
optional: true,
},
path: { path: {
schema: DIR_NAME_SCHEMA, schema: DIR_NAME_SCHEMA,
}, },
} }
)] )]
#[serde(rename_all="kebab-case")]
#[derive(Serialize,Deserialize)] #[derive(Serialize,Deserialize)]
/// Datastore configuration properties. /// Datastore configuration properties.
pub struct DataStoreConfig { pub struct DataStoreConfig {
#[serde(skip_serializing_if="Option::is_none")] #[serde(skip_serializing_if="Option::is_none")]
pub comment: Option<String>, pub comment: Option<String>,
pub path: String, pub path: String,
#[serde(skip_serializing_if="Option::is_none")]
pub gc_schedule: Option<String>,
} }
fn init() -> SectionConfig { fn init() -> SectionConfig {