From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id E1EE4777CF for ; Wed, 28 Apr 2021 12:34:23 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D3D27A6F9 for ; Wed, 28 Apr 2021 12:34:23 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 4BBBFA6F0 for ; Wed, 28 Apr 2021 12:34:23 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 8DA8742959 for ; Wed, 28 Apr 2021 12:25:26 +0200 (CEST) From: Hannes Laimer To: pbs-devel@lists.proxmox.com Date: Wed, 28 Apr 2021 12:25:18 +0200 Message-Id: <20210428102518.1578345-1-h.laimer@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 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 Subject: [pbs-devel] [PATCH proxmox-backup] api2: add keep-job-configs flag to datastore remove endpoint 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: , X-List-Received-Date: Wed, 28 Apr 2021 10:34:23 -0000 Signed-off-by: Hannes Laimer --- Adds a flag that controls whether related sync and verify-jobs should be kept or deleted. If not set or set to false, job configs will be removed if set to true, job config files will be left untouched and may be used in a new datastore with the same name. src/api2/config/datastore.rs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/api2/config/datastore.rs b/src/api2/config/datastore.rs index 6ca98b53..f9794e7f 100644 --- a/src/api2/config/datastore.rs +++ b/src/api2/config/datastore.rs @@ -1,13 +1,15 @@ use std::path::PathBuf; use anyhow::{bail, Error}; -use serde_json::Value; +use serde_json::{Value, json}; use ::serde::{Deserialize, Serialize}; use proxmox::api::{api, Router, RpcEnvironment, Permission}; use proxmox::api::schema::parse_property_string; use proxmox::tools::fs::open_file_locked; +use crate::api2::config::sync::{list_sync_jobs, delete_sync_job}; +use crate::api2::config::verify::{list_verification_jobs, delete_verification_job}; use crate::api2::types::*; use crate::backup::*; use crate::config::cached_user_info::CachedUserInfo; @@ -392,6 +394,12 @@ pub fn update_datastore( name: { schema: DATASTORE_SCHEMA, }, + "keep-job-configs": { + description: "If enabled, the job configurations related to this datastore will be kept.", + type: bool, + optional: true, + default: false, + }, digest: { optional: true, schema: PROXMOX_CONFIG_DIGEST_SCHEMA, @@ -403,8 +411,12 @@ pub fn update_datastore( }, )] /// Remove a datastore configuration. -pub fn delete_datastore(name: String, digest: Option) -> Result<(), Error> { - +pub fn delete_datastore( + name: String, + keep_job_configs: Option, + digest: Option, + rpcenv: &mut dyn RpcEnvironment, +) -> Result<(), Error> { let _lock = open_file_locked(datastore::DATASTORE_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?; let (mut config, expected_digest) = datastore::config()?; @@ -419,6 +431,18 @@ pub fn delete_datastore(name: String, digest: Option) -> Result<(), Erro None => bail!("datastore '{}' does not exist.", name), } + match keep_job_configs { + Some(true) => {} + _ => { // not set or set to false + for job_config in list_verification_jobs(json!({ "store": name }), rpcenv)? { + delete_verification_job(job_config.id, None, rpcenv)? + } + for job_config in list_sync_jobs(json!({ "store": name }), rpcenv)? { + delete_sync_job(job_config.id, None, rpcenv)? + } + } + } + datastore::save_config(&config)?; // ignore errors -- 2.20.1