2020-12-09 11:58:43 +00:00
|
|
|
use anyhow::Error;
|
|
|
|
use serde_json::Value;
|
|
|
|
|
|
|
|
use proxmox::{
|
|
|
|
api::{
|
|
|
|
api,
|
|
|
|
cli::*,
|
|
|
|
RpcEnvironment,
|
|
|
|
ApiHandler,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
use proxmox_backup::{
|
|
|
|
api2::{
|
|
|
|
self,
|
|
|
|
types::{
|
2020-12-13 08:18:16 +00:00
|
|
|
DRIVE_NAME_SCHEMA,
|
2020-12-09 11:58:43 +00:00
|
|
|
},
|
|
|
|
},
|
2021-01-21 16:25:32 +00:00
|
|
|
tape::complete_drive_path,
|
2020-12-09 11:58:43 +00:00
|
|
|
config::drive::{
|
|
|
|
complete_drive_name,
|
|
|
|
complete_changer_name,
|
|
|
|
complete_linux_drive_name,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
pub fn drive_commands() -> CommandLineInterface {
|
|
|
|
|
|
|
|
let cmd_def = CliCommandMap::new()
|
2020-12-10 06:58:45 +00:00
|
|
|
.insert("scan", CliCommand::new(&API_METHOD_SCAN_FOR_DRIVES))
|
2020-12-09 11:58:43 +00:00
|
|
|
.insert("list", CliCommand::new(&API_METHOD_LIST_DRIVES))
|
|
|
|
.insert("config",
|
|
|
|
CliCommand::new(&API_METHOD_GET_CONFIG)
|
|
|
|
.arg_param(&["name"])
|
|
|
|
.completion_cb("name", complete_linux_drive_name)
|
|
|
|
)
|
|
|
|
.insert(
|
|
|
|
"remove",
|
2020-12-10 07:35:11 +00:00
|
|
|
CliCommand::new(&api2::config::drive::API_METHOD_DELETE_DRIVE)
|
2020-12-09 11:58:43 +00:00
|
|
|
.arg_param(&["name"])
|
|
|
|
.completion_cb("name", complete_linux_drive_name)
|
|
|
|
)
|
|
|
|
.insert(
|
|
|
|
"create",
|
2020-12-10 07:35:11 +00:00
|
|
|
CliCommand::new(&api2::config::drive::API_METHOD_CREATE_DRIVE)
|
2020-12-09 11:58:43 +00:00
|
|
|
.arg_param(&["name"])
|
|
|
|
.completion_cb("name", complete_drive_name)
|
|
|
|
.completion_cb("path", complete_drive_path)
|
|
|
|
.completion_cb("changer", complete_changer_name)
|
|
|
|
)
|
|
|
|
.insert(
|
|
|
|
"update",
|
2020-12-10 07:35:11 +00:00
|
|
|
CliCommand::new(&api2::config::drive::API_METHOD_UPDATE_DRIVE)
|
2020-12-09 11:58:43 +00:00
|
|
|
.arg_param(&["name"])
|
|
|
|
.completion_cb("name", complete_linux_drive_name)
|
|
|
|
.completion_cb("path", complete_drive_path)
|
|
|
|
.completion_cb("changer", complete_changer_name)
|
|
|
|
)
|
|
|
|
;
|
|
|
|
|
|
|
|
cmd_def.into()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
"output-format": {
|
|
|
|
schema: OUTPUT_FORMAT,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// List drives
|
|
|
|
fn list_drives(
|
|
|
|
param: Value,
|
|
|
|
rpcenv: &mut dyn RpcEnvironment,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
|
|
|
|
let output_format = get_output_format(¶m);
|
|
|
|
let info = &api2::config::drive::API_METHOD_LIST_DRIVES;
|
|
|
|
let mut data = match info.handler {
|
|
|
|
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let options = default_table_format_options()
|
|
|
|
.column(ColumnConfig::new("name"))
|
|
|
|
.column(ColumnConfig::new("path"))
|
|
|
|
.column(ColumnConfig::new("changer"))
|
|
|
|
.column(ColumnConfig::new("vendor"))
|
|
|
|
.column(ColumnConfig::new("model"))
|
|
|
|
.column(ColumnConfig::new("serial"))
|
|
|
|
;
|
|
|
|
|
2020-12-18 11:26:07 +00:00
|
|
|
format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
|
2020-12-09 11:58:43 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
"output-format": {
|
|
|
|
schema: OUTPUT_FORMAT,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)]
|
|
|
|
/// Scan for drives
|
|
|
|
fn scan_for_drives(
|
|
|
|
param: Value,
|
|
|
|
rpcenv: &mut dyn RpcEnvironment,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
|
|
|
|
let output_format = get_output_format(¶m);
|
|
|
|
let info = &api2::tape::drive::API_METHOD_SCAN_DRIVES;
|
|
|
|
let mut data = match info.handler {
|
|
|
|
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let options = default_table_format_options()
|
|
|
|
.column(ColumnConfig::new("path"))
|
|
|
|
.column(ColumnConfig::new("vendor"))
|
|
|
|
.column(ColumnConfig::new("model"))
|
|
|
|
.column(ColumnConfig::new("serial"))
|
|
|
|
;
|
|
|
|
|
2020-12-18 11:26:07 +00:00
|
|
|
format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
|
2020-12-09 11:58:43 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
"output-format": {
|
|
|
|
schema: OUTPUT_FORMAT,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
name: {
|
2020-12-13 08:18:16 +00:00
|
|
|
schema: DRIVE_NAME_SCHEMA,
|
2020-12-09 11:58:43 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Get pool configuration
|
|
|
|
fn get_config(
|
|
|
|
param: Value,
|
|
|
|
rpcenv: &mut dyn RpcEnvironment,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
|
|
|
|
let output_format = get_output_format(¶m);
|
|
|
|
let info = &api2::config::drive::API_METHOD_GET_CONFIG;
|
|
|
|
let mut data = match info.handler {
|
|
|
|
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let options = default_table_format_options()
|
|
|
|
.column(ColumnConfig::new("name"))
|
|
|
|
.column(ColumnConfig::new("path"))
|
|
|
|
.column(ColumnConfig::new("changer"))
|
2020-12-10 08:09:06 +00:00
|
|
|
.column(ColumnConfig::new("changer-drive-id"))
|
2020-12-09 11:58:43 +00:00
|
|
|
;
|
|
|
|
|
2020-12-18 11:26:07 +00:00
|
|
|
format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
|
2020-12-09 11:58:43 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|