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