From d9c26f43ee7f8c8a4e371b417cb1fe15f8dc20cb Mon Sep 17 00:00:00 2001 From: Jean-Gabriel Gill-Couture Date: Sun, 31 Aug 2025 00:31:55 -0400 Subject: [PATCH] wip: saving harmony inventory, currently messing with async stuff, properly understanding stuff now so I should fix it soon. The recv in the inventory agent is sync and blocking the whole thread so the request cannot be sent until the recv is killed, which is wrong. Will fix this by isolating on another thread --- examples/nanodc/src/main.rs | 3 +- examples/okd_pxe/src/topology.rs | 3 +- examples/opnsense/src/main.rs | 3 +- harmony/src/domain/config.rs | 8 + harmony/src/domain/hardware/mod.rs | 242 +++++++----------- harmony/src/domain/inventory/mod.rs | 8 +- harmony/src/infra/inventory/mod.rs | 18 +- harmony/src/modules/inventory/mod.rs | 94 +++++-- harmony_inventory_agent/src/client.rs | 7 +- harmony_inventory_agent/src/hwinfo.rs | 24 +- harmony_inventory_agent/src/lib.rs | 2 +- .../src/local_presence/discover.rs | 13 +- 12 files changed, 233 insertions(+), 192 deletions(-) diff --git a/examples/nanodc/src/main.rs b/examples/nanodc/src/main.rs index a8a17e3..a6bb8e4 100644 --- a/examples/nanodc/src/main.rs +++ b/examples/nanodc/src/main.rs @@ -87,8 +87,7 @@ async fn main() { let inventory = Inventory { location: Location::new("I am mobile".to_string(), "earth".to_string()), switch: SwitchGroup::from([]), - firewall: FirewallGroup::from([PhysicalHost::empty(HostCategory::Firewall) - .management(Arc::new(OPNSenseManagementInterface::new()))]), + firewall_mgmt: Box::new(OPNSenseManagementInterface::new()), storage_host: vec![], worker_host: vec![ PhysicalHost::empty(HostCategory::Server) diff --git a/examples/okd_pxe/src/topology.rs b/examples/okd_pxe/src/topology.rs index eb23908..27eb8c0 100644 --- a/examples/okd_pxe/src/topology.rs +++ b/examples/okd_pxe/src/topology.rs @@ -69,8 +69,7 @@ pub fn get_inventory() -> Inventory { "testopnsense".to_string(), ), switch: SwitchGroup::from([]), - firewall: FirewallGroup::from([PhysicalHost::empty(HostCategory::Firewall) - .management(Arc::new(OPNSenseManagementInterface::new()))]), + firewall_mgmt: Box::new(OPNSenseManagementInterface::new()), storage_host: vec![], worker_host: vec![], control_plane_host: vec![], diff --git a/examples/opnsense/src/main.rs b/examples/opnsense/src/main.rs index 3af30cf..465b0fa 100644 --- a/examples/opnsense/src/main.rs +++ b/examples/opnsense/src/main.rs @@ -63,8 +63,7 @@ async fn main() { "wk".to_string(), ), switch: SwitchGroup::from([]), - firewall: FirewallGroup::from([PhysicalHost::empty(HostCategory::Firewall) - .management(Arc::new(OPNSenseManagementInterface::new()))]), + firewall_mgmt: Box::new(OPNSenseManagementInterface::new()), storage_host: vec![], worker_host: vec![], control_plane_host: vec![ diff --git a/harmony/src/domain/config.rs b/harmony/src/domain/config.rs index 62f612f..1a91684 100644 --- a/harmony/src/domain/config.rs +++ b/harmony/src/domain/config.rs @@ -12,4 +12,12 @@ lazy_static! { std::env::var("HARMONY_REGISTRY_PROJECT").unwrap_or_else(|_| "harmony".to_string()); pub static ref DRY_RUN: bool = std::env::var("HARMONY_DRY_RUN").is_ok_and(|value| value.parse().unwrap_or(false)); + pub static ref DEFAULT_DATABASE_URL: String = "sqlite://harmony.sqlite".to_string(); + pub static ref DATABASE_URL: String = std::env::var("HARMONY_DATABASE_URL") + .map(|value| if value.is_empty() { + (*DEFAULT_DATABASE_URL).clone() + } else { + value + }) + .unwrap_or((*DEFAULT_DATABASE_URL).clone()); } diff --git a/harmony/src/domain/hardware/mod.rs b/harmony/src/domain/hardware/mod.rs index eb1e760..20038d2 100644 --- a/harmony/src/domain/hardware/mod.rs +++ b/harmony/src/domain/hardware/mod.rs @@ -1,25 +1,24 @@ -use std::{str::FromStr, sync::Arc}; +use std::sync::Arc; use derive_new::new; +use harmony_inventory_agent::hwinfo::{CPU, MemoryModule, NetworkInterface, StorageDrive}; use harmony_types::net::MacAddress; use serde::{Deserialize, Serialize, Serializer, ser::SerializeStruct}; use serde_value::Value; -use harmony_inventory_agent::hwinfo::NetworkInterface; pub type HostGroup = Vec; pub type SwitchGroup = Vec; pub type FirewallGroup = Vec; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize)] pub struct PhysicalHost { pub id: Id, pub category: HostCategory, pub network: Vec, - pub management: Arc, - pub storage: Vec, + pub storage: Vec, pub labels: Vec