chore: Reorganize file tree for easier onboarding. Rust project now at the root for simple git clone && cargo run
This commit is contained in:
118
opnsense-config-xml/src/data/dhcpd.rs
Normal file
118
opnsense-config-xml/src/data/dhcpd.rs
Normal file
@@ -0,0 +1,118 @@
|
||||
use yaserde_derive::{YaDeserialize, YaSerialize};
|
||||
|
||||
use yaserde::MaybeString;
|
||||
|
||||
use super::opnsense::{NumberOption, Range, StaticMap};
|
||||
|
||||
// #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
|
||||
// #[yaserde(rename = "dhcpd")]
|
||||
// pub struct Dhcpd {
|
||||
// #[yaserde(rename = "lan")]
|
||||
// pub lan: DhcpInterface,
|
||||
// }
|
||||
|
||||
#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
|
||||
pub struct DhcpInterface {
|
||||
pub enable: Option<MaybeString>,
|
||||
pub gateway: Option<MaybeString>,
|
||||
pub domain: Option<MaybeString>,
|
||||
pub tftp: Option<String>,
|
||||
pub bootfilename: Option<String>,
|
||||
pub netboot: Option<u32>,
|
||||
pub nextserver: Option<String>,
|
||||
pub filename64: Option<String>,
|
||||
#[yaserde(rename = "ddnsdomainalgorithm")]
|
||||
pub ddns_domain_algorithm: Option<MaybeString>,
|
||||
#[yaserde(rename = "numberoptions")]
|
||||
pub number_options: Vec<NumberOption>,
|
||||
#[yaserde(rename = "range")]
|
||||
pub range: Range,
|
||||
pub winsserver: Option<MaybeString>,
|
||||
pub dnsserver: Option<MaybeString>,
|
||||
pub ntpserver: Option<MaybeString>,
|
||||
#[yaserde(rename = "staticmap")]
|
||||
pub staticmaps: Vec<StaticMap>,
|
||||
pub pool: Option<MaybeString>,
|
||||
}
|
||||
|
||||
#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
|
||||
pub struct DhcpRange {
|
||||
#[yaserde(rename = "from")]
|
||||
pub from: String,
|
||||
#[yaserde(rename = "to")]
|
||||
pub to: String,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::xml_utils::to_xml_str;
|
||||
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn dhcpd_should_deserialize_serialize_identical() {
|
||||
let dhcpd: Dhcpd =
|
||||
yaserde::de::from_str(SERIALIZED_DHCPD).expect("Deserialize Dhcpd failed");
|
||||
|
||||
assert_eq!(
|
||||
to_xml_str(&dhcpd).expect("Serialize Dhcpd failed"),
|
||||
SERIALIZED_DHCPD
|
||||
);
|
||||
}
|
||||
|
||||
const SERIALIZED_DHCPD: &str = "<?xml version=\"1.0\"?>
|
||||
<dhcpd>
|
||||
<lan>
|
||||
<enable>1</enable>
|
||||
<gateway>192.168.20.1</gateway>
|
||||
<domain>somedomain.yourlocal.mcd</domain>
|
||||
<ddnsdomainalgorithm>hmac-md5</ddnsdomainalgorithm>
|
||||
<numberoptions>
|
||||
<item/>
|
||||
</numberoptions>
|
||||
<range>
|
||||
<from>192.168.20.50</from>
|
||||
<to>192.168.20.200</to>
|
||||
</range>
|
||||
<winsserver/>
|
||||
<dnsserver>192.168.20.1</dnsserver>
|
||||
<ntpserver/>
|
||||
<staticmap>
|
||||
<mac>55:55:55:55:55:1c</mac>
|
||||
<ipaddr>192.168.20.160</ipaddr>
|
||||
<hostname>somehost983</hostname>
|
||||
<descr>someservire8</descr>
|
||||
<winsserver/>
|
||||
<dnsserver/>
|
||||
<ntpserver/>
|
||||
</staticmap>
|
||||
<staticmap>
|
||||
<mac>55:55:55:55:55:1c</mac>
|
||||
<ipaddr>192.168.20.155</ipaddr>
|
||||
<hostname>somehost893</hostname>
|
||||
<winsserver/>
|
||||
<dnsserver/>
|
||||
<ntpserver/>
|
||||
</staticmap>
|
||||
<staticmap>
|
||||
<mac>55:55:55:55:55:1c</mac>
|
||||
<ipaddr>192.168.20.165</ipaddr>
|
||||
<hostname>somehost893</hostname>
|
||||
<descr/>
|
||||
<winsserver/>
|
||||
<dnsserver/>
|
||||
<ntpserver/>
|
||||
</staticmap>
|
||||
<staticmap>
|
||||
<mac>55:55:55:55:55:1c</mac>
|
||||
<ipaddr>192.168.20.50</ipaddr>
|
||||
<hostname>hostswitch2</hostname>
|
||||
<descr>switch-2 (bottom)</descr>
|
||||
<winsserver/>
|
||||
<dnsserver/>
|
||||
<ntpserver/>
|
||||
</staticmap>
|
||||
<pool/>
|
||||
</lan>
|
||||
</dhcpd>\n";
|
||||
}
|
||||
Reference in New Issue
Block a user