From 1eaae2016a23b5f9b5fd2cb64ec08b2de746027b Mon Sep 17 00:00:00 2001 From: tahahawa Date: Tue, 15 Jul 2025 00:16:57 -0400 Subject: [PATCH] WIP: Create Upgradeable trait --- Cargo.lock | 1 + examples/opnsense/Cargo.toml | 1 + examples/opnsense/src/main.rs | 7 +++++-- harmony/src/domain/topology/ha_cluster.rs | 15 +++++++++++++-- harmony/src/domain/topology/mod.rs | 1 + harmony/src/domain/topology/upgradeable.rs | 8 ++++++++ harmony/src/infra/opnsense/mod.rs | 21 ++++++++++++++++++++- 7 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 harmony/src/domain/topology/upgradeable.rs diff --git a/Cargo.lock b/Cargo.lock index e19e6f3..1eb805d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1343,6 +1343,7 @@ dependencies = [ "cidr", "env_logger", "harmony", + "harmony_cli", "harmony_macros", "harmony_tui", "harmony_types", diff --git a/examples/opnsense/Cargo.toml b/examples/opnsense/Cargo.toml index 60986d3..ea291d9 100644 --- a/examples/opnsense/Cargo.toml +++ b/examples/opnsense/Cargo.toml @@ -16,3 +16,4 @@ harmony_macros = { path = "../../harmony_macros" } log = { workspace = true } env_logger = { workspace = true } url = { workspace = true } +harmony_cli = { version = "0.1.0", path = "../../harmony_cli" } diff --git a/examples/opnsense/src/main.rs b/examples/opnsense/src/main.rs index dc329b3..7f1d190 100644 --- a/examples/opnsense/src/main.rs +++ b/examples/opnsense/src/main.rs @@ -13,7 +13,7 @@ use harmony::{ dummy::{ErrorScore, PanicScore, SuccessScore}, http::StaticFilesHttpScore, okd::{dhcp::OKDDhcpScore, dns::OKDDnsScore, load_balancer::OKDLoadBalancerScore}, - opnsense::OPNsenseShellCommandScore, + opnsense::{OPNSenseLaunchUpgrade, OPNsenseShellCommandScore}, tftp::TftpScore, }, topology::{LogicalHost, UnmanagedRouter, Url}, @@ -97,9 +97,12 @@ async fn main() { opnsense: opnsense.get_opnsense_config(), command: "touch /tmp/helloharmonytouching".to_string(), }), + Box::new(OPNSenseLaunchUpgrade { + opnsense: opnsense.get_opnsense_config(), + }), Box::new(SuccessScore {}), Box::new(ErrorScore {}), Box::new(PanicScore {}), ]); - harmony_tui::init(maestro).await.unwrap(); + harmony_cli::init(maestro, None).await.unwrap(); } diff --git a/harmony/src/domain/topology/ha_cluster.rs b/harmony/src/domain/topology/ha_cluster.rs index a114e18..010f922 100644 --- a/harmony/src/domain/topology/ha_cluster.rs +++ b/harmony/src/domain/topology/ha_cluster.rs @@ -1,11 +1,14 @@ use async_trait::async_trait; use harmony_macros::ip; use harmony_types::net::MacAddress; +use log::error; use log::info; use crate::executors::ExecutorError; use crate::interpret::InterpretError; use crate::interpret::Outcome; +use crate::inventory::Inventory; +use crate::topology::upgradeable::Upgradeable; use super::DHCPStaticEntry; use super::DhcpServer; @@ -49,9 +52,10 @@ impl Topology for HAClusterTopology { "HAClusterTopology" } async fn ensure_ready(&self) -> Result { - todo!( + error!( "ensure_ready, not entirely sure what it should do here, probably something like verify that the hosts are reachable and all services are up and ready." - ) + ); + Ok(Outcome::success("for now do nothing".to_string())) } } @@ -417,3 +421,10 @@ impl DnsServer for DummyInfra { unimplemented!("{}", UNIMPLEMENTED_DUMMY_INFRA) } } + +#[async_trait] +impl Upgradeable for HAClusterTopology { + async fn upgrade(&self, inventory: &Inventory, topology: &T) -> Result<(), InterpretError> { + todo!("implement upgrades for all parts of the cluster") + } +} diff --git a/harmony/src/domain/topology/mod.rs b/harmony/src/domain/topology/mod.rs index c72a898..82e21d7 100644 --- a/harmony/src/domain/topology/mod.rs +++ b/harmony/src/domain/topology/mod.rs @@ -6,6 +6,7 @@ mod k8s_anywhere; mod localhost; pub mod oberservability; pub mod tenant; +pub mod upgradeable; pub use k8s_anywhere::*; pub use localhost::*; pub mod k8s; diff --git a/harmony/src/domain/topology/upgradeable.rs b/harmony/src/domain/topology/upgradeable.rs new file mode 100644 index 0000000..a8f9ec6 --- /dev/null +++ b/harmony/src/domain/topology/upgradeable.rs @@ -0,0 +1,8 @@ +use async_trait::async_trait; + +use crate::{interpret::InterpretError, inventory::Inventory}; + +#[async_trait] +pub trait Upgradeable: Send + Sync { + async fn upgrade(&self, inventory: &Inventory, topology: &T) -> Result<(), InterpretError>; +} diff --git a/harmony/src/infra/opnsense/mod.rs b/harmony/src/infra/opnsense/mod.rs index 0aa5532..d0a1738 100644 --- a/harmony/src/infra/opnsense/mod.rs +++ b/harmony/src/infra/opnsense/mod.rs @@ -7,13 +7,18 @@ mod management; mod tftp; use std::sync::Arc; +use async_trait::async_trait; pub use management::*; use opnsense_config_xml::Host; use tokio::sync::RwLock; use crate::{ executors::ExecutorError, - topology::{IpAddress, LogicalHost}, + interpret::InterpretError, + inventory::Inventory, + modules::opnsense::OPNSenseLaunchUpgrade, + score::Score, + topology::{IpAddress, LogicalHost, Topology, upgradeable::Upgradeable}, }; #[derive(Debug, Clone)] @@ -49,3 +54,17 @@ impl OPNSenseFirewall { .map_err(|e| ExecutorError::UnexpectedError(e.to_string())) } } + +#[async_trait] +impl Upgradeable for OPNSenseFirewall { + async fn upgrade(&self, inventory: &Inventory, topology: &T) -> Result<(), InterpretError> { + OPNSenseLaunchUpgrade { + opnsense: self.get_opnsense_config(), + } + .create_interpret() + .execute(inventory, topology) + .await?; + + Ok(()) + } +}