forked from Proxmox/proxmox
system-config-api: expose helpers to set ports/slaves as string (list)
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
This commit is contained in:
parent
805b1d366b
commit
26c7a591eb
@ -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<String>) -> 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<Vec<String>, 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()]
|
||||
|
@ -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<u8>, bool), Error> {
|
||||
pub(crate) fn parse_address_or_cidr(cidr: &str) -> Result<(String, Option<u8>, 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<u8>, bool), E
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_network_interfaces() -> Result<HashMap<String, bool>, Error> {
|
||||
pub(crate) fn get_network_interfaces() -> Result<HashMap<String, bool>, Error> {
|
||||
const PROC_NET_DEV: &str = "/proc/net/dev";
|
||||
|
||||
#[repr(C)]
|
||||
@ -196,7 +196,7 @@ pub fn get_network_interfaces() -> Result<HashMap<String, bool>, Error> {
|
||||
Ok(interface_list)
|
||||
}
|
||||
|
||||
pub fn compute_file_diff(filename: &str, shadow: &str) -> Result<String, Error> {
|
||||
pub(crate) fn compute_file_diff(filename: &str, shadow: &str) -> Result<String, Error> {
|
||||
let output = Command::new("diff")
|
||||
.arg("-b")
|
||||
.arg("-u")
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user