]> git.proxmox.com Git - proxmox-backup.git/blob - src/bin/proxmox_backup_manager/traffic_control.rs
Add traffic control configuration config with API
[proxmox-backup.git] / src / bin / proxmox_backup_manager / traffic_control.rs
1 use anyhow::Error;
2 use serde_json::Value;
3
4 use proxmox_router::{cli::*, ApiHandler, RpcEnvironment};
5 use proxmox_schema::api;
6
7 use pbs_api_types::TRAFFIC_CONTROL_ID_SCHEMA;
8
9 use proxmox_backup::api2;
10
11
12 #[api(
13 input: {
14 properties: {
15 "output-format": {
16 schema: OUTPUT_FORMAT,
17 optional: true,
18 },
19 }
20 }
21 )]
22 /// List configured traffic control rules.
23 fn list_traffic_controls(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
24
25 let output_format = get_output_format(&param);
26
27 let info = &api2::config::traffic_control::API_METHOD_LIST_TRAFFIC_CONTROLS;
28 let mut data = match info.handler {
29 ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
30 _ => unreachable!(),
31 };
32
33 let options = default_table_format_options()
34 .column(ColumnConfig::new("name"))
35 .column(ColumnConfig::new("rate-in"))
36 .column(ColumnConfig::new("burst-in"))
37 .column(ColumnConfig::new("rate-out"))
38 .column(ColumnConfig::new("burst-out"))
39 .column(ColumnConfig::new("network"))
40 .column(ColumnConfig::new("timeframe"))
41 .column(ColumnConfig::new("comment"));
42
43 format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
44
45 Ok(Value::Null)
46 }
47
48 #[api(
49 input: {
50 properties: {
51 name: {
52 schema: TRAFFIC_CONTROL_ID_SCHEMA,
53 },
54 "output-format": {
55 schema: OUTPUT_FORMAT,
56 optional: true,
57 },
58 }
59 }
60 )]
61 /// Show traffic control configuration
62 fn show_traffic_control(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
63
64 let output_format = get_output_format(&param);
65
66 let info = &api2::config::traffic_control::API_METHOD_READ_TRAFFIC_CONTROL;
67 let mut data = match info.handler {
68 ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
69 _ => unreachable!(),
70 };
71
72 let options = default_table_format_options();
73 format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
74
75 Ok(Value::Null)
76 }
77
78 pub fn traffic_control_commands() -> CommandLineInterface {
79
80 let cmd_def = CliCommandMap::new()
81 .insert("list", CliCommand::new(&API_METHOD_LIST_TRAFFIC_CONTROLS))
82 .insert(
83 "show",
84 CliCommand::new(&API_METHOD_SHOW_TRAFFIC_CONTROL)
85 .arg_param(&["name"])
86 .completion_cb("name", pbs_config::traffic_control::complete_traffic_control_name)
87 )
88 .insert(
89 "create",
90 CliCommand::new(&api2::config::traffic_control::API_METHOD_CREATE_TRAFFIC_CONTROL)
91 .arg_param(&["name"])
92 )
93 .insert(
94 "update",
95 CliCommand::new(&api2::config::traffic_control::API_METHOD_UPDATE_TRAFFIC_CONTROL)
96 .arg_param(&["name"])
97 .completion_cb("name", pbs_config::traffic_control::complete_traffic_control_name)
98 )
99 .insert(
100 "remove",
101 CliCommand::new(&api2::config::traffic_control::API_METHOD_DELETE_TRAFFIC_CONTROL)
102 .arg_param(&["name"])
103 .completion_cb("name", pbs_config::traffic_control::complete_traffic_control_name)
104 );
105
106 cmd_def.into()
107 }