[pbs-devel] [RFC proxmox-backup 7/8] manager: add sanity check jobs management cli commands

Christian Ebner c.ebner at proxmox.com
Wed Dec 13 16:38:18 CET 2023


Expose the sanity check management commands to the CLI, allowing to
create, show/list, update, remove and run jobs.

Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
 src/bin/proxmox-backup-manager.rs             |   3 +-
 src/bin/proxmox_backup_manager/mod.rs         |   2 +
 .../proxmox_backup_manager/sanity_check.rs    | 126 ++++++++++++++++++
 3 files changed, 130 insertions(+), 1 deletion(-)
 create mode 100644 src/bin/proxmox_backup_manager/sanity_check.rs

diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs
index 115207f3..e17b18c7 100644
--- a/src/bin/proxmox-backup-manager.rs
+++ b/src/bin/proxmox-backup-manager.rs
@@ -447,6 +447,7 @@ async fn run() -> Result<(), Error> {
         .insert("acme", acme_mgmt_cli())
         .insert("cert", cert_mgmt_cli())
         .insert("subscription", subscription_commands())
+        .insert("sanity-check-job", sanity_check_job_commands())
         .insert("sync-job", sync_job_commands())
         .insert("verify-job", verify_job_commands())
         .insert("prune-job", prune_job_commands())
@@ -510,7 +511,7 @@ fn main() -> Result<(), Error> {
     proxmox_async::runtime::main(run())
 }
 
-/// Run the job of a given type (one of "prune", "sync", "verify"),
+/// Run the job of a given type (one of "prune", "sync", "verify", "sanity-check"),
 /// specified by the 'id' parameter.
 async fn run_job(job_type: &str, param: Value) -> Result<Value, Error> {
     let output_format = get_output_format(&param);
diff --git a/src/bin/proxmox_backup_manager/mod.rs b/src/bin/proxmox_backup_manager/mod.rs
index 8a1c140c..4d728636 100644
--- a/src/bin/proxmox_backup_manager/mod.rs
+++ b/src/bin/proxmox_backup_manager/mod.rs
@@ -16,6 +16,8 @@ mod prune;
 pub use prune::*;
 mod remote;
 pub use remote::*;
+mod sanity_check;
+pub use sanity_check::*;
 mod sync;
 pub use sync::*;
 mod verify;
diff --git a/src/bin/proxmox_backup_manager/sanity_check.rs b/src/bin/proxmox_backup_manager/sanity_check.rs
new file mode 100644
index 00000000..ff875b65
--- /dev/null
+++ b/src/bin/proxmox_backup_manager/sanity_check.rs
@@ -0,0 +1,126 @@
+
+use anyhow::Error;
+use serde_json::Value;
+
+use proxmox_router::{cli::*, ApiHandler, RpcEnvironment};
+use proxmox_schema::api;
+
+use pbs_api_types::JOB_ID_SCHEMA;
+
+use proxmox_backup::api2;
+
+#[api(
+    input: {
+        properties: {
+            "output-format": {
+                schema: OUTPUT_FORMAT,
+                optional: true,
+            },
+        }
+    }
+)]
+/// List all sanity check jobs
+fn list_sanity_check_jobs(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
+    let output_format = get_output_format(&param);
+
+    let info = &api2::config::sanity_check::API_METHOD_LIST_SANITY_CHECK_JOBS;
+    let mut data = match info.handler {
+        ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
+        _ => unreachable!(),
+    };
+
+    let options = default_table_format_options()
+        .column(ColumnConfig::new("id"))
+        .column(ColumnConfig::new("schedule"))
+        .column(ColumnConfig::new("datastore-usage-full-threshold"));
+
+    format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
+
+    Ok(Value::Null)
+}
+
+#[api(
+    input: {
+        properties: {
+            id: {
+                schema: JOB_ID_SCHEMA,
+            },
+            "output-format": {
+                schema: OUTPUT_FORMAT,
+                optional: true,
+            },
+        }
+    }
+)]
+/// Show sanity check job configuration
+fn show_sanity_check_job(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
+    let output_format = get_output_format(&param);
+
+    let info = &api2::config::sanity_check::API_METHOD_READ_SANITY_CHECK_JOB;
+    let mut data = match info.handler {
+        ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
+        _ => unreachable!(),
+    };
+
+    let options = default_table_format_options();
+    format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
+
+    Ok(Value::Null)
+}
+
+#[api(
+    input: {
+        properties: {
+            id: {
+                schema: JOB_ID_SCHEMA,
+            },
+            "output-format": {
+                schema: OUTPUT_FORMAT,
+                optional: true,
+            },
+        }
+    }
+)]
+/// Run the specified sanity check job
+async fn run_sanity_check_job(param: Value) -> Result<Value, Error> {
+    crate::run_job("sanity-check", param).await
+}
+
+pub fn sanity_check_job_commands() -> CommandLineInterface {
+    let cmd_def = CliCommandMap::new()
+        .insert("list", CliCommand::new(&API_METHOD_LIST_SANITY_CHECK_JOBS))
+        .insert(
+            "show",
+            CliCommand::new(&API_METHOD_SHOW_SANITY_CHECK_JOB)
+                .arg_param(&["id"])
+                .completion_cb("id", pbs_config::sanity_check::complete_sanity_check_job_id),
+        )
+        .insert(
+            "create",
+            CliCommand::new(&api2::config::sanity_check::API_METHOD_CREATE_SANITY_CHECK_JOB)
+                .arg_param(&["id"])
+                .completion_cb("id", pbs_config::sanity_check::complete_sanity_check_job_id)
+                .completion_cb("schedule", pbs_config::datastore::complete_calendar_event),
+        )
+        .insert(
+            "update",
+            CliCommand::new(&api2::config::sanity_check::API_METHOD_UPDATE_SANITY_CHECK_JOB)
+                .arg_param(&["id"])
+                .completion_cb("id", pbs_config::sanity_check::complete_sanity_check_job_id)
+                .completion_cb("schedule", pbs_config::datastore::complete_calendar_event),
+        )
+        .insert(
+            "run",
+            CliCommand::new(&API_METHOD_RUN_SANITY_CHECK_JOB)
+                .arg_param(&["id"])
+                .completion_cb("id", pbs_config::sanity_check::complete_sanity_check_job_id),
+        )
+        .insert(
+            "remove",
+            CliCommand::new(&api2::config::sanity_check::API_METHOD_DELETE_SANITY_CHECK_JOB)
+                .arg_param(&["id"])
+                .completion_cb("id", pbs_config::sanity_check::complete_sanity_check_job_id),
+        );
+
+    cmd_def.into()
+}
-- 
2.39.2





More information about the pbs-devel mailing list