]>
Commit | Line | Data |
---|---|---|
e6604cf3 DM |
1 | use anyhow::Error; |
2 | use serde_json::Value; | |
3 | ||
6ef1b649 WB |
4 | use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; |
5 | use proxmox_schema::api; | |
e6604cf3 | 6 | |
1ce8e905 DM |
7 | use pbs_api_types::DRIVE_NAME_SCHEMA; |
8 | ||
9 | use pbs_config::drive::{ | |
10 | complete_drive_name, | |
11 | complete_changer_name, | |
12 | complete_lto_drive_name, | |
e6604cf3 DM |
13 | }; |
14 | ||
048b43af DM |
15 | use pbs_tape::linux_list_drives::{complete_drive_path}; |
16 | ||
17 | use proxmox_backup::api2; | |
1ce8e905 | 18 | |
e6604cf3 DM |
19 | pub fn drive_commands() -> CommandLineInterface { |
20 | ||
21 | let cmd_def = CliCommandMap::new() | |
5605ca56 | 22 | .insert("scan", CliCommand::new(&API_METHOD_SCAN_FOR_DRIVES)) |
e6604cf3 DM |
23 | .insert("list", CliCommand::new(&API_METHOD_LIST_DRIVES)) |
24 | .insert("config", | |
25 | CliCommand::new(&API_METHOD_GET_CONFIG) | |
26 | .arg_param(&["name"]) | |
a79082a0 | 27 | .completion_cb("name", complete_lto_drive_name) |
e6604cf3 DM |
28 | ) |
29 | .insert( | |
30 | "remove", | |
a3c709ef | 31 | CliCommand::new(&api2::config::drive::API_METHOD_DELETE_DRIVE) |
e6604cf3 | 32 | .arg_param(&["name"]) |
a79082a0 | 33 | .completion_cb("name", complete_lto_drive_name) |
e6604cf3 DM |
34 | ) |
35 | .insert( | |
36 | "create", | |
a3c709ef | 37 | CliCommand::new(&api2::config::drive::API_METHOD_CREATE_DRIVE) |
e6604cf3 DM |
38 | .arg_param(&["name"]) |
39 | .completion_cb("name", complete_drive_name) | |
40 | .completion_cb("path", complete_drive_path) | |
41 | .completion_cb("changer", complete_changer_name) | |
42 | ) | |
43 | .insert( | |
44 | "update", | |
a3c709ef | 45 | CliCommand::new(&api2::config::drive::API_METHOD_UPDATE_DRIVE) |
e6604cf3 | 46 | .arg_param(&["name"]) |
a79082a0 | 47 | .completion_cb("name", complete_lto_drive_name) |
e6604cf3 DM |
48 | .completion_cb("path", complete_drive_path) |
49 | .completion_cb("changer", complete_changer_name) | |
50 | ) | |
e6604cf3 DM |
51 | ; |
52 | ||
53 | cmd_def.into() | |
54 | } | |
55 | ||
e6604cf3 DM |
56 | #[api( |
57 | input: { | |
58 | properties: { | |
59 | "output-format": { | |
60 | schema: OUTPUT_FORMAT, | |
61 | optional: true, | |
62 | }, | |
63 | }, | |
64 | }, | |
65 | )] | |
66 | /// List drives | |
67 | fn list_drives( | |
68 | param: Value, | |
69 | rpcenv: &mut dyn RpcEnvironment, | |
70 | ) -> Result<(), Error> { | |
71 | ||
72 | let output_format = get_output_format(¶m); | |
5fdaecf6 | 73 | let info = &api2::tape::drive::API_METHOD_LIST_DRIVES; |
e6604cf3 DM |
74 | let mut data = match info.handler { |
75 | ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, | |
76 | _ => unreachable!(), | |
77 | }; | |
78 | ||
79 | let options = default_table_format_options() | |
80 | .column(ColumnConfig::new("name")) | |
81 | .column(ColumnConfig::new("path")) | |
82 | .column(ColumnConfig::new("changer")) | |
83 | .column(ColumnConfig::new("vendor")) | |
84 | .column(ColumnConfig::new("model")) | |
85 | .column(ColumnConfig::new("serial")) | |
86 | ; | |
87 | ||
b2362a12 | 88 | format_and_print_result_full(&mut data, &info.returns, &output_format, &options); |
e6604cf3 DM |
89 | |
90 | Ok(()) | |
91 | } | |
92 | ||
93 | #[api( | |
94 | input: { | |
95 | properties: { | |
96 | "output-format": { | |
97 | schema: OUTPUT_FORMAT, | |
98 | optional: true, | |
99 | }, | |
100 | }, | |
101 | } | |
102 | )] | |
103 | /// Scan for drives | |
104 | fn scan_for_drives( | |
105 | param: Value, | |
106 | rpcenv: &mut dyn RpcEnvironment, | |
107 | ) -> Result<(), Error> { | |
108 | ||
109 | let output_format = get_output_format(¶m); | |
9586ce2f | 110 | let info = &api2::tape::API_METHOD_SCAN_DRIVES; |
e6604cf3 DM |
111 | let mut data = match info.handler { |
112 | ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, | |
113 | _ => unreachable!(), | |
114 | }; | |
115 | ||
116 | let options = default_table_format_options() | |
117 | .column(ColumnConfig::new("path")) | |
118 | .column(ColumnConfig::new("vendor")) | |
119 | .column(ColumnConfig::new("model")) | |
120 | .column(ColumnConfig::new("serial")) | |
121 | ; | |
122 | ||
b2362a12 | 123 | format_and_print_result_full(&mut data, &info.returns, &output_format, &options); |
e6604cf3 DM |
124 | |
125 | Ok(()) | |
126 | } | |
127 | ||
128 | ||
129 | #[api( | |
130 | input: { | |
131 | properties: { | |
132 | "output-format": { | |
133 | schema: OUTPUT_FORMAT, | |
134 | optional: true, | |
135 | }, | |
136 | name: { | |
49c965a4 | 137 | schema: DRIVE_NAME_SCHEMA, |
e6604cf3 DM |
138 | }, |
139 | }, | |
140 | }, | |
141 | )] | |
142 | /// Get pool configuration | |
143 | fn get_config( | |
144 | param: Value, | |
145 | rpcenv: &mut dyn RpcEnvironment, | |
146 | ) -> Result<(), Error> { | |
147 | ||
148 | let output_format = get_output_format(¶m); | |
149 | let info = &api2::config::drive::API_METHOD_GET_CONFIG; | |
150 | let mut data = match info.handler { | |
151 | ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, | |
152 | _ => unreachable!(), | |
153 | }; | |
154 | ||
155 | let options = default_table_format_options() | |
156 | .column(ColumnConfig::new("name")) | |
157 | .column(ColumnConfig::new("path")) | |
158 | .column(ColumnConfig::new("changer")) | |
627d0000 | 159 | .column(ColumnConfig::new("changer-drivenum")) |
e6604cf3 DM |
160 | ; |
161 | ||
b2362a12 | 162 | format_and_print_result_full(&mut data, &info.returns, &output_format, &options); |
e6604cf3 DM |
163 | |
164 | Ok(()) | |
165 | } |