[pbs-devel] [PATCH proxmox-backup v3 4/6] fix #3690: cli: add function wipe_disk
Markus Frank
m.frank at proxmox.com
Tue Nov 28 14:23:21 CET 2023
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 <m.frank at proxmox.com>
---
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<Value, Error> {
+ 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
More information about the pbs-devel
mailing list