From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 9AE5B1FF38D for ; Fri, 3 May 2024 16:29:37 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A99A22F28; Fri, 3 May 2024 16:29:38 +0200 (CEST) From: Gabriel Goller To: pbs-devel@lists.proxmox.com Date: Fri, 3 May 2024 16:29:28 +0200 Message-ID: <20240503142933.171798-1-g.goller@proxmox.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.075 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [datastore.rs] Subject: [pbs-devel] [PATCH proxmox-backup 1/2] config: add default datastore creation function X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "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 --- 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, +) -> 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 { - 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