src/api2/node/disks.rs: implement initgpt API

This commit is contained in:
Dietmar Maurer
2020-06-07 10:30:34 +02:00
parent 9069debcd8
commit 707974fdb3
4 changed files with 171 additions and 7 deletions

View File

@ -85,6 +85,40 @@ fn smart_attributes(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result
Ok(Value::Null)
}
#[api(
input: {
properties: {
disk: {
schema: BLOCKDEVICE_NAME_SCHEMA,
},
uuid: {
description: "UUID for the GPT table.",
type: String,
optional: true,
max_length: 36,
},
},
},
)]
/// Initialize empty Disk with GPT
async fn initialize_disk(
mut param: Value,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
param["node"] = "localhost".into();
let info = &api2::node::disks::API_METHOD_INITIALIZE_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)
}
pub fn disk_commands() -> CommandLineInterface {
let cmd_def = CliCommandMap::new()
@ -93,6 +127,11 @@ pub fn disk_commands() -> CommandLineInterface {
CliCommand::new(&API_METHOD_SMART_ATTRIBUTES)
.arg_param(&["disk"])
.completion_cb("disk", complete_disk_name)
)
.insert("initialize",
CliCommand::new(&API_METHOD_INITIALIZE_DISK)
.arg_param(&["disk"])
.completion_cb("disk", complete_disk_name)
);
cmd_def.into()