]>
Commit | Line | Data |
---|---|---|
be327dbc DM |
1 | use anyhow::Error; |
2 | use serde_json::Value; | |
3 | ||
4 | use proxmox::api::{api, cli::*, RpcEnvironment, ApiHandler}; | |
5 | ||
2b7f8dd5 WB |
6 | use pbs_client::{connect_to_localhost, view_task_result}; |
7 | ||
be327dbc DM |
8 | use proxmox_backup::{ |
9 | config, | |
10 | api2::{ | |
11 | self, | |
12 | types::*, | |
13 | }, | |
14 | }; | |
15 | ||
16 | #[api( | |
17 | input: { | |
18 | properties: { | |
19 | "output-format": { | |
20 | schema: OUTPUT_FORMAT, | |
21 | optional: true, | |
22 | }, | |
23 | } | |
24 | } | |
25 | )] | |
26 | /// Tape backup job list. | |
27 | fn list_tape_backup_jobs(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { | |
28 | ||
29 | let output_format = get_output_format(¶m); | |
30 | ||
31 | let info = &api2::config::tape_backup_job::API_METHOD_LIST_TAPE_BACKUP_JOBS; | |
32 | let mut data = match info.handler { | |
33 | ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, | |
34 | _ => unreachable!(), | |
35 | }; | |
36 | ||
37 | let options = default_table_format_options() | |
38 | .column(ColumnConfig::new("id")) | |
39 | .column(ColumnConfig::new("store")) | |
40 | .column(ColumnConfig::new("pool")) | |
41 | .column(ColumnConfig::new("drive")) | |
42 | .column(ColumnConfig::new("schedule")) | |
43 | .column(ColumnConfig::new("comment")); | |
44 | ||
45 | format_and_print_result_full(&mut data, &info.returns, &output_format, &options); | |
46 | ||
47 | Ok(Value::Null) | |
48 | } | |
49 | ||
50 | #[api( | |
51 | input: { | |
52 | properties: { | |
53 | id: { | |
54 | schema: JOB_ID_SCHEMA, | |
55 | }, | |
56 | "output-format": { | |
57 | schema: OUTPUT_FORMAT, | |
58 | optional: true, | |
59 | }, | |
60 | } | |
61 | } | |
62 | )] | |
63 | /// Show tape backup job configuration | |
64 | fn show_tape_backup_job(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { | |
65 | ||
66 | let output_format = get_output_format(¶m); | |
67 | ||
68 | let info = &api2::config::tape_backup_job::API_METHOD_READ_TAPE_BACKUP_JOB; | |
69 | let mut data = match info.handler { | |
70 | ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, | |
71 | _ => unreachable!(), | |
72 | }; | |
73 | ||
74 | let options = default_table_format_options(); | |
75 | format_and_print_result_full(&mut data, &info.returns, &output_format, &options); | |
76 | ||
77 | Ok(Value::Null) | |
78 | } | |
79 | ||
41a8db35 DM |
80 | #[api( |
81 | input: { | |
82 | properties: { | |
83 | id: { | |
84 | schema: JOB_ID_SCHEMA, | |
85 | }, | |
86 | }, | |
87 | }, | |
88 | )] | |
89 | /// Run THape Backup Job | |
90 | async fn run_tape_backup_job(mut param: Value) -> Result<(), Error> { | |
91 | ||
92 | let output_format = get_output_format(¶m); | |
93 | ||
94 | let id = param["id"].take().as_str().unwrap().to_string(); | |
95 | ||
96 | let mut client = connect_to_localhost()?; | |
97 | ||
98 | let result = client.post(&format!("api2/json/tape/backup/{}", id), Some(param)).await?; | |
99 | ||
100 | view_task_result(&mut client, result, &output_format).await?; | |
101 | ||
102 | Ok(()) | |
103 | } | |
104 | ||
be327dbc DM |
105 | pub fn backup_job_commands() -> CommandLineInterface { |
106 | ||
107 | let cmd_def = CliCommandMap::new() | |
108 | .insert("list", CliCommand::new(&API_METHOD_LIST_TAPE_BACKUP_JOBS)) | |
109 | .insert("show", | |
110 | CliCommand::new(&API_METHOD_SHOW_TAPE_BACKUP_JOB) | |
111 | .arg_param(&["id"]) | |
112 | .completion_cb("id", config::tape_job::complete_tape_job_id) | |
113 | ) | |
41a8db35 DM |
114 | .insert("run", |
115 | CliCommand::new(&API_METHOD_RUN_TAPE_BACKUP_JOB) | |
116 | .arg_param(&["id"]) | |
117 | .completion_cb("id", config::tape_job::complete_tape_job_id) | |
118 | ) | |
be327dbc DM |
119 | .insert("create", |
120 | CliCommand::new(&api2::config::tape_backup_job::API_METHOD_CREATE_TAPE_BACKUP_JOB) | |
121 | .arg_param(&["id"]) | |
122 | .completion_cb("id", config::tape_job::complete_tape_job_id) | |
123 | .completion_cb("schedule", config::datastore::complete_calendar_event) | |
124 | .completion_cb("store", config::datastore::complete_datastore_name) | |
125 | .completion_cb("pool", config::media_pool::complete_pool_name) | |
126 | .completion_cb("drive", crate::complete_drive_name) | |
127 | ) | |
128 | .insert("update", | |
129 | CliCommand::new(&api2::config::tape_backup_job::API_METHOD_UPDATE_TAPE_BACKUP_JOB) | |
130 | .arg_param(&["id"]) | |
131 | .completion_cb("id", config::tape_job::complete_tape_job_id) | |
132 | .completion_cb("schedule", config::datastore::complete_calendar_event) | |
133 | .completion_cb("store", config::datastore::complete_datastore_name) | |
134 | .completion_cb("pool", config::media_pool::complete_pool_name) | |
135 | .completion_cb("drive", crate::complete_drive_name) | |
136 | ) | |
137 | .insert("remove", | |
138 | CliCommand::new(&api2::config::tape_backup_job::API_METHOD_DELETE_TAPE_BACKUP_JOB) | |
139 | .arg_param(&["id"]) | |
140 | .completion_cb("id", config::tape_job::complete_tape_job_id) | |
141 | ); | |
142 | ||
143 | cmd_def.into() | |
144 | } |