From: Markus Frank <m.frank@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 3/6] feature #3690: api: add function wipe_disk
Date: Fri, 10 Nov 2023 14:50:07 +0100 [thread overview]
Message-ID: <20231110135010.106015-3-m.frank@proxmox.com> (raw)
In-Reply-To: <20231110135010.106015-1-m.frank@proxmox.com>
Signed-off-by: Markus Frank <m.frank@proxmox.com>
---
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<Value, Error> {
+ 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
next prev parent reply other threads:[~2023-11-10 13:51 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-10 13:50 [pbs-devel] [PATCH proxmox-backup 1/6] feature #3690: add regex, format & schema for partition names to pbs-api-types Markus Frank
2023-11-10 13:50 ` [pbs-devel] [PATCH proxmox-backup 2/6] feature #3690: add wipe_blockdev & change_parttype rust equivalent Markus Frank
2023-11-27 16:29 ` Lukas Wagner
2023-11-10 13:50 ` Markus Frank [this message]
2023-11-10 13:50 ` [pbs-devel] [PATCH proxmox-backup 4/6] feature #3690: cli: add function wipe_disk Markus Frank
2023-11-10 13:50 ` [pbs-devel] [PATCH proxmox-backup 5/6] feature #3690: ui: enable wipe disk in StorageAndDisks Markus Frank
2023-11-27 16:29 ` Lukas Wagner
2023-11-10 13:50 ` [pbs-devel] [PATCH proxmox-backup 6/6] prohibit disk wipe of EFI partition Markus Frank
2023-11-27 16:29 ` Lukas Wagner
2023-11-27 16:29 ` [pbs-devel] [PATCH proxmox-backup 1/6] feature #3690: add regex, format & schema for partition names to pbs-api-types Lukas Wagner
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=20231110135010.106015-3-m.frank@proxmox.com \
--to=m.frank@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal