From 3eac78c6d3e6c3371ab3e891ee0e906b6c37eebb Mon Sep 17 00:00:00 2001 From: Jean-Gabriel Gill-Couture Date: Sat, 1 Feb 2025 11:45:04 -0500 Subject: [PATCH] feat(harmony): enhance PhysicalHost with builder methods and update dependencies - Added builder methods to `PhysicalHost` for configuring CPU, memory size, storage, MAC address, labels, and management interface. - Updated the edition of various Cargo.toml files to 2024. - Implemented workspace inheritance for version, readme, and license fields in Cargo.toml files. --- harmony-rs/Cargo.lock | 66 ++++++++++--------- harmony-rs/Cargo.toml | 6 +- .../{demo => examples}/kube-rs/Cargo.toml | 5 +- .../{demo => examples}/kube-rs/src/main.rs | 0 .../opnsense}/Cargo.toml | 9 ++- .../opnsense}/README.md | 3 +- .../opnsense}/src/main.rs | 39 +++++------ harmony-rs/harmony/Cargo.toml | 6 +- harmony-rs/harmony/src/domain/hardware/mod.rs | 58 +++++++++++++++- harmony-rs/harmony_macros/Cargo.toml | 4 +- harmony-rs/harmony_tui/Cargo.toml | 6 +- harmony-rs/harmony_types/Cargo.toml | 4 +- 12 files changed, 132 insertions(+), 74 deletions(-) rename harmony-rs/{demo => examples}/kube-rs/Cargo.toml (82%) rename harmony-rs/{demo => examples}/kube-rs/src/main.rs (100%) rename harmony-rs/{demo/vbox-opnsense => examples/opnsense}/Cargo.toml (53%) rename harmony-rs/{demo/vbox-opnsense => examples/opnsense}/README.md (89%) rename harmony-rs/{demo/vbox-opnsense => examples/opnsense}/src/main.rs (71%) diff --git a/harmony-rs/Cargo.lock b/harmony-rs/Cargo.lock index 7f255e4..cbd67e0 100644 --- a/harmony-rs/Cargo.lock +++ b/harmony-rs/Cargo.lock @@ -794,6 +794,38 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "example-kube-rs" +version = "0.1.0" +dependencies = [ + "cidr", + "env_logger", + "harmony", + "harmony_macros", + "http 1.2.0", + "k8s-openapi", + "kube", + "log", + "serde_yaml", + "tokio", + "url", +] + +[[package]] +name = "example-opnsense" +version = "0.1.0" +dependencies = [ + "cidr", + "env_logger", + "harmony", + "harmony_macros", + "harmony_tui", + "harmony_types", + "log", + "tokio", + "url", +] + [[package]] name = "eyre" version = "0.6.12" @@ -1101,7 +1133,7 @@ dependencies = [ [[package]] name = "harmony_macros" -version = "1.0.0" +version = "0.1.0" dependencies = [ "harmony_types", "quote", @@ -1127,7 +1159,7 @@ dependencies = [ [[package]] name = "harmony_types" -version = "1.0.0" +version = "0.1.0" [[package]] name = "hashbrown" @@ -3282,23 +3314,6 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "test-kube-rs" -version = "0.1.0" -dependencies = [ - "cidr", - "env_logger", - "harmony", - "harmony_macros", - "http 1.2.0", - "k8s-openapi", - "kube", - "log", - "serde_yaml", - "tokio", - "url", -] - [[package]] name = "thiserror" version = "1.0.63" @@ -3687,19 +3702,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" -[[package]] -name = "vbox-opnpsense" -version = "0.1.0" -dependencies = [ - "cidr", - "env_logger", - "harmony", - "harmony_macros", - "log", - "tokio", - "url", -] - [[package]] name = "vcpkg" version = "0.2.15" diff --git a/harmony-rs/Cargo.toml b/harmony-rs/Cargo.toml index 4a43c1b..8c7afdd 100644 --- a/harmony-rs/Cargo.toml +++ b/harmony-rs/Cargo.toml @@ -2,7 +2,7 @@ resolver = "2" members = [ "private_repos/*", - "demo/*", + "examples/*", "harmony", "harmony_types", "harmony_macros", @@ -39,7 +39,3 @@ features = [ "fast-rng", # Use a faster (but still sufficiently random) RNG "macro-diagnostics", # Enable better diagnostics for compile-time UUIDs ] - - -#[workspace.target.x86_64-unknown-linux-gnu] -#rustflags = ["-C", "link-arg=-fuse-ld=mold"] diff --git a/harmony-rs/demo/kube-rs/Cargo.toml b/harmony-rs/examples/kube-rs/Cargo.toml similarity index 82% rename from harmony-rs/demo/kube-rs/Cargo.toml rename to harmony-rs/examples/kube-rs/Cargo.toml index f53b80b..a4d7651 100644 --- a/harmony-rs/demo/kube-rs/Cargo.toml +++ b/harmony-rs/examples/kube-rs/Cargo.toml @@ -1,15 +1,16 @@ [package] -name = "test-kube-rs" +name = "example-kube-rs" edition = "2024" version.workspace = true readme.workspace = true license.workspace = true +publish = false [dependencies] harmony = { version = "0.1.0", path = "../../harmony" } cidr = { workspace = true } tokio = { workspace = true } -harmony_macros = { version = "1.0.0", path = "../../harmony_macros" } +harmony_macros = { path = "../../harmony_macros" } log = { workspace = true } env_logger = { workspace = true } url = { workspace = true } diff --git a/harmony-rs/demo/kube-rs/src/main.rs b/harmony-rs/examples/kube-rs/src/main.rs similarity index 100% rename from harmony-rs/demo/kube-rs/src/main.rs rename to harmony-rs/examples/kube-rs/src/main.rs diff --git a/harmony-rs/demo/vbox-opnsense/Cargo.toml b/harmony-rs/examples/opnsense/Cargo.toml similarity index 53% rename from harmony-rs/demo/vbox-opnsense/Cargo.toml rename to harmony-rs/examples/opnsense/Cargo.toml index 332ad11..60986d3 100644 --- a/harmony-rs/demo/vbox-opnsense/Cargo.toml +++ b/harmony-rs/examples/opnsense/Cargo.toml @@ -1,15 +1,18 @@ [package] -name = "vbox-opnpsense" +name = "example-opnsense" edition = "2024" version.workspace = true readme.workspace = true license.workspace = true +publish = false [dependencies] -harmony = { version = "0.1.0", path = "../../harmony" } +harmony = { path = "../../harmony" } +harmony_tui = { path = "../../harmony_tui" } +harmony_types = { path = "../../harmony_types" } cidr = { workspace = true } tokio = { workspace = true } -harmony_macros = { version = "1.0.0", path = "../../harmony_macros" } +harmony_macros = { path = "../../harmony_macros" } log = { workspace = true } env_logger = { workspace = true } url = { workspace = true } diff --git a/harmony-rs/demo/vbox-opnsense/README.md b/harmony-rs/examples/opnsense/README.md similarity index 89% rename from harmony-rs/demo/vbox-opnsense/README.md rename to harmony-rs/examples/opnsense/README.md index 596c16b..a2a7a1a 100644 --- a/harmony-rs/demo/vbox-opnsense/README.md +++ b/harmony-rs/examples/opnsense/README.md @@ -11,6 +11,5 @@ Credentials are opnsense default (root/opnsense) Run the project with the correct ip address on the command line : ```bash -cd demo/vbox-opnsense/ -cargo run 192.168.5.229 +cargo run -p example-opnsense -- 192.168.5.229 ``` diff --git a/harmony-rs/demo/vbox-opnsense/src/main.rs b/harmony-rs/examples/opnsense/src/main.rs similarity index 71% rename from harmony-rs/demo/vbox-opnsense/src/main.rs rename to harmony-rs/examples/opnsense/src/main.rs index 1f903cb..c9b47eb 100644 --- a/harmony-rs/demo/vbox-opnsense/src/main.rs +++ b/harmony-rs/examples/opnsense/src/main.rs @@ -16,11 +16,10 @@ use harmony::{ }, topology::{LogicalHost, UnmanagedRouter, Url}, }; -use harmony_macros::ip; +use harmony_macros::{ip, mac_address}; #[tokio::main] async fn main() { - env_logger::init(); let firewall = harmony::topology::LogicalHost { ip: ip!("192.168.5.229"), @@ -63,34 +62,32 @@ async fn main() { "wk".to_string(), ), switch: SwitchGroup::from([]), - firewall: FirewallGroup::from([PhysicalHost { - category: HostCategory::Firewall, - network: vec![], - management: Arc::new(OPNSenseManagementInterface::new()), - storage: vec![], - labels: vec![], - }]), - worker_host: vec![], + firewall: FirewallGroup::from([PhysicalHost::empty(HostCategory::Firewall) + .management(Arc::new(OPNSenseManagementInterface::new()))]), storage_host: vec![], - control_plane_host: vec![], + worker_host: vec![], + control_plane_host: vec![PhysicalHost::empty(HostCategory::Server).mac_address(mac_address!("08:00:27:62:EC:C3"))], }; // TODO regroup smaller scores in a larger one such as this // let okd_boostrap_preparation(); - // let dhcp_score = OKDDhcpScore::new(&topology, &inventory); - // let dns_score = OKDDnsScore::new(&topology); - // let load_balancer_score = - // harmony::modules::okd::load_balancer::OKDLoadBalancerScore::new(&topology); + let dhcp_score = OKDDhcpScore::new(&topology, &inventory); + let dns_score = OKDDnsScore::new(&topology); + let load_balancer_score = + harmony::modules::okd::load_balancer::OKDLoadBalancerScore::new(&topology); let tftp_score = TftpScore::new(Url::LocalFolder("../../../watchguard/tftpboot".to_string())); let http_score = HttpScore::new(Url::LocalFolder( "../../../watchguard/pxe-http-files".to_string(), )); - let maestro = Maestro::new(inventory, topology); - // maestro.interpret(dns_score).await.unwrap(); - // maestro.interpret(dhcp_score).await.unwrap(); - // maestro.interpret(load_balancer_score).await.unwrap(); - // maestro.interpret(tftp_score).await.unwrap(); - maestro.interpret(&http_score).await.unwrap(); + let mut maestro = Maestro::new(inventory, topology); + maestro.register_all(vec![ + Box::new(dns_score), + Box::new(dhcp_score), + Box::new(load_balancer_score), + Box::new(tftp_score), + Box::new(http_score), + ]); + harmony_tui::init(maestro).await.unwrap(); } diff --git a/harmony-rs/harmony/Cargo.toml b/harmony-rs/harmony/Cargo.toml index 8418d9e..f084af0 100644 --- a/harmony-rs/harmony/Cargo.toml +++ b/harmony-rs/harmony/Cargo.toml @@ -1,7 +1,9 @@ [package] name = "harmony" -version = "0.1.0" -edition = "2021" +edition = "2024" +version.workspace = true +readme.workspace = true +license.workspace = true [dependencies] libredfish = "0.1.1" diff --git a/harmony-rs/harmony/src/domain/hardware/mod.rs b/harmony-rs/harmony/src/domain/hardware/mod.rs index c05b288..1670fe4 100644 --- a/harmony-rs/harmony/src/domain/hardware/mod.rs +++ b/harmony-rs/harmony/src/domain/hardware/mod.rs @@ -14,16 +14,20 @@ pub struct PhysicalHost { pub management: Arc, pub storage: Vec, pub labels: Vec