feat(harmony): add lamp server module and refactor dhcpd tests
Implement LAMP server module with basic configuration. Refactor and remove commented out Dhcpd struct and associated tests in opnsense/xml_utils. Ensure codebase adheres to best practices and maintainability standards.
This commit is contained in:
parent
fe42ebd347
commit
fbc18d2fad
@ -3,7 +3,7 @@ use std::sync::{Arc, RwLock};
|
|||||||
use log::info;
|
use log::info;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
interpret::{Interpret, InterpretError, Outcome},
|
interpret::{InterpretError, Outcome},
|
||||||
inventory::Inventory,
|
inventory::Inventory,
|
||||||
score::Score,
|
score::Score,
|
||||||
topology::HAClusterTopology,
|
topology::HAClusterTopology,
|
||||||
|
|||||||
@ -14,7 +14,7 @@ pub use http::*;
|
|||||||
pub use network::*;
|
pub use network::*;
|
||||||
pub use tftp::*;
|
pub use tftp::*;
|
||||||
|
|
||||||
use std::{net::IpAddr, sync::Arc};
|
use std::net::IpAddr;
|
||||||
|
|
||||||
pub type IpAddress = IpAddr;
|
pub type IpAddress = IpAddr;
|
||||||
|
|
||||||
|
|||||||
70
harmony/src/modules/lamp.rs
Normal file
70
harmony/src/modules/lamp.rs
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
use async_trait::async_trait;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
data::{Id, Version},
|
||||||
|
interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome},
|
||||||
|
inventory::Inventory,
|
||||||
|
modules::k8s::deployment::K8sDeploymentScore,
|
||||||
|
score::Score,
|
||||||
|
topology::HAClusterTopology,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct LAMPScore {
|
||||||
|
pub name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Score for LAMPScore {
|
||||||
|
fn create_interpret(&self) -> Box<dyn Interpret> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn name(&self) -> String {
|
||||||
|
"LampScore".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn clone_box(&self) -> Box<dyn Score> {
|
||||||
|
Box::new(self.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct LAMPInterpret {
|
||||||
|
score: LAMPScore,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl Interpret for LAMPInterpret {
|
||||||
|
async fn execute(
|
||||||
|
&self,
|
||||||
|
inventory: &Inventory,
|
||||||
|
topology: &HAClusterTopology,
|
||||||
|
) -> Result<Outcome, InterpretError> {
|
||||||
|
let deployment_score = K8sDeploymentScore {
|
||||||
|
name: self.score.name.clone(),
|
||||||
|
image: "local_image".to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
|
deployment_score
|
||||||
|
.create_interpret()
|
||||||
|
.execute(inventory, topology)
|
||||||
|
.await?;
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_name(&self) -> InterpretName {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_version(&self) -> Version {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_status(&self) -> InterpretStatus {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_children(&self) -> Vec<Id> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -7,3 +7,4 @@ pub mod load_balancer;
|
|||||||
pub mod okd;
|
pub mod okd;
|
||||||
pub mod opnsense;
|
pub mod opnsense;
|
||||||
pub mod tftp;
|
pub mod tftp;
|
||||||
|
pub mod lamp;
|
||||||
|
|||||||
@ -4,13 +4,6 @@ use yaserde::MaybeString;
|
|||||||
|
|
||||||
use super::opnsense::{NumberOption, Range, StaticMap};
|
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)]
|
#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
|
||||||
pub struct DhcpInterface {
|
pub struct DhcpInterface {
|
||||||
pub enable: Option<MaybeString>,
|
pub enable: Option<MaybeString>,
|
||||||
@ -42,77 +35,3 @@ pub struct DhcpRange {
|
|||||||
#[yaserde(rename = "to")]
|
#[yaserde(rename = "to")]
|
||||||
pub to: String,
|
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";
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user