]> git.proxmox.com Git - proxmox-backup.git/blob - src/bin/proxmox_backup_manager/remote.rs
adaptions for proxmox 0.9 and proxmox-api-macro 0.3
[proxmox-backup.git] / src / bin / proxmox_backup_manager / remote.rs
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 /// List configured remotes.
20 fn list_remotes(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
21
22 let output_format = get_output_format(&param);
23
24 let info = &api2::config::remote::API_METHOD_LIST_REMOTES;
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("host"))
33 .column(ColumnConfig::new("userid"))
34 .column(ColumnConfig::new("fingerprint"))
35 .column(ColumnConfig::new("comment"));
36
37 format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
38
39 Ok(Value::Null)
40 }
41
42 #[api(
43 input: {
44 properties: {
45 name: {
46 schema: REMOTE_ID_SCHEMA,
47 },
48 "output-format": {
49 schema: OUTPUT_FORMAT,
50 optional: true,
51 },
52 }
53 }
54 )]
55 /// Show remote configuration
56 fn show_remote(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
57
58 let output_format = get_output_format(&param);
59
60 let info = &api2::config::remote::API_METHOD_READ_REMOTE;
61 let mut data = match info.handler {
62 ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
63 _ => unreachable!(),
64 };
65
66 let options = default_table_format_options();
67 format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
68
69 Ok(Value::Null)
70 }
71
72 pub fn remote_commands() -> CommandLineInterface {
73
74 let cmd_def = CliCommandMap::new()
75 .insert("list", CliCommand::new(&&API_METHOD_LIST_REMOTES))
76 .insert(
77 "show",
78 CliCommand::new(&API_METHOD_SHOW_REMOTE)
79 .arg_param(&["name"])
80 .completion_cb("name", config::remote::complete_remote_name)
81 )
82 .insert(
83 "create",
84 // fixme: howto handle password parameter?
85 CliCommand::new(&api2::config::remote::API_METHOD_CREATE_REMOTE)
86 .arg_param(&["name"])
87 )
88 .insert(
89 "update",
90 CliCommand::new(&api2::config::remote::API_METHOD_UPDATE_REMOTE)
91 .arg_param(&["name"])
92 .completion_cb("name", config::remote::complete_remote_name)
93 )
94 .insert(
95 "remove",
96 CliCommand::new(&api2::config::remote::API_METHOD_DELETE_REMOTE)
97 .arg_param(&["name"])
98 .completion_cb("name", config::remote::complete_remote_name)
99 );
100
101 cmd_def.into()
102 }