diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs index 8b907f12..34f524e8 100644 --- a/src/bin/proxmox-backup-manager.rs +++ b/src/bin/proxmox-backup-manager.rs @@ -4,7 +4,7 @@ use std::collections::HashMap; use anyhow::{bail, format_err, Error}; use serde_json::{json, Value}; -use proxmox::api::{api, cli::*, RpcEnvironment, ApiHandler}; +use proxmox::api::{api, cli::*, RpcEnvironment}; use proxmox_backup::configdir; use proxmox_backup::tools; @@ -54,97 +54,6 @@ fn connect() -> Result { Ok(client) } -#[api( - input: { - properties: { - "output-format": { - schema: OUTPUT_FORMAT, - optional: true, - }, - } - } -)] -/// Datastore list. -fn list_datastores(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result { - - let output_format = get_output_format(¶m); - - let info = &api2::config::datastore::API_METHOD_LIST_DATASTORES; - 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("comment")); - - format_and_print_result_full(&mut data, info.returns, &output_format, &options); - - Ok(Value::Null) -} - -#[api( - input: { - properties: { - name: { - schema: DATASTORE_SCHEMA, - }, - "output-format": { - schema: OUTPUT_FORMAT, - optional: true, - }, - } - } -)] -/// Show datastore configuration -fn show_datastore(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result { - - let output_format = get_output_format(¶m); - - let info = &api2::config::datastore::API_METHOD_READ_DATASTORE; - let mut data = match info.handler { - ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, - _ => unreachable!(), - }; - - let options = default_table_format_options(); - format_and_print_result_full(&mut data, info.returns, &output_format, &options); - - Ok(Value::Null) -} - -fn datastore_commands() -> CommandLineInterface { - - let cmd_def = CliCommandMap::new() - .insert("list", CliCommand::new(&API_METHOD_LIST_DATASTORES)) - .insert("show", - CliCommand::new(&API_METHOD_SHOW_DATASTORE) - .arg_param(&["name"]) - .completion_cb("name", config::datastore::complete_datastore_name) - ) - .insert("create", - CliCommand::new(&api2::config::datastore::API_METHOD_CREATE_DATASTORE) - .arg_param(&["name", "path"]) - ) - .insert("update", - CliCommand::new(&api2::config::datastore::API_METHOD_UPDATE_DATASTORE) - .arg_param(&["name"]) - .completion_cb("name", config::datastore::complete_datastore_name) - .completion_cb("gc-schedule", config::datastore::complete_calendar_event) - .completion_cb("prune-schedule", config::datastore::complete_calendar_event) - ) - .insert("remove", - CliCommand::new(&api2::config::datastore::API_METHOD_DELETE_DATASTORE) - .arg_param(&["name"]) - .completion_cb("name", config::datastore::complete_datastore_name) - ); - - cmd_def.into() -} - - #[api( input: { properties: { diff --git a/src/bin/proxmox_backup_manager/datastore.rs b/src/bin/proxmox_backup_manager/datastore.rs new file mode 100644 index 00000000..9087b44c --- /dev/null +++ b/src/bin/proxmox_backup_manager/datastore.rs @@ -0,0 +1,97 @@ +use anyhow::Error; +use serde_json::Value; + +use proxmox::api::{api, cli::*, RpcEnvironment, ApiHandler}; + +use proxmox_backup::config; +use proxmox_backup::api2::{self, types::* }; + +#[api( + input: { + properties: { + "output-format": { + schema: OUTPUT_FORMAT, + optional: true, + }, + } + } +)] +/// Datastore list. +fn list_datastores(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result { + + let output_format = get_output_format(¶m); + + let info = &api2::config::datastore::API_METHOD_LIST_DATASTORES; + 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("comment")); + + format_and_print_result_full(&mut data, info.returns, &output_format, &options); + + Ok(Value::Null) +} + +#[api( + input: { + properties: { + name: { + schema: DATASTORE_SCHEMA, + }, + "output-format": { + schema: OUTPUT_FORMAT, + optional: true, + }, + } + } +)] +/// Show datastore configuration +fn show_datastore(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result { + + let output_format = get_output_format(¶m); + + let info = &api2::config::datastore::API_METHOD_READ_DATASTORE; + let mut data = match info.handler { + ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, + _ => unreachable!(), + }; + + let options = default_table_format_options(); + format_and_print_result_full(&mut data, info.returns, &output_format, &options); + + Ok(Value::Null) +} + +pub fn datastore_commands() -> CommandLineInterface { + + let cmd_def = CliCommandMap::new() + .insert("list", CliCommand::new(&API_METHOD_LIST_DATASTORES)) + .insert("show", + CliCommand::new(&API_METHOD_SHOW_DATASTORE) + .arg_param(&["name"]) + .completion_cb("name", config::datastore::complete_datastore_name) + ) + .insert("create", + CliCommand::new(&api2::config::datastore::API_METHOD_CREATE_DATASTORE) + .arg_param(&["name", "path"]) + ) + .insert("update", + CliCommand::new(&api2::config::datastore::API_METHOD_UPDATE_DATASTORE) + .arg_param(&["name"]) + .completion_cb("name", config::datastore::complete_datastore_name) + .completion_cb("gc-schedule", config::datastore::complete_calendar_event) + .completion_cb("prune-schedule", config::datastore::complete_calendar_event) + ) + .insert("remove", + CliCommand::new(&api2::config::datastore::API_METHOD_DELETE_DATASTORE) + .arg_param(&["name"]) + .completion_cb("name", config::datastore::complete_datastore_name) + ); + + cmd_def.into() +} diff --git a/src/bin/proxmox_backup_manager/mod.rs b/src/bin/proxmox_backup_manager/mod.rs index 25972368..a3945b59 100644 --- a/src/bin/proxmox_backup_manager/mod.rs +++ b/src/bin/proxmox_backup_manager/mod.rs @@ -1,5 +1,7 @@ mod acl; pub use acl::*; +mod datastore; +pub use datastore::*; mod dns; pub use dns::*; mod network;