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 35E86A10F6 for ; Fri, 10 Nov 2023 14:51:02 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 169D61771 for ; Fri, 10 Nov 2023 14:50:32 +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 ; Fri, 10 Nov 2023 14:50:31 +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 0914B47B0D for ; Fri, 10 Nov 2023 14:50:31 +0100 (CET) From: Markus Frank To: pbs-devel@lists.proxmox.com Date: Fri, 10 Nov 2023 14:50:07 +0100 Message-Id: <20231110135010.106015-3-m.frank@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231110135010.106015-1-m.frank@proxmox.com> References: <20231110135010.106015-1-m.frank@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.038 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. [mod.rs] Subject: [pbs-devel] [PATCH proxmox-backup 3/6] feature #3690: api: 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: Fri, 10 Nov 2023 13:51:02 -0000 Signed-off-by: Markus Frank --- src/api2/node/disks/mod.rs | 53 +++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/src/api2/node/disks/mod.rs b/src/api2/node/disks/mod.rs index 5ee959cd..55da0b54 100644 --- a/src/api2/node/disks/mod.rs +++ b/src/api2/node/disks/mod.rs @@ -9,12 +9,13 @@ use proxmox_sortable_macro::sortable; use proxmox_sys::task_log; use pbs_api_types::{ - BLOCKDEVICE_NAME_SCHEMA, NODE_SCHEMA, PRIV_SYS_AUDIT, PRIV_SYS_MODIFY, UPID_SCHEMA, + BLOCKDEVICE_NAME_SCHEMA, BLOCKDEVICE_PARTITION_NAME_SCHEMA, NODE_SCHEMA, PRIV_SYS_AUDIT, + PRIV_SYS_MODIFY, UPID_SCHEMA, }; use crate::tools::disks::{ - get_smart_data, inititialize_gpt_disk, DiskManage, DiskUsageInfo, DiskUsageQuery, - DiskUsageType, SmartData, + get_smart_data, inititialize_gpt_disk, wipe_blockdev, DiskManage, DiskUsageInfo, + DiskUsageQuery, DiskUsageType, SmartData, }; use proxmox_rest_server::WorkerTask; @@ -178,6 +179,51 @@ pub fn initialize_disk( Ok(json!(upid_str)) } +#[api( + protected: true, + input: { + properties: { + node: { + schema: NODE_SCHEMA, + }, + disk: { + schema: BLOCKDEVICE_PARTITION_NAME_SCHEMA, + }, + }, + }, + returns: { + schema: UPID_SCHEMA, + }, + access: { + permission: &Permission::Privilege(&["system", "disks"], PRIV_SYS_MODIFY, false), + }, +)] +/// wipe disk +pub fn wipe_disk(disk: String, rpcenv: &mut dyn RpcEnvironment) -> Result { + let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI; + + let auth_id = rpcenv.get_auth_id().unwrap(); + + let upid_str = WorkerTask::new_thread( + "wipedisk", + Some(disk.clone()), + auth_id, + to_stdout, + move |worker| { + task_log!(worker, "wipe disk {}", disk); + + let disk_manager = DiskManage::new(); + let disk_info = disk_manager.partition_by_name(&disk)?; + + wipe_blockdev(&disk_info)?; + + Ok(()) + }, + )?; + + Ok(json!(upid_str)) +} + #[sortable] const SUBDIRS: SubdirMap = &sorted!([ // ("lvm", &lvm::ROUTER), @@ -186,6 +232,7 @@ const SUBDIRS: SubdirMap = &sorted!([ ("initgpt", &Router::new().post(&API_METHOD_INITIALIZE_DISK)), ("list", &Router::new().get(&API_METHOD_LIST_DISKS)), ("smart", &Router::new().get(&API_METHOD_SMART_STATUS)), + ("wipedisk", &Router::new().put(&API_METHOD_WIPE_DISK)), ]); pub const ROUTER: Router = Router::new() -- 2.39.2