diff --git a/proxmox-system-config-api/src/network/api_types.rs b/proxmox-system-config-api/src/network/api_types.rs index 5c775ebe..aa3028c2 100644 --- a/proxmox-system-config-api/src/network/api_types.rs +++ b/proxmox-system-config-api/src/network/api_types.rs @@ -372,6 +372,12 @@ impl Interface { Ok(()) } + /// Setter for bridge ports (check if interface type is a bridge) + pub fn set_bridge_port_list(&mut self, ports: &str) -> Result<(), Error> { + let ports = Self::split_interface_list(ports)?; + self.set_bridge_ports(ports) + } + /// Setter for bond slaves (check if interface type is a bond) pub fn set_bond_slaves(&mut self, slaves: Vec) -> Result<(), Error> { if self.interface_type != NetworkInterfaceType::Bond { @@ -385,6 +391,22 @@ impl Interface { Ok(()) } + /// Setter for bond slaves (check if interface type is a bond) + pub fn set_bond_slave_list(&mut self, slaves: &str) -> Result<(), Error> { + let slaves = Self::split_interface_list(slaves)?; + self.set_bond_slaves(slaves) + } + + /// Split a network interface list into an array of interface names. + pub fn split_interface_list(list: &str) -> Result, Error> { + let value = NETWORK_INTERFACE_ARRAY_SCHEMA.parse_property_string(list)?; + Ok(value + .as_array() + .unwrap() + .iter() + .map(|v| v.as_str().unwrap().to_string()) + .collect()) + } } #[api()] diff --git a/proxmox-system-config-api/src/network/config/helper.rs b/proxmox-system-config-api/src/network/config/helper.rs index c2a3f70a..00464384 100644 --- a/proxmox-system-config-api/src/network/config/helper.rs +++ b/proxmox-system-config-api/src/network/config/helper.rs @@ -69,7 +69,7 @@ pub fn parse_cidr(cidr: &str) -> Result<(String, u8, bool), Error> { } } -pub fn check_netmask(mask: u8, is_v6: bool) -> Result<(), Error> { +pub(crate) fn check_netmask(mask: u8, is_v6: bool) -> Result<(), Error> { let (ver, min, max) = if is_v6 { ("IPv6", 1, 128) } else { @@ -90,7 +90,7 @@ pub fn check_netmask(mask: u8, is_v6: bool) -> Result<(), Error> { } // parse ip address with optional cidr mask -pub fn parse_address_or_cidr(cidr: &str) -> Result<(String, Option, bool), Error> { +pub(crate) fn parse_address_or_cidr(cidr: &str) -> Result<(String, Option, bool), Error> { // NOTE: This is NOT the same regex as in proxmox-schema as this one has capture groups for // the addresses vs cidr portions! lazy_static! { @@ -123,7 +123,7 @@ pub fn parse_address_or_cidr(cidr: &str) -> Result<(String, Option, bool), E } } -pub fn get_network_interfaces() -> Result, Error> { +pub(crate) fn get_network_interfaces() -> Result, Error> { const PROC_NET_DEV: &str = "/proc/net/dev"; #[repr(C)] @@ -196,7 +196,7 @@ pub fn get_network_interfaces() -> Result, Error> { Ok(interface_list) } -pub fn compute_file_diff(filename: &str, shadow: &str) -> Result { +pub(crate) fn compute_file_diff(filename: &str, shadow: &str) -> Result { let output = Command::new("diff") .arg("-b") .arg("-u") diff --git a/proxmox-system-config-api/src/network/config/mod.rs b/proxmox-system-config-api/src/network/config/mod.rs index b994ef7d..848385fb 100644 --- a/proxmox-system-config-api/src/network/config/mod.rs +++ b/proxmox-system-config-api/src/network/config/mod.rs @@ -2,6 +2,8 @@ mod helper; mod lexer; mod parser; +pub use helper::{assert_ifupdown2_installed, network_reload, parse_cidr}; + use std::collections::{BTreeMap, HashMap, HashSet}; use std::io::Write;