[pbs-devel] [PATCH proxmox-backup] api2: add keep-job-configs flag to datastore remove endpoint

Hannes Laimer h.laimer at proxmox.com
Wed Apr 28 12:25:18 CEST 2021


Signed-off-by: Hannes Laimer <h.laimer at proxmox.com>
---
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<String>) -> Result<(), Error> {
-
+pub fn delete_datastore(
+    name: String,
+    keep_job_configs: Option<bool>,
+    digest: Option<String>,
+    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<String>) -> 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






More information about the pbs-devel mailing list