]>
Commit | Line | Data |
---|---|---|
380bd7df DM |
1 | use anyhow::Error; |
2 | use serde_json::Value; | |
3 | ||
4 | use proxmox::api::{api, cli::*, RpcEnvironment, ApiHandler}; | |
5 | ||
6 | use proxmox_backup::config; | |
7 | use proxmox_backup::api2::{self, types::* }; | |
8 | ||
9 | #[api( | |
10 | input: { | |
11 | properties: { | |
12 | "output-format": { | |
13 | schema: OUTPUT_FORMAT, | |
14 | optional: true, | |
15 | }, | |
16 | } | |
17 | } | |
18 | )] | |
19 | /// Datastore list. | |
20 | fn list_datastores(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { | |
21 | ||
22 | let output_format = get_output_format(¶m); | |
23 | ||
24 | let info = &api2::config::datastore::API_METHOD_LIST_DATASTORES; | |
25 | let mut data = match info.handler { | |
26 | ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, | |
27 | _ => unreachable!(), | |
28 | }; | |
29 | ||
30 | let options = default_table_format_options() | |
31 | .column(ColumnConfig::new("name")) | |
32 | .column(ColumnConfig::new("path")) | |
33 | .column(ColumnConfig::new("comment")); | |
34 | ||
b2362a12 | 35 | format_and_print_result_full(&mut data, &info.returns, &output_format, &options); |
380bd7df DM |
36 | |
37 | Ok(Value::Null) | |
38 | } | |
39 | ||
40 | #[api( | |
41 | input: { | |
42 | properties: { | |
43 | name: { | |
44 | schema: DATASTORE_SCHEMA, | |
45 | }, | |
46 | "output-format": { | |
47 | schema: OUTPUT_FORMAT, | |
48 | optional: true, | |
49 | }, | |
50 | } | |
51 | } | |
52 | )] | |
53 | /// Show datastore configuration | |
54 | fn show_datastore(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { | |
55 | ||
56 | let output_format = get_output_format(¶m); | |
57 | ||
58 | let info = &api2::config::datastore::API_METHOD_READ_DATASTORE; | |
59 | let mut data = match info.handler { | |
60 | ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, | |
61 | _ => unreachable!(), | |
62 | }; | |
63 | ||
64 | let options = default_table_format_options(); | |
b2362a12 | 65 | format_and_print_result_full(&mut data, &info.returns, &output_format, &options); |
380bd7df DM |
66 | |
67 | Ok(Value::Null) | |
68 | } | |
69 | ||
70 | pub fn datastore_commands() -> CommandLineInterface { | |
71 | ||
72 | let cmd_def = CliCommandMap::new() | |
73 | .insert("list", CliCommand::new(&API_METHOD_LIST_DATASTORES)) | |
74 | .insert("show", | |
75 | CliCommand::new(&API_METHOD_SHOW_DATASTORE) | |
76 | .arg_param(&["name"]) | |
77 | .completion_cb("name", config::datastore::complete_datastore_name) | |
78 | ) | |
79 | .insert("create", | |
80 | CliCommand::new(&api2::config::datastore::API_METHOD_CREATE_DATASTORE) | |
81 | .arg_param(&["name", "path"]) | |
82 | ) | |
83 | .insert("update", | |
84 | CliCommand::new(&api2::config::datastore::API_METHOD_UPDATE_DATASTORE) | |
85 | .arg_param(&["name"]) | |
86 | .completion_cb("name", config::datastore::complete_datastore_name) | |
87 | .completion_cb("gc-schedule", config::datastore::complete_calendar_event) | |
88 | .completion_cb("prune-schedule", config::datastore::complete_calendar_event) | |
355c055e | 89 | ) |
380bd7df DM |
90 | .insert("remove", |
91 | CliCommand::new(&api2::config::datastore::API_METHOD_DELETE_DATASTORE) | |
92 | .arg_param(&["name"]) | |
93 | .completion_cb("name", config::datastore::complete_datastore_name) | |
94 | ); | |
95 | ||
96 | cmd_def.into() | |
97 | } |