4 use proxmox_router
::{cli::*, ApiHandler, RpcEnvironment}
;
5 use proxmox_schema
::api
;
7 use pbs_api_types
::TRAFFIC_CONTROL_ID_SCHEMA
;
9 use proxmox_backup
::api2
;
16 schema
: OUTPUT_FORMAT
,
22 /// List configured traffic control rules.
23 fn list_traffic_controls(param
: Value
, rpcenv
: &mut dyn RpcEnvironment
) -> Result
<Value
, Error
> {
25 let output_format
= get_output_format(¶m
);
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
)?
,
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"));
43 format_and_print_result_full(&mut data
, &info
.returns
, &output_format
, &options
);
52 schema
: TRAFFIC_CONTROL_ID_SCHEMA
,
55 schema
: OUTPUT_FORMAT
,
61 /// Show traffic control configuration
62 fn show_traffic_control(param
: Value
, rpcenv
: &mut dyn RpcEnvironment
) -> Result
<Value
, Error
> {
64 let output_format
= get_output_format(¶m
);
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
)?
,
72 let options
= default_table_format_options();
73 format_and_print_result_full(&mut data
, &info
.returns
, &output_format
, &options
);
78 pub fn traffic_control_commands() -> CommandLineInterface
{
80 let cmd_def
= CliCommandMap
::new()
81 .insert("list", CliCommand
::new(&API_METHOD_LIST_TRAFFIC_CONTROLS
))
84 CliCommand
::new(&API_METHOD_SHOW_TRAFFIC_CONTROL
)
86 .completion_cb("name", pbs_config
::traffic_control
::complete_traffic_control_name
)
90 CliCommand
::new(&api2
::config
::traffic_control
::API_METHOD_CREATE_TRAFFIC_CONTROL
)
95 CliCommand
::new(&api2
::config
::traffic_control
::API_METHOD_UPDATE_TRAFFIC_CONTROL
)
97 .completion_cb("name", pbs_config
::traffic_control
::complete_traffic_control_name
)
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
)