public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Christian Ebner <c.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [RFC proxmox-backup 7/8] manager: add sanity check jobs management cli commands
Date: Wed, 13 Dec 2023 16:38:18 +0100	[thread overview]
Message-ID: <20231213153819.391392-8-c.ebner@proxmox.com> (raw)
In-Reply-To: <20231213153819.391392-1-c.ebner@proxmox.com>

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@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





  parent reply	other threads:[~2023-12-13 15:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-13 15:38 [pbs-devel] [RFC proxmox-backup 0/8] implement sanity check jobs Christian Ebner
2023-12-13 15:38 ` [pbs-devel] [RFC proxmox-backup 1/8] api-types: jobs: add sanity checks job types Christian Ebner
2023-12-13 15:38 ` [pbs-devel] [RFC proxmox-backup 2/8] config: implement sanity check job configuration Christian Ebner
2023-12-13 15:38 ` [pbs-devel] [RFC proxmox-backup 3/8] api: config: sanity check jobs api endpoints Christian Ebner
2023-12-13 15:38 ` [pbs-devel] [RFC proxmox-backup 4/8] server: add sanity check job email notifications Christian Ebner
2023-12-13 15:38 ` [pbs-devel] [RFC proxmox-backup 5/8] server: implement sanity check job Christian Ebner
2023-12-13 15:38 ` [pbs-devel] [RFC proxmox-backup 6/8] api: admin: add sanity check job api endpoints Christian Ebner
2023-12-13 15:38 ` Christian Ebner [this message]
2023-12-13 15:38 ` [pbs-devel] [RFC proxmox-backup 8/8] proxy: add sanity check task to scheduler Christian Ebner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231213153819.391392-8-c.ebner@proxmox.com \
    --to=c.ebner@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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