diff --git a/src/api2/config/datastore.rs b/src/api2/config/datastore.rs index 0bd86c2d..c39d0fa2 100644 --- a/src/api2/config/datastore.rs +++ b/src/api2/config/datastore.rs @@ -27,6 +27,10 @@ use crate::config::acl::{PRIV_DATASTORE_AUDIT, PRIV_DATASTORE_MODIFY}; path: { schema: datastore::DIR_NAME_SCHEMA, }, + "gc-schedule": { + optional: true, + schema: GC_SCHEDULE_SCHEMA, + }, comment: { optional: true, schema: SINGLE_LINE_COMMENT_SCHEMA, @@ -61,6 +65,10 @@ pub fn list_datastores( optional: true, schema: SINGLE_LINE_COMMENT_SCHEMA, }, + "gc-schedule": { + optional: true, + schema: GC_SCHEDULE_SCHEMA, + }, path: { schema: datastore::DIR_NAME_SCHEMA, }, @@ -122,11 +130,14 @@ pub fn read_datastore(name: String) -> Result { #[api()] #[derive(Serialize, Deserialize)] +#[serde(rename_all="kebab-case")] #[allow(non_camel_case_types)] /// Deletable property name pub enum DeletableProperty { /// Delete the comment property. comment, + /// Delete the garbage collection schedule. + gc_schedule, } #[api( @@ -140,6 +151,10 @@ pub enum DeletableProperty { optional: true, schema: SINGLE_LINE_COMMENT_SCHEMA, }, + "gc-schedule": { + optional: true, + schema: GC_SCHEDULE_SCHEMA, + }, delete: { description: "List of properties to delete.", type: Array, @@ -162,6 +177,7 @@ pub enum DeletableProperty { pub fn update_datastore( name: String, comment: Option, + gc_schedule: Option, delete: Option>, digest: Option, ) -> Result<(), Error> { @@ -182,6 +198,7 @@ pub fn update_datastore( for delete_prop in delete { match delete_prop { 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)?; datastore::save_config(&config)?; diff --git a/src/api2/types.rs b/src/api2/types.rs index d26195c1..d3ad88c7 100644 --- a/src/api2/types.rs +++ b/src/api2/types.rs @@ -287,6 +287,11 @@ pub const DATASTORE_SCHEMA: Schema = StringSchema::new("Datastore name.") .max_length(32) .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.") .format(&PROXMOX_SAFE_ID_FORMAT) .min_length(3) diff --git a/src/config/datastore.rs b/src/config/datastore.rs index 4ce4eaa2..65fe1838 100644 --- a/src/config/datastore.rs +++ b/src/config/datastore.rs @@ -22,7 +22,6 @@ lazy_static! { } // fixme: define better schemas - pub const DIR_NAME_SCHEMA: Schema = StringSchema::new("Directory name").schema(); #[api( @@ -31,17 +30,24 @@ pub const DIR_NAME_SCHEMA: Schema = StringSchema::new("Directory name").schema() optional: true, schema: SINGLE_LINE_COMMENT_SCHEMA, }, + "gc-schedule": { + schema: GC_SCHEDULE_SCHEMA, + optional: true, + }, path: { schema: DIR_NAME_SCHEMA, }, } )] +#[serde(rename_all="kebab-case")] #[derive(Serialize,Deserialize)] /// Datastore configuration properties. pub struct DataStoreConfig { #[serde(skip_serializing_if="Option::is_none")] pub comment: Option, pub path: String, + #[serde(skip_serializing_if="Option::is_none")] + pub gc_schedule: Option, } fn init() -> SectionConfig {