src/config/network.rs: implement bond_mode
and rename bond_slaves to slaves to make it compatible with pve.
This commit is contained in:
@ -187,7 +187,11 @@ pub fn read_interface(iface: String) -> Result<Value, Error> {
|
||||
type: bool,
|
||||
optional: true,
|
||||
},
|
||||
bond_slaves: {
|
||||
bond_mode: {
|
||||
type: LinuxBondMode,
|
||||
optional: true,
|
||||
},
|
||||
slaves: {
|
||||
schema: NETWORK_INTERFACE_LIST_SCHEMA,
|
||||
optional: true,
|
||||
},
|
||||
@ -212,7 +216,8 @@ pub fn create_interface(
|
||||
mtu: Option<u64>,
|
||||
bridge_ports: Option<Vec<String>>,
|
||||
bridge_vlan_aware: Option<bool>,
|
||||
bond_slaves: Option<Vec<String>>,
|
||||
bond_mode: Option<LinuxBondMode>,
|
||||
slaves: Option<Vec<String>>,
|
||||
param: Value,
|
||||
) -> Result<(), Error> {
|
||||
|
||||
@ -269,7 +274,8 @@ pub fn create_interface(
|
||||
if bridge_vlan_aware.is_some() { interface.bridge_vlan_aware = bridge_vlan_aware; }
|
||||
}
|
||||
NetworkInterfaceType::Bond => {
|
||||
if let Some(slaves) = bond_slaves { interface.set_bond_slaves(slaves)?; }
|
||||
if bond_mode.is_some() { interface.bond_mode = bond_mode; }
|
||||
if let Some(slaves) = slaves { interface.set_bond_slaves(slaves)?; }
|
||||
}
|
||||
_ => bail!("creating network interface type '{:?}' is not supported", interface_type),
|
||||
}
|
||||
@ -323,7 +329,7 @@ pub enum DeletableProperty {
|
||||
/// Delet bridge-vlan-aware flag
|
||||
bridge_vlan_aware,
|
||||
/// Delete bond-slaves (set to 'none')
|
||||
bond_slaves,
|
||||
slaves,
|
||||
}
|
||||
|
||||
|
||||
@ -397,7 +403,11 @@ pub enum DeletableProperty {
|
||||
type: bool,
|
||||
optional: true,
|
||||
},
|
||||
bond_slaves: {
|
||||
bond_mode: {
|
||||
type: LinuxBondMode,
|
||||
optional: true,
|
||||
},
|
||||
slaves: {
|
||||
schema: NETWORK_INTERFACE_LIST_SCHEMA,
|
||||
optional: true,
|
||||
},
|
||||
@ -434,7 +444,8 @@ pub fn update_interface(
|
||||
mtu: Option<u64>,
|
||||
bridge_ports: Option<Vec<String>>,
|
||||
bridge_vlan_aware: Option<bool>,
|
||||
bond_slaves: Option<Vec<String>>,
|
||||
bond_mode: Option<LinuxBondMode>,
|
||||
slaves: Option<Vec<String>>,
|
||||
delete: Option<Vec<DeletableProperty>>,
|
||||
digest: Option<String>,
|
||||
param: Value,
|
||||
@ -476,7 +487,7 @@ pub fn update_interface(
|
||||
DeletableProperty::autostart => { interface.autostart = false; },
|
||||
DeletableProperty::bridge_ports => { interface.set_bridge_ports(Vec::new())?; }
|
||||
DeletableProperty::bridge_vlan_aware => { interface.bridge_vlan_aware = None; }
|
||||
DeletableProperty::bond_slaves => { interface.set_bond_slaves(Vec::new())?; }
|
||||
DeletableProperty::slaves => { interface.set_bond_slaves(Vec::new())?; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -487,7 +498,8 @@ pub fn update_interface(
|
||||
if mtu.is_some() { interface.mtu = mtu; }
|
||||
if let Some(ports) = bridge_ports { interface.set_bridge_ports(ports)?; }
|
||||
if bridge_vlan_aware.is_some() { interface.bridge_vlan_aware = bridge_vlan_aware; }
|
||||
if let Some(slaves) = bond_slaves { interface.set_bond_slaves(slaves)?; }
|
||||
if let Some(slaves) = slaves { interface.set_bond_slaves(slaves)?; }
|
||||
if bond_mode.is_some() { interface.bond_mode = bond_mode; }
|
||||
|
||||
if let Some(cidr) = cidr {
|
||||
let (_, _, is_v6) = network::parse_cidr(&cidr)?;
|
||||
|
@ -549,6 +549,30 @@ pub enum NetworkConfigMethod {
|
||||
Loopback,
|
||||
}
|
||||
|
||||
#[api()]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[repr(u8)]
|
||||
/// Linux Bond Mode
|
||||
pub enum LinuxBondMode {
|
||||
/// Round-robin policy
|
||||
balance_rr = 0,
|
||||
/// Active-backup policy
|
||||
active_backup = 1,
|
||||
/// XOR policy
|
||||
balance_xor = 2,
|
||||
/// Broadcast policy
|
||||
broadcast = 3,
|
||||
/// IEEE 802.3ad Dynamic link aggregation
|
||||
//#[serde(rename = "802.3ad")]
|
||||
ieee802_3ad = 4,
|
||||
/// Adaptive transmit load balancing
|
||||
balance_tlb = 5,
|
||||
/// Adaptive load balancing
|
||||
balance_alb = 6,
|
||||
}
|
||||
|
||||
#[api()]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
@ -642,10 +666,14 @@ pub const NETWORK_INTERFACE_LIST_SCHEMA: Schema = ArraySchema::new(
|
||||
schema: NETWORK_INTERFACE_LIST_SCHEMA,
|
||||
optional: true,
|
||||
},
|
||||
bond_slaves: {
|
||||
slaves: {
|
||||
schema: NETWORK_INTERFACE_LIST_SCHEMA,
|
||||
optional: true,
|
||||
},
|
||||
bond_mode: {
|
||||
type: LinuxBondMode,
|
||||
optional: true,
|
||||
}
|
||||
}
|
||||
)]
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
@ -699,7 +727,9 @@ pub struct Interface {
|
||||
pub bridge_vlan_aware: Option<bool>,
|
||||
|
||||
#[serde(skip_serializing_if="Option::is_none")]
|
||||
pub bond_slaves: Option<Vec<String>>,
|
||||
pub slaves: Option<Vec<String>>,
|
||||
#[serde(skip_serializing_if="Option::is_none")]
|
||||
pub bond_mode: Option<LinuxBondMode>,
|
||||
}
|
||||
|
||||
// Regression tests
|
||||
|
Reference in New Issue
Block a user