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 589F79EBFC for ; Tue, 28 Nov 2023 14:24:04 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3991617357 for ; Tue, 28 Nov 2023 14:23:34 +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 ; Tue, 28 Nov 2023 14:23:33 +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 506F940E6D for ; Tue, 28 Nov 2023 14:23:33 +0100 (CET) From: Markus Frank To: pbs-devel@lists.proxmox.com Date: Tue, 28 Nov 2023 14:23:21 +0100 Message-Id: <20231128132323.162721-5-m.frank@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231128132323.162721-1-m.frank@proxmox.com> References: <20231128132323.162721-1-m.frank@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.035 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 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [disk.rs, mod.rs] Subject: [pbs-devel] [PATCH proxmox-backup v3 4/6] fix #3690: cli: add function wipe_disk 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: Tue, 28 Nov 2023 13:24:04 -0000 A new cli subcommand which calls the api wipe_disk function to wipe a disk/partition with a specified dev name. Examples: proxmox-backup-manager disk wipe sda2 proxmox-backup-manager disk wipe sda proxmox-backup-manager disk wipe nvme0n1p1 The complete_partition_name from tools/disks/mod.rs is used for command completion. Signed-off-by: Markus Frank --- src/bin/proxmox_backup_manager/disk.rs | 38 ++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/bin/proxmox_backup_manager/disk.rs b/src/bin/proxmox_backup_manager/disk.rs index fae8829f..7a292098 100644 --- a/src/bin/proxmox_backup_manager/disk.rs +++ b/src/bin/proxmox_backup_manager/disk.rs @@ -5,10 +5,12 @@ use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; use proxmox_schema::api; use pbs_api_types::{ - ZfsCompressionType, ZfsRaidLevel, BLOCKDEVICE_NAME_SCHEMA, DATASTORE_SCHEMA, DISK_LIST_SCHEMA, - ZFS_ASHIFT_SCHEMA, + ZfsCompressionType, ZfsRaidLevel, BLOCKDEVICE_DISK_AND_PARTITION_NAME_SCHEMA, + BLOCKDEVICE_NAME_SCHEMA, DATASTORE_SCHEMA, DISK_LIST_SCHEMA, ZFS_ASHIFT_SCHEMA, +}; +use proxmox_backup::tools::disks::{ + complete_disk_name, complete_partition_name, FileSystemType, SmartAttribute, }; -use proxmox_backup::tools::disks::{complete_disk_name, FileSystemType, SmartAttribute}; use proxmox_backup::api2; @@ -137,6 +139,30 @@ async fn initialize_disk( Ok(Value::Null) } +#[api( + input: { + properties: { + disk: { + schema: BLOCKDEVICE_DISK_AND_PARTITION_NAME_SCHEMA, + }, + }, + }, +)] +/// wipe disk +async fn wipe_disk(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result { + param["node"] = "localhost".into(); + + let info = &api2::node::disks::API_METHOD_WIPE_DISK; + let result = match info.handler { + ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, + _ => unreachable!(), + }; + + crate::wait_for_local_worker(result.as_str().unwrap()).await?; + + Ok(Value::Null) +} + #[api( input: { properties: { @@ -375,6 +401,12 @@ pub fn disk_commands() -> CommandLineInterface { CliCommand::new(&API_METHOD_INITIALIZE_DISK) .arg_param(&["disk"]) .completion_cb("disk", complete_disk_name), + ) + .insert( + "wipe", + CliCommand::new(&API_METHOD_WIPE_DISK) + .arg_param(&["disk"]) + .completion_cb("disk", complete_partition_name), ); cmd_def.into() -- 2.39.2