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 7E700BA0CF for ; Wed, 13 Dec 2023 16:38:31 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 66BB6C7F7 for ; Wed, 13 Dec 2023 16:38:31 +0100 (CET) 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 for ; Wed, 13 Dec 2023 16:38:30 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id C65E0472E0 for ; Wed, 13 Dec 2023 16:38:29 +0100 (CET) From: Christian Ebner To: pbs-devel@lists.proxmox.com Date: Wed, 13 Dec 2023 16:38:18 +0100 Message-Id: <20231213153819.391392-8-c.ebner@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231213153819.391392-1-c.ebner@proxmox.com> References: <20231213153819.391392-1-c.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.055 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 T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pbs-devel] [RFC proxmox-backup 7/8] manager: add sanity check jobs management cli commands 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, 13 Dec 2023 15:38:31 -0000 Expose the sanity check management commands to the CLI, allowing to create, show/list, update, remove and run jobs. Signed-off-by: Christian Ebner --- 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 { let output_format = get_output_format(¶m); 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 { + let output_format = get_output_format(¶m); + + 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 { + let output_format = get_output_format(¶m); + + 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 { + 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