public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH proxmox-backup 1/2] config: add default datastore creation function
@ 2024-05-03 14:29 Gabriel Goller
  2024-05-03 14:29 ` [pbs-devel] [PATCH proxmox-backup 2/2] disks: unify default datastore creation Gabriel Goller
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Gabriel Goller @ 2024-05-03 14:29 UTC (permalink / raw)
  To: pbs-devel

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-05-13  9:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-03 14:29 [pbs-devel] [PATCH proxmox-backup 1/2] config: add default datastore creation function Gabriel Goller
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal