From df714e216a8b2f328d6f19e785a7a285be667201 Mon Sep 17 00:00:00 2001 From: Jean-Gabriel Gill-Couture Date: Sun, 8 Sep 2024 22:42:29 -0400 Subject: [PATCH] feat: Topology, inventory, score, its all coming together and compiles. I think its very usable as a first alpha version. Game on --- harmony-rs/fqm/src/main.rs | 7 ++--- harmony-rs/fqm/src/topology.rs | 5 ++-- harmony-rs/harmony/src/domain/hardware/mod.rs | 16 +++++----- .../harmony/src/domain/interpret/mod.rs | 4 +-- harmony-rs/harmony/src/domain/maestro/mod.rs | 5 ++-- harmony-rs/harmony/src/domain/score.rs | 2 +- .../src/domain/topology/load_balancer.rs | 10 ++++++- harmony-rs/harmony/src/domain/topology/mod.rs | 30 ++++++++++++------- .../harmony/src/domain/topology/network.rs | 25 ++++++++++++++-- .../harmony/src/domain/topology/router.rs | 10 ++++++- .../harmony/src/infra/executors/russh/mod.rs | 1 - harmony-rs/harmony/src/infra/opnsense/mod.rs | 20 ++++++++++--- .../harmony/src/modules/opnsense_dhcp.rs | 18 +++++------ 13 files changed, 105 insertions(+), 48 deletions(-) diff --git a/harmony-rs/fqm/src/main.rs b/harmony-rs/fqm/src/main.rs index 26f0579..76b679a 100644 --- a/harmony-rs/fqm/src/main.rs +++ b/harmony-rs/fqm/src/main.rs @@ -1,7 +1,6 @@ use fqm::{inventory::get_inventory, topology::fqm_topology}; use harmony::{ - inventory::InventoryFilter, - maestro::Maestro, + maestro::Maestro, modules::opnsense_dhcp::OPNSenseDhcpScore, }; use log::info; @@ -12,9 +11,9 @@ async fn main() { tokio::spawn(async move { info!("FQM Harmony Starting"); - let maestro = Maestro::new(get_inventory()); let topology = fqm_topology(); - let score = OPNSenseDhcpScore::new(InventoryFilter::new(vec![])); + let maestro = Maestro::new(get_inventory(), topology.clone()); + let score = OPNSenseDhcpScore::new(topology); let result = maestro.interpret(score).await.unwrap(); info!("{result}"); }).await.unwrap(); diff --git a/harmony-rs/fqm/src/topology.rs b/harmony-rs/fqm/src/topology.rs index abcc112..520a375 100644 --- a/harmony-rs/fqm/src/topology.rs +++ b/harmony-rs/fqm/src/topology.rs @@ -1,18 +1,19 @@ use std::net::Ipv4Addr; +use std::sync::Arc; use cidr::Ipv4Cidr; use harmony::infra::opnsense::OPNSenseFirewall; use harmony::topology::{HAClusterTopology, IpAddress, UnmanagedRouter}; pub fn fqm_topology() -> HAClusterTopology { - let opnsense_firewall = Box::new(OPNSenseFirewall::new(IpAddress::V4(Ipv4Addr::new(10, 10, 8, 2)))); + let opnsense_firewall = Arc::new(OPNSenseFirewall::new(IpAddress::V4(Ipv4Addr::new(10, 10, 8, 2)))); HAClusterTopology { firewall: opnsense_firewall.clone(), control_plane: vec![], ceph_hosts: vec![], switch: vec![], - router: Box::new(UnmanagedRouter::new( + router: Arc::new(UnmanagedRouter::new( IpAddress::V4(Ipv4Addr::new(10, 10, 8, 1)), Ipv4Cidr::new(Ipv4Addr::new(10, 10, 8, 0), 22).expect("Subnet is valid"), )), diff --git a/harmony-rs/harmony/src/domain/hardware/mod.rs b/harmony-rs/harmony/src/domain/hardware/mod.rs index ef03260..4072946 100644 --- a/harmony-rs/harmony/src/domain/hardware/mod.rs +++ b/harmony-rs/harmony/src/domain/hardware/mod.rs @@ -3,7 +3,7 @@ use derive_new::new; pub type HostGroup = Vec; pub type SwitchGroup = Vec; pub type FirewallGroup = Vec; -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct Host { pub category: HostCategory, pub network: Vec, @@ -11,14 +11,14 @@ pub struct Host { pub labels: Vec