From b1564af25a2ee7c2eb5984c35e8ab61d97074ba7 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 22 Apr 2020 17:37:20 +0200 Subject: [PATCH] src/bin/proxmox-backup-manager.rs: format datastore list output --- src/api2/config/datastore.rs | 14 ++++++++++++- src/bin/proxmox-backup-manager.rs | 33 ++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/api2/config/datastore.rs b/src/api2/config/datastore.rs index e22086d3..e6a34b5f 100644 --- a/src/api2/config/datastore.rs +++ b/src/api2/config/datastore.rs @@ -18,7 +18,19 @@ use crate::config::acl::{PRIV_DATASTORE_AUDIT, PRIV_DATASTORE_ALLOCATE}; description: "List the configured datastores (with config digest).", type: Array, items: { - type: datastore::DataStoreConfig, + description: "Datastore configuration.", + properties: { + name: { + schema: DATASTORE_SCHEMA, + }, + path: { + schema: datastore::DIR_NAME_SCHEMA, + }, + comment: { + optional: true, + schema: SINGLE_LINE_COMMENT_SCHEMA, + }, + }, }, }, access: { diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs index ea342ddf..4bce0b0b 100644 --- a/src/bin/proxmox-backup-manager.rs +++ b/src/bin/proxmox-backup-manager.rs @@ -288,10 +288,41 @@ fn network_commands() -> CommandLineInterface { cmd_def.into() } +#[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) +} + fn datastore_commands() -> CommandLineInterface { let cmd_def = CliCommandMap::new() - .insert("list", CliCommand::new(&api2::config::datastore::API_METHOD_LIST_DATASTORES)) + .insert("list", CliCommand::new(&API_METHOD_LIST_DATASTORES)) .insert("create", CliCommand::new(&api2::config::datastore::API_METHOD_CREATE_DATASTORE) .arg_param(&["name", "path"])