From c8547e38f21368df9c4742bf3ac93d4835ff1e83 Mon Sep 17 00:00:00 2001 From: Sylvain Tremblay Date: Sun, 2 Mar 2025 12:14:04 -0500 Subject: [PATCH] feat(ipxe): create empty score shell for ipxe --- data/watchguard/pxe-http-files/.gitattributes | 1 + examples/nanodc/src/main.rs | 4 +- harmony/src/domain/interpret/mod.rs | 2 + harmony/src/modules/ipxe.rs | 74 +++++++++++++++++++ harmony/src/modules/mod.rs | 1 + 5 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 data/watchguard/pxe-http-files/.gitattributes create mode 100644 harmony/src/modules/ipxe.rs diff --git a/data/watchguard/pxe-http-files/.gitattributes b/data/watchguard/pxe-http-files/.gitattributes new file mode 100644 index 0000000..b503bee --- /dev/null +++ b/data/watchguard/pxe-http-files/.gitattributes @@ -0,0 +1 @@ +slitaz/* filter=lfs diff=lfs merge=lfs -text diff --git a/examples/nanodc/src/main.rs b/examples/nanodc/src/main.rs index 4ed5ea0..c51700a 100644 --- a/examples/nanodc/src/main.rs +++ b/examples/nanodc/src/main.rs @@ -10,7 +10,7 @@ use harmony::{ inventory::Inventory, maestro::Maestro, modules::{ - http::HttpScore, okd::{dhcp::OKDDhcpScore, dns::OKDDnsScore}, opnsense::OPNSenseLaunchUpgrade, tftp::TftpScore + http::HttpScore, okd::{dhcp::OKDDhcpScore, dns::OKDDnsScore}, opnsense::OPNSenseLaunchUpgrade, tftp::TftpScore, ipxe::IpxeScore }, topology::{LogicalHost, UnmanagedRouter, Url}, }; @@ -96,6 +96,7 @@ async fn main() { let http_score = HttpScore::new(Url::LocalFolder( "./data/watchguard/pxe-http-files".to_string(), )); + let ipxe_score = IpxeScore::new(); let mut maestro = Maestro::new(inventory, topology); maestro.register_all(vec![ Box::new(dns_score), @@ -103,6 +104,7 @@ async fn main() { Box::new(load_balancer_score), Box::new(tftp_score), Box::new(http_score), + Box::new(ipxe_score), ]); harmony_tui::init(maestro).await.unwrap(); } diff --git a/harmony/src/domain/interpret/mod.rs b/harmony/src/domain/interpret/mod.rs index 731d663..565b125 100644 --- a/harmony/src/domain/interpret/mod.rs +++ b/harmony/src/domain/interpret/mod.rs @@ -16,6 +16,7 @@ pub enum InterpretName { LoadBalancer, Tftp, Http, + Ipxe, Dummy, Panic, OPNSense, @@ -29,6 +30,7 @@ impl std::fmt::Display for InterpretName { InterpretName::LoadBalancer => f.write_str("LoadBalancer"), InterpretName::Tftp => f.write_str("Tftp"), InterpretName::Http => f.write_str("Http"), + InterpretName::Ipxe => f.write_str("iPXE"), InterpretName::Dummy => f.write_str("Dummy"), InterpretName::Panic => f.write_str("Panic"), InterpretName::OPNSense => f.write_str("OPNSense"), diff --git a/harmony/src/modules/ipxe.rs b/harmony/src/modules/ipxe.rs new file mode 100644 index 0000000..03e0140 --- /dev/null +++ b/harmony/src/modules/ipxe.rs @@ -0,0 +1,74 @@ +use async_trait::async_trait; +use derive_new::new; + +use crate::{ + data::{Id, Version}, + interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, + inventory::Inventory, + score::Score, + topology::HAClusterTopology, +}; + +#[derive(Debug, new, Clone)] +pub struct IpxeScore { + //files_to_serve: Url, +} + +impl Score for IpxeScore { + fn create_interpret(&self) -> Box { + Box::new(IpxeInterpret::new(self.clone())) + } + + fn name(&self) -> String { + "IpxeScore".to_string() + } + + fn clone_box(&self) -> Box { + Box::new(self.clone()) + } +} + +#[derive(Debug, new, Clone)] +pub struct IpxeInterpret { + score: IpxeScore, +} + +#[async_trait] +impl Interpret for IpxeInterpret { + async fn execute( + &self, + _inventory: &Inventory, + _topology: &HAClusterTopology, + ) -> Result { + /* + let http_server = &topology.http_server; + http_server.ensure_initialized().await?; + Ok(Outcome::success(format!( + "Http Server running and serving files from {}", + self.score.files_to_serve + ))) + */ + + Ok(Outcome::success(format!( + "Success running {}", + self.score.name() + ))) + //Ok(Outcome::success("Success".to_string())) + } + + fn get_name(&self) -> InterpretName { + InterpretName::Ipxe + } + + fn get_version(&self) -> Version { + todo!() + } + + fn get_status(&self) -> InterpretStatus { + todo!() + } + + fn get_children(&self) -> Vec { + todo!() + } +} diff --git a/harmony/src/modules/mod.rs b/harmony/src/modules/mod.rs index c181375..250f0f0 100644 --- a/harmony/src/modules/mod.rs +++ b/harmony/src/modules/mod.rs @@ -7,3 +7,4 @@ pub mod load_balancer; pub mod okd; pub mod opnsense; pub mod tftp; +pub mod ipxe;