From: Gabriel Goller <g.goller@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 1/2] config: add default datastore creation function
Date: Fri, 3 May 2024 16:29:28 +0200 [thread overview]
Message-ID: <20240503142933.171798-1-g.goller@proxmox.com> (raw)
Add a function to create a default datastore. This datastore will have a
default prune-job with a daily schedule and a gc-job with a daily
schedule as well.
Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
src/api2/config/datastore.rs | 92 ++++++++++++++++++++----------------
1 file changed, 50 insertions(+), 42 deletions(-)
diff --git a/src/api2/config/datastore.rs b/src/api2/config/datastore.rs
index 6b742acb..6cb3b21a 100644
--- a/src/api2/config/datastore.rs
+++ b/src/api2/config/datastore.rs
@@ -1,4 +1,5 @@
use std::path::PathBuf;
+use std::sync::Arc;
use ::serde::{Deserialize, Serialize};
use anyhow::Error;
@@ -66,6 +67,54 @@ pub fn list_datastores(
Ok(list.into_iter().filter(filter_by_privs).collect())
}
+/// Creates a default datastore with the provided config.
+/// Also adds a gc schedule (daily) and the default prune-job (daily).
+pub(crate) fn create_default_datastore(
+ config: DataStoreConfig,
+ worker: Arc<WorkerTask>,
+) -> Result<(), Error> {
+ let lock = pbs_config::datastore::lock_config()?;
+
+ let (section_config, _digest) = pbs_config::datastore::config()?;
+
+ if section_config.sections.get(&config.name).is_some() {
+ param_bail!("name", "datastore '{}' already exists.", config.name);
+ }
+
+ let prune_job_config = config.prune_schedule.as_ref().map(|schedule| {
+ let mut id = format!("default-{}-{}", config.name, Uuid::generate());
+ id.truncate(32);
+
+ PruneJobConfig {
+ id,
+ store: config.name.clone(),
+ comment: None,
+ disable: false,
+ schedule: schedule.clone(),
+ options: PruneJobOptions {
+ keep: config.keep.clone(),
+ max_depth: None,
+ ns: None,
+ },
+ }
+ });
+
+ // clearing prune settings in the datastore config, as they are now handled by prune jobs
+ let config = DataStoreConfig {
+ prune_schedule: None,
+ keep: KeepOptions::default(),
+ ..config
+ };
+
+ do_create_datastore(lock, section_config, config, Some(&worker))?;
+
+ if let Some(prune_job_config) = prune_job_config {
+ do_create_prune_job(prune_job_config, Some(&worker))
+ } else {
+ Ok(())
+ }
+}
+
pub(crate) fn do_create_datastore(
_lock: BackupLockGuard,
mut config: SectionConfigData,
@@ -114,56 +163,15 @@ pub fn create_datastore(
config: DataStoreConfig,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<String, Error> {
- let lock = pbs_config::datastore::lock_config()?;
-
- let (section_config, _digest) = pbs_config::datastore::config()?;
-
- if section_config.sections.get(&config.name).is_some() {
- param_bail!("name", "datastore '{}' already exists.", config.name);
- }
-
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI;
- let prune_job_config = config.prune_schedule.as_ref().map(|schedule| {
- let mut id = format!("default-{}-{}", config.name, Uuid::generate());
- id.truncate(32);
-
- PruneJobConfig {
- id,
- store: config.name.clone(),
- comment: None,
- disable: false,
- schedule: schedule.clone(),
- options: PruneJobOptions {
- keep: config.keep.clone(),
- max_depth: None,
- ns: None,
- },
- }
- });
-
- // clearing prune settings in the datastore config, as they are now handled by prune jobs
- let config = DataStoreConfig {
- prune_schedule: None,
- keep: KeepOptions::default(),
- ..config
- };
-
WorkerTask::new_thread(
"create-datastore",
Some(config.name.to_string()),
auth_id.to_string(),
to_stdout,
- move |worker| {
- do_create_datastore(lock, section_config, config, Some(&worker))?;
-
- if let Some(prune_job_config) = prune_job_config {
- do_create_prune_job(prune_job_config, Some(&worker))
- } else {
- Ok(())
- }
- },
+ move |worker| create_default_datastore(config, worker),
)
}
--
2.43.0
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
next reply other threads:[~2024-05-03 14:29 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-03 14:29 Gabriel Goller [this message]
2024-05-03 14:29 ` [pbs-devel] [PATCH proxmox-backup 2/2] disks: unify default datastore creation Gabriel Goller
2024-05-03 14:32 ` [pbs-devel] [PATCH proxmox-backup 1/2] config: add default datastore creation function Gabriel Goller
2024-05-03 14:49 ` Christian Ebner
2024-05-03 15:31 ` Christian Ebner
2024-05-13 8:52 ` Christian Ebner
2024-05-13 9:31 ` Gabriel Goller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240503142933.171798-1-g.goller@proxmox.com \
--to=g.goller@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox