From 943cfd541795b0e3c598cac128a8e772cc009d4f Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 10 May 2024 09:53:27 +0200 Subject: [PATCH] system-config-api: network: add helpers to set bridge ports and bond slaves Signed-off-by: Dietmar Maurer --- .../src/network/api_types.rs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/proxmox-system-config-api/src/network/api_types.rs b/proxmox-system-config-api/src/network/api_types.rs index d0f62e27..34d0840c 100644 --- a/proxmox-system-config-api/src/network/api_types.rs +++ b/proxmox-system-config-api/src/network/api_types.rs @@ -1,5 +1,6 @@ use std::fmt; +use anyhow::{bail, Error}; use serde::{Deserialize, Serialize}; use lazy_static::lazy_static; @@ -357,4 +358,31 @@ impl Interface { bond_xmit_hash_policy: None, } } + + /// Setter for bridge ports (check if interface type is a bridge) + pub fn set_bridge_ports(&mut self, ports: Vec) -> Result<(), Error> { + if self.interface_type != NetworkInterfaceType::Bridge { + bail!( + "interface '{}' is no bridge (type is {:?})", + self.name, + self.interface_type + ); + } + self.bridge_ports = Some(ports); + Ok(()) + } + + /// 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 { + bail!( + "interface '{}' is no bond (type is {:?})", + self.name, + self.interface_type + ); + } + self.slaves = Some(slaves); + Ok(()) + } + }