From 1e1aa53eaaffae1e86df496690d73e2a99571c91 Mon Sep 17 00:00:00 2001 From: jeangab Date: Mon, 23 Sep 2024 00:30:27 -0400 Subject: [PATCH 1/2] feat: Significant refactoring to introduce the HostBinding struct that has for sole purpose to bind a PhysicalHost and LogicalHost together. The PhysicalHost contains everything hardware up to the mac address, LogicalHost ip address, name and above --- harmony-rs/README.md | 7 ++ .../harmony/src/domain/executors/mod.rs | 7 +- harmony-rs/harmony/src/domain/hardware/mod.rs | 53 ++++++++- .../harmony/src/domain/interpret/mod.rs | 21 +++- .../harmony/src/domain/inventory/mod.rs | 6 +- harmony-rs/harmony/src/domain/maestro/mod.rs | 24 ++-- harmony-rs/harmony/src/domain/score.rs | 1 - .../src/domain/topology/host_binding.rs | 17 +++ .../src/domain/topology/load_balancer.rs | 5 +- harmony-rs/harmony/src/domain/topology/mod.rs | 41 +++---- .../harmony/src/domain/topology/network.rs | 31 ++++- .../harmony/src/domain/topology/router.rs | 15 ++- .../ansible/opnsense_dhcp_configuration.rs | 0 .../harmony/src/infra/executors/boot/mod.rs | 0 harmony-rs/harmony/src/infra/executors/mod.rs | 1 - .../harmony/src/infra/executors/russh/mod.rs | 25 +++- harmony-rs/harmony/src/infra/hp_ilo/mod.rs | 11 +- harmony-rs/harmony/src/infra/intel_amt/mod.rs | 14 ++- harmony-rs/harmony/src/infra/mod.rs | 4 +- .../harmony/src/infra/opnsense/management.rs | 22 ++++ harmony-rs/harmony/src/infra/opnsense/mod.rs | 62 ++++++++-- .../harmony/src/modules/opnsense_dhcp.rs | 109 +++++++++++++----- 22 files changed, 352 insertions(+), 124 deletions(-) create mode 100644 harmony-rs/README.md create mode 100644 harmony-rs/harmony/src/domain/topology/host_binding.rs delete mode 100644 harmony-rs/harmony/src/infra/executors/ansible/opnsense_dhcp_configuration.rs delete mode 100644 harmony-rs/harmony/src/infra/executors/boot/mod.rs create mode 100644 harmony-rs/harmony/src/infra/opnsense/management.rs diff --git a/harmony-rs/README.md b/harmony-rs/README.md new file mode 100644 index 0000000..83bab1a --- /dev/null +++ b/harmony-rs/README.md @@ -0,0 +1,7 @@ +Due to the current setup being a mix of separate repositories with gitignore and rust workspace, a few options are required for cargo-watch to have the desired behavior : + +```sh +RUST_LOG=info cargo watch --ignore-nothing -w harmony -w private_repos/ -x 'run --bin nationtech' +``` + +This will run the nationtech bin (likely `private_repos/nationtech/src/main.rs`) on any change in the harmony or private_repos folders. diff --git a/harmony-rs/harmony/src/domain/executors/mod.rs b/harmony-rs/harmony/src/domain/executors/mod.rs index 9e991cb..e7ca378 100644 --- a/harmony-rs/harmony/src/domain/executors/mod.rs +++ b/harmony-rs/harmony/src/domain/executors/mod.rs @@ -31,5 +31,10 @@ impl std::error::Error for ExecutorError {} #[async_trait] pub trait SshClient { - async fn test_connection(&self, address: IpAddress, username: &str, password: &str) -> Result<(), ExecutorError>; + async fn test_connection( + &self, + address: IpAddress, + username: &str, + password: &str, + ) -> Result<(), ExecutorError>; } diff --git a/harmony-rs/harmony/src/domain/hardware/mod.rs b/harmony-rs/harmony/src/domain/hardware/mod.rs index 2a1fdb4..985e16e 100644 --- a/harmony-rs/harmony/src/domain/hardware/mod.rs +++ b/harmony-rs/harmony/src/domain/hardware/mod.rs @@ -1,25 +1,68 @@ +use std::sync::Arc; + use derive_new::new; -pub type HostGroup = Vec; +use crate::topology::MacAddress; + +pub type HostGroup = Vec; pub type SwitchGroup = Vec; -pub type FirewallGroup = Vec; +pub type FirewallGroup = Vec; #[derive(Debug, Clone)] -pub struct Host { +pub struct PhysicalHost { pub category: HostCategory, pub network: Vec, + pub management: Arc, pub storage: Vec, pub labels: Vec