src/api2/config/network.rs: allow to update 'auto' flag

This commit is contained in:
Dietmar Maurer 2020-04-22 16:46:46 +02:00
parent 3fce3bc36e
commit f1026a5aa9
4 changed files with 14 additions and 5 deletions

View File

@ -4,7 +4,6 @@ use ::serde::{Deserialize, Serialize};
use proxmox::api::{api, ApiMethod, Router, RpcEnvironment, Permission};
//use crate::api2::types::*;
use crate::config::network;
use crate::config::acl::{PRIV_SYS_AUDIT, PRIV_SYS_MODIFY};
use crate::api2::types::*;
@ -95,6 +94,8 @@ pub enum DeletableProperty {
mtu_v4,
/// Delete mtu IPv6.
mtu_v6,
/// Delete auto flag
auto,
}
#[api(
@ -104,6 +105,11 @@ pub enum DeletableProperty {
name: {
schema: NETWORK_INTERFACE_NAME_SCHEMA,
},
auto: {
description: "Autostart interface.",
type: bool,
optional: true,
},
method_v4: {
type: NetworkConfigMethod,
optional: true,
@ -153,6 +159,7 @@ pub enum DeletableProperty {
/// Update network interface config.
pub fn update_interface(
name: String,
auto: Option<bool>,
method_v4: Option<NetworkConfigMethod>,
method_v6: Option<NetworkConfigMethod>,
address: Option<String>,
@ -185,10 +192,12 @@ pub fn update_interface(
DeletableProperty::method_v6 => { interface.method_v6 = None; },
DeletableProperty::mtu_v4 => { interface.mtu_v4 = None; },
DeletableProperty::mtu_v6 => { interface.mtu_v6 = None; },
DeletableProperty::auto => { interface.auto = false; },
}
}
}
if let Some(auto) = auto { interface.auto = auto; }
if method_v4.is_some() { interface.method_v4 = method_v4; }
if method_v6.is_some() { interface.method_v6 = method_v6; }
if mtu_v4.is_some() { interface.mtu_v4 = mtu_v4; }

View File

@ -562,7 +562,7 @@ pub const NETWORK_INTERFACE_NAME_SCHEMA: Schema = StringSchema::new("Network int
/// Network Interface configuration
pub struct Interface {
/// Autostart interface
pub autostart: bool,
pub auto: bool,
/// Interface is a physical network device
pub exists: bool,
/// Interface is active (UP)

View File

@ -21,7 +21,7 @@ impl Interface {
pub fn new(name: String) -> Self {
Self {
name,
autostart: false,
auto: false,
exists: false,
active: false,
method_v4: None,
@ -154,7 +154,7 @@ impl Interface {
if self.method_v4.is_none() && self.method_v6.is_none() { return Ok(()); }
if self.autostart {
if self.auto {
writeln!(w, "auto {}", self.name)?;
}

View File

@ -282,7 +282,7 @@ impl <R: BufRead> NetworkParser<R> {
for iface in auto_flag.iter() {
if let Some(interface) = config.interfaces.get_mut(iface) {
interface.autostart = true;
interface.auto = true;
}
}