4 use proxmox_router
::{cli::*, ApiHandler, RpcEnvironment}
;
5 use proxmox_schema
::api
;
7 use proxmox_backup
::api2
;
13 schema
: OUTPUT_FORMAT
,
19 /// Network device list.
20 fn list_network_devices(mut param
: Value
, rpcenv
: &mut dyn RpcEnvironment
) -> Result
<Value
, Error
> {
22 let output_format
= get_output_format(¶m
);
24 param
["node"] = "localhost".into();
26 let info
= &api2
::node
::network
::API_METHOD_LIST_NETWORK_DEVICES
;
27 let mut data
= match info
.handler
{
28 ApiHandler
::Sync(handler
) => (handler
)(param
, info
, rpcenv
)?
,
32 if let Value
::String(ref diff
) = rpcenv
["changes"] {
33 if output_format
== "text" {
34 eprintln
!("pending changes:\n{}\n", diff
);
38 fn render_address(_value
: &Value
, record
: &Value
) -> Result
<String
, Error
> {
39 let mut text
= String
::new();
41 if let Some(cidr
) = record
["cidr"].as_str() {
44 if let Some(cidr
) = record
["cidr6"].as_str() {
45 if !text
.is_empty() { text.push('\n'); }
52 fn render_ports(_value
: &Value
, record
: &Value
) -> Result
<String
, Error
> {
53 let mut text
= String
::new();
55 if let Some(ports
) = record
["bridge_ports"].as_array() {
56 let list
: Vec
<&str> = ports
.iter().filter_map(|v
| v
.as_str()).collect();
57 text
.push_str(&list
.join(" "));
59 if let Some(slaves
) = record
["slaves"].as_array() {
60 let list
: Vec
<&str> = slaves
.iter().filter_map(|v
| v
.as_str()).collect();
61 text
.push_str(&list
.join(" "));
67 fn render_gateway(_value
: &Value
, record
: &Value
) -> Result
<String
, Error
> {
68 let mut text
= String
::new();
70 if let Some(gateway
) = record
["gateway"].as_str() {
71 text
.push_str(gateway
);
73 if let Some(gateway
) = record
["gateway6"].as_str() {
74 if !text
.is_empty() { text.push('\n'); }
75 text
.push_str(gateway
);
81 let options
= default_table_format_options()
82 .column(ColumnConfig
::new("name"))
83 .column(ColumnConfig
::new("type").header("type"))
84 .column(ColumnConfig
::new("autostart"))
85 .column(ColumnConfig
::new("method"))
86 .column(ColumnConfig
::new("method6"))
87 .column(ColumnConfig
::new("cidr").header("address").renderer(render_address
))
88 .column(ColumnConfig
::new("gateway").header("gateway").renderer(render_gateway
))
89 .column(ColumnConfig
::new("bridge_ports").header("ports/slaves").renderer(render_ports
));
91 format_and_print_result_full(&mut data
, &info
.returns
, &output_format
, &options
);
97 /// Show pending configuration changes (diff)
98 fn pending_network_changes(mut param
: Value
, rpcenv
: &mut dyn RpcEnvironment
) -> Result
<Value
, Error
> {
99 param
["node"] = "localhost".into();
101 let info
= &api2
::node
::network
::API_METHOD_LIST_NETWORK_DEVICES
;
102 let _data
= match info
.handler
{
103 ApiHandler
::Sync(handler
) => (handler
)(param
, info
, rpcenv
)?
,
107 if let Value
::String(ref diff
) = rpcenv
["changes"] {
108 println
!("{}", diff
);
114 pub fn network_commands() -> CommandLineInterface
{
116 let cmd_def
= CliCommandMap
::new()
119 CliCommand
::new(&API_METHOD_LIST_NETWORK_DEVICES
)
123 CliCommand
::new(&API_METHOD_PENDING_NETWORK_CHANGES
)
127 CliCommand
::new(&api2
::node
::network
::API_METHOD_CREATE_INTERFACE
)
128 .fixed_param("node", String
::from("localhost"))
129 .arg_param(&["iface"])
130 .completion_cb("iface", pbs_config
::network
::complete_interface_name
)
131 .completion_cb("bridge_ports", pbs_config
::network
::complete_port_list
)
132 .completion_cb("slaves", pbs_config
::network
::complete_port_list
)
136 CliCommand
::new(&api2
::node
::network
::API_METHOD_UPDATE_INTERFACE
)
137 .fixed_param("node", String
::from("localhost"))
138 .arg_param(&["iface"])
139 .completion_cb("iface", pbs_config
::network
::complete_interface_name
)
140 .completion_cb("bridge_ports", pbs_config
::network
::complete_port_list
)
141 .completion_cb("slaves", pbs_config
::network
::complete_port_list
)
145 CliCommand
::new(&api2
::node
::network
::API_METHOD_DELETE_INTERFACE
)
146 .fixed_param("node", String
::from("localhost"))
147 .arg_param(&["iface"])
148 .completion_cb("iface", pbs_config
::network
::complete_interface_name
)
152 CliCommand
::new(&api2
::node
::network
::API_METHOD_REVERT_NETWORK_CONFIG
)
153 .fixed_param("node", String
::from("localhost"))
157 CliCommand
::new(&api2
::node
::network
::API_METHOD_RELOAD_NETWORK_CONFIG
)
158 .fixed_param("node", String
::from("localhost"))