rename ConfigMethod to NetworkConfigMethod
This commit is contained in:
parent
ca0e534796
commit
7e02d08cd0
@ -20,7 +20,7 @@ pub use parser::*;
|
|||||||
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "lowercase")]
|
#[serde(rename_all = "lowercase")]
|
||||||
/// Interface configuration method
|
/// Interface configuration method
|
||||||
pub enum ConfigMethod {
|
pub enum NetworkConfigMethod {
|
||||||
/// Configuration is done manually using other tools
|
/// Configuration is done manually using other tools
|
||||||
Manual,
|
Manual,
|
||||||
/// Define interfaces with statically allocated addresses.
|
/// Define interfaces with statically allocated addresses.
|
||||||
@ -39,11 +39,11 @@ pub enum ConfigMethod {
|
|||||||
max_length: libc::IFNAMSIZ-1,
|
max_length: libc::IFNAMSIZ-1,
|
||||||
},
|
},
|
||||||
method_v4: {
|
method_v4: {
|
||||||
type: ConfigMethod,
|
type: NetworkConfigMethod,
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
method_v6: {
|
method_v6: {
|
||||||
type: ConfigMethod,
|
type: NetworkConfigMethod,
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
options_v4: {
|
options_v4: {
|
||||||
@ -76,9 +76,9 @@ pub struct Interface {
|
|||||||
/// Interface name
|
/// Interface name
|
||||||
pub name: String,
|
pub name: String,
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
pub method_v4: Option<ConfigMethod>,
|
pub method_v4: Option<NetworkConfigMethod>,
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
pub method_v6: Option<ConfigMethod>,
|
pub method_v6: Option<NetworkConfigMethod>,
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
/// IPv4 address
|
/// IPv4 address
|
||||||
pub address_v4: Option<String>,
|
pub address_v4: Option<String>,
|
||||||
@ -124,7 +124,7 @@ impl Interface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_method_v4(&mut self, method: ConfigMethod) -> Result<(), Error> {
|
fn set_method_v4(&mut self, method: NetworkConfigMethod) -> Result<(), Error> {
|
||||||
if self.method_v4.is_none() {
|
if self.method_v4.is_none() {
|
||||||
self.method_v4 = Some(method);
|
self.method_v4 = Some(method);
|
||||||
} else {
|
} else {
|
||||||
@ -133,7 +133,7 @@ impl Interface {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_method_v6(&mut self, method: ConfigMethod) -> Result<(), Error> {
|
fn set_method_v6(&mut self, method: NetworkConfigMethod) -> Result<(), Error> {
|
||||||
if self.method_v6.is_none() {
|
if self.method_v6.is_none() {
|
||||||
self.method_v6 = Some(method);
|
self.method_v6 = Some(method);
|
||||||
} else {
|
} else {
|
||||||
@ -250,12 +250,12 @@ impl Interface {
|
|||||||
|
|
||||||
fn write_iface(&self, w: &mut dyn Write) -> Result<(), Error> {
|
fn write_iface(&self, w: &mut dyn Write) -> Result<(), Error> {
|
||||||
|
|
||||||
fn method_to_str(method: ConfigMethod) -> &'static str {
|
fn method_to_str(method: NetworkConfigMethod) -> &'static str {
|
||||||
match method {
|
match method {
|
||||||
ConfigMethod::Static => "static",
|
NetworkConfigMethod::Static => "static",
|
||||||
ConfigMethod::Loopback => "loopback",
|
NetworkConfigMethod::Loopback => "loopback",
|
||||||
ConfigMethod::Manual => "manual",
|
NetworkConfigMethod::Manual => "manual",
|
||||||
ConfigMethod::DHCP => "dhcp",
|
NetworkConfigMethod::DHCP => "dhcp",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,7 +264,7 @@ impl Interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if self.method_v4 == self.method_v6 {
|
if self.method_v4 == self.method_v6 {
|
||||||
let method = self.method_v4.unwrap_or(ConfigMethod::Static);
|
let method = self.method_v4.unwrap_or(NetworkConfigMethod::Static);
|
||||||
writeln!(w, "iface {} {}", self.name, method_to_str(method))?;
|
writeln!(w, "iface {} {}", self.name, method_to_str(method))?;
|
||||||
self.write_iface_attributes_v4(w)?;
|
self.write_iface_attributes_v4(w)?;
|
||||||
self.write_iface_attributes_v6(w)?;
|
self.write_iface_attributes_v6(w)?;
|
||||||
|
@ -11,7 +11,7 @@ use proxmox::*; // for IP macros
|
|||||||
use super::helper::*;
|
use super::helper::*;
|
||||||
use super::lexer::*;
|
use super::lexer::*;
|
||||||
|
|
||||||
use super::{NetworkConfig, NetworkOrderEntry, Interface, ConfigMethod};
|
use super::{NetworkConfig, NetworkOrderEntry, Interface, NetworkConfigMethod};
|
||||||
|
|
||||||
pub struct NetworkParser<R: BufRead> {
|
pub struct NetworkParser<R: BufRead> {
|
||||||
input: Peekable<Lexer<R>>,
|
input: Peekable<Lexer<R>>,
|
||||||
@ -222,16 +222,16 @@ impl <R: BufRead> NetworkParser<R> {
|
|||||||
Token::Newline => break,
|
Token::Newline => break,
|
||||||
Token::Inet => address_family_v4 = true,
|
Token::Inet => address_family_v4 = true,
|
||||||
Token::Inet6 => address_family_v6 = true,
|
Token::Inet6 => address_family_v6 = true,
|
||||||
Token::Loopback => config_method = Some(ConfigMethod::Loopback),
|
Token::Loopback => config_method = Some(NetworkConfigMethod::Loopback),
|
||||||
Token::Static => config_method = Some(ConfigMethod::Static),
|
Token::Static => config_method = Some(NetworkConfigMethod::Static),
|
||||||
Token::Manual => config_method = Some(ConfigMethod::Manual),
|
Token::Manual => config_method = Some(NetworkConfigMethod::Manual),
|
||||||
Token::DHCP => config_method = Some(ConfigMethod::DHCP),
|
Token::DHCP => config_method = Some(NetworkConfigMethod::DHCP),
|
||||||
_ => bail!("unknown iface option {}", text),
|
_ => bail!("unknown iface option {}", text),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let has_attributes = self.peek()? == Token::Attribute;
|
let has_attributes = self.peek()? == Token::Attribute;
|
||||||
let config_method = config_method.unwrap_or(ConfigMethod::Static);
|
let config_method = config_method.unwrap_or(NetworkConfigMethod::Static);
|
||||||
|
|
||||||
if !(address_family_v4 || address_family_v6) {
|
if !(address_family_v4 || address_family_v6) {
|
||||||
address_family_v4 = true;
|
address_family_v4 = true;
|
||||||
@ -328,7 +328,7 @@ impl <R: BufRead> NetworkParser<R> {
|
|||||||
interface.active = *active;
|
interface.active = *active;
|
||||||
} else if exists { // also add all physical NICs
|
} else if exists { // also add all physical NICs
|
||||||
let mut interface = Interface::new(iface.clone());
|
let mut interface = Interface::new(iface.clone());
|
||||||
interface.set_method_v4(ConfigMethod::Manual)?;
|
interface.set_method_v4(NetworkConfigMethod::Manual)?;
|
||||||
interface.exists = true;
|
interface.exists = true;
|
||||||
interface.active = *active;
|
interface.active = *active;
|
||||||
config.interfaces.insert(interface.name.clone(), interface);
|
config.interfaces.insert(interface.name.clone(), interface);
|
||||||
|
Loading…
Reference in New Issue
Block a user