]> git.proxmox.com Git - proxmox-backup.git/blob - src/bin/proxmox_backup_manager/sync.rs
adaptions for proxmox 0.9 and proxmox-api-macro 0.3
[proxmox-backup.git] / src / bin / proxmox_backup_manager / sync.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 /// Sync job list.
20 fn list_sync_jobs(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
21
22 let output_format = get_output_format(&param);
23
24 let info = &api2::config::sync::API_METHOD_LIST_SYNC_JOBS;
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("id"))
32 .column(ColumnConfig::new("store"))
33 .column(ColumnConfig::new("remote"))
34 .column(ColumnConfig::new("remote-store"))
35 .column(ColumnConfig::new("schedule"))
36 .column(ColumnConfig::new("comment"));
37
38 format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
39
40 Ok(Value::Null)
41 }
42
43 #[api(
44 input: {
45 properties: {
46 id: {
47 schema: JOB_ID_SCHEMA,
48 },
49 "output-format": {
50 schema: OUTPUT_FORMAT,
51 optional: true,
52 },
53 }
54 }
55 )]
56 /// Show sync job configuration
57 fn show_sync_job(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
58
59 let output_format = get_output_format(&param);
60
61 let info = &api2::config::sync::API_METHOD_READ_SYNC_JOB;
62 let mut data = match info.handler {
63 ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
64 _ => unreachable!(),
65 };
66
67 let options = default_table_format_options();
68 format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
69
70 Ok(Value::Null)
71 }
72
73 pub fn sync_job_commands() -> CommandLineInterface {
74
75 let cmd_def = CliCommandMap::new()
76 .insert("list", CliCommand::new(&API_METHOD_LIST_SYNC_JOBS))
77 .insert("show",
78 CliCommand::new(&API_METHOD_SHOW_SYNC_JOB)
79 .arg_param(&["id"])
80 .completion_cb("id", config::sync::complete_sync_job_id)
81 )
82 .insert("create",
83 CliCommand::new(&api2::config::sync::API_METHOD_CREATE_SYNC_JOB)
84 .arg_param(&["id"])
85 .completion_cb("id", config::sync::complete_sync_job_id)
86 .completion_cb("schedule", config::datastore::complete_calendar_event)
87 .completion_cb("store", config::datastore::complete_datastore_name)
88 .completion_cb("remote", config::remote::complete_remote_name)
89 .completion_cb("remote-store", crate::complete_remote_datastore_name)
90 )
91 .insert("update",
92 CliCommand::new(&api2::config::sync::API_METHOD_UPDATE_SYNC_JOB)
93 .arg_param(&["id"])
94 .completion_cb("id", config::sync::complete_sync_job_id)
95 .completion_cb("schedule", config::datastore::complete_calendar_event)
96 .completion_cb("store", config::datastore::complete_datastore_name)
97 .completion_cb("remote-store", crate::complete_remote_datastore_name)
98 )
99 .insert("remove",
100 CliCommand::new(&api2::config::sync::API_METHOD_DELETE_SYNC_JOB)
101 .arg_param(&["id"])
102 .completion_cb("id", config::sync::complete_sync_job_id)
103 );
104
105 cmd_def.into()
106 }