src/api2/config/network.rs: implement update/delete for bridge_ports and bond_slaves
This commit is contained in:
		@ -94,8 +94,13 @@ pub enum DeletableProperty {
 | 
				
			|||||||
    mtu,
 | 
					    mtu,
 | 
				
			||||||
    /// Delete auto flag
 | 
					    /// Delete auto flag
 | 
				
			||||||
    auto,
 | 
					    auto,
 | 
				
			||||||
 | 
					    /// Delete bridge ports (set to 'none')
 | 
				
			||||||
 | 
					    bridge_ports,
 | 
				
			||||||
 | 
					    /// Delete bond-slaves (set to 'none')
 | 
				
			||||||
 | 
					    bond_slaves,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[api(
 | 
					#[api(
 | 
				
			||||||
    protected: true,
 | 
					    protected: true,
 | 
				
			||||||
    input: {
 | 
					    input: {
 | 
				
			||||||
@ -131,6 +136,14 @@ pub enum DeletableProperty {
 | 
				
			|||||||
                maximum: 65535,
 | 
					                maximum: 65535,
 | 
				
			||||||
                default: 1500,
 | 
					                default: 1500,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
 | 
					            bridge_ports: {
 | 
				
			||||||
 | 
					                schema: NETWORK_INTERFACE_LIST_SCHEMA,
 | 
				
			||||||
 | 
					                optional: true,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            bond_slaves: {
 | 
				
			||||||
 | 
					                schema: NETWORK_INTERFACE_LIST_SCHEMA,
 | 
				
			||||||
 | 
					                optional: true,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
            delete: {
 | 
					            delete: {
 | 
				
			||||||
                description: "List of properties to delete.",
 | 
					                description: "List of properties to delete.",
 | 
				
			||||||
                type: Array,
 | 
					                type: Array,
 | 
				
			||||||
@ -158,6 +171,8 @@ pub fn update_interface(
 | 
				
			|||||||
    address: Option<String>,
 | 
					    address: Option<String>,
 | 
				
			||||||
    gateway: Option<String>,
 | 
					    gateway: Option<String>,
 | 
				
			||||||
    mtu: Option<u64>,
 | 
					    mtu: Option<u64>,
 | 
				
			||||||
 | 
					    bridge_ports: Option<Vec<String>>,
 | 
				
			||||||
 | 
					    bond_slaves: Option<Vec<String>>,
 | 
				
			||||||
    delete: Option<Vec<DeletableProperty>>,
 | 
					    delete: Option<Vec<DeletableProperty>>,
 | 
				
			||||||
    digest: Option<String>,
 | 
					    digest: Option<String>,
 | 
				
			||||||
) -> Result<(), Error> {
 | 
					) -> Result<(), Error> {
 | 
				
			||||||
@ -182,8 +197,8 @@ pub fn update_interface(
 | 
				
			|||||||
    let interface = config.lookup_mut(&name)?;
 | 
					    let interface = config.lookup_mut(&name)?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if let Some(delete) = delete {
 | 
					    if let Some(delete) = delete {
 | 
				
			||||||
        for name in delete {
 | 
					        for delete_prop in delete {
 | 
				
			||||||
            match name {
 | 
					            match delete_prop {
 | 
				
			||||||
                DeletableProperty::address_v4 => { interface.cidr_v4 = None; },
 | 
					                DeletableProperty::address_v4 => { interface.cidr_v4 = None; },
 | 
				
			||||||
                DeletableProperty::address_v6 => { interface.cidr_v6 = None; },
 | 
					                DeletableProperty::address_v6 => { interface.cidr_v6 = None; },
 | 
				
			||||||
                DeletableProperty::gateway_v4 => { interface.gateway_v4 = None; },
 | 
					                DeletableProperty::gateway_v4 => { interface.gateway_v4 = None; },
 | 
				
			||||||
@ -192,6 +207,8 @@ pub fn update_interface(
 | 
				
			|||||||
                DeletableProperty::method_v6 => { interface.method_v6 = None; },
 | 
					                DeletableProperty::method_v6 => { interface.method_v6 = None; },
 | 
				
			||||||
                DeletableProperty::mtu => { interface.mtu = None; },
 | 
					                DeletableProperty::mtu => { interface.mtu = None; },
 | 
				
			||||||
                DeletableProperty::auto => { interface.auto = false; },
 | 
					                DeletableProperty::auto => { interface.auto = false; },
 | 
				
			||||||
 | 
					                DeletableProperty::bridge_ports => { interface.set_bridge_ports(Vec::new())?; }
 | 
				
			||||||
 | 
					                DeletableProperty::bond_slaves => { interface.set_bond_slaves(Vec::new())?; }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -200,6 +217,8 @@ pub fn update_interface(
 | 
				
			|||||||
    if method_v4.is_some() { interface.method_v4 = method_v4; }
 | 
					    if method_v4.is_some() { interface.method_v4 = method_v4; }
 | 
				
			||||||
    if method_v6.is_some() { interface.method_v6 = method_v6; }
 | 
					    if method_v6.is_some() { interface.method_v6 = method_v6; }
 | 
				
			||||||
    if mtu.is_some() { interface.mtu = mtu; }
 | 
					    if mtu.is_some() { interface.mtu = mtu; }
 | 
				
			||||||
 | 
					    if let Some(ports) = bridge_ports { interface.set_bridge_ports(ports)?; }
 | 
				
			||||||
 | 
					    if let Some(slaves) = bond_slaves { interface.set_bond_slaves(slaves)?; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if let Some(address) = address {
 | 
					    if let Some(address) = address {
 | 
				
			||||||
        let (_, _, is_v6) = network::parse_cidr(&address)?;
 | 
					        let (_, _, is_v6) = network::parse_cidr(&address)?;
 | 
				
			||||||
 | 
				
			|||||||
@ -101,6 +101,22 @@ impl Interface {
 | 
				
			|||||||
        Ok(())
 | 
					        Ok(())
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pub(crate) fn set_bridge_ports(&mut self, ports: Vec<String>) -> 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(())
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pub(crate) fn set_bond_slaves(&mut self, slaves: Vec<String>) -> Result<(), Error> {
 | 
				
			||||||
 | 
					        if self.interface_type != NetworkInterfaceType::Bond {
 | 
				
			||||||
 | 
					            bail!("interface '{}' is no bond (type is {:?})", self.name, self.interface_type);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        self.bond_slaves = Some(slaves);
 | 
				
			||||||
 | 
					        Ok(())
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn push_addon_option(&mut self, text: String) {
 | 
					    fn push_addon_option(&mut self, text: String) {
 | 
				
			||||||
        if self.method_v4.is_none() && self.method_v6.is_some() {
 | 
					        if self.method_v4.is_none() && self.method_v6.is_some() {
 | 
				
			||||||
            self.options_v6.push(text);
 | 
					            self.options_v6.push(text);
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user