diff --git a/Cargo.lock b/Cargo.lock index d6d78d8..fb8f3a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -815,6 +815,21 @@ dependencies = [ "url", ] +[[package]] +name = "example-nanodc" +version = "0.1.0" +dependencies = [ + "cidr", + "env_logger", + "harmony", + "harmony_macros", + "harmony_tui", + "harmony_types", + "log", + "tokio", + "url", +] + [[package]] name = "example-opnsense" version = "0.1.0" diff --git a/README.md b/README.md index 83bab1a..277356d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +### Watch the whole repo on every change + 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 diff --git a/adr/002-hexagonal-architecture.md b/adr/002-hexagonal-architecture.md index 6436d12..dffbc1b 100644 --- a/adr/002-hexagonal-architecture.md +++ b/adr/002-hexagonal-architecture.md @@ -17,9 +17,9 @@ We have decided to adopt Hexagonal Architecture (also known as Ports and Adapter 2. Flexibility: The ports and adapters model allows us to easily swap or add new implementations for different hardware or protocols without affecting the core logic. -3. Testability: The architecture facilitates easier testing by allowing us to mock external dependencies through port interfaces. +3. Testability: The architecture facilitates easier testing by allowing us to mock external dependencies through port interfaces or virtualization. -4. Alignment with Project Requirements: The structure aligns well with our need to interact with various external systems (IPMI, Redfish, AMT, etc.) and our plan to use event-driven patterns with NATS. +4. Alignment with Project Requirements: The structure aligns well with our need to interact with various external systems (IPMI, Redfish, AMT, etc.) and our plan to use event-driven patterns with eg. NATS. 5. Future-proofing: As we plan to expand into day 2 operations and policy management, Hexagonal Architecture provides a clear path for growth without compromising existing structure. diff --git a/adr/003-infrastructure-abstractions.md b/adr/003-infrastructure-abstractions.md index 84f4f3a..3d01531 100644 --- a/adr/003-infrastructure-abstractions.md +++ b/adr/003-infrastructure-abstractions.md @@ -1,5 +1,7 @@ **Architecture Decision Record: Harmony Infrastructure Abstractions** +**Status**: Proposed + **Context**: Harmony is an infrastructure orchestrator written in pure Rust, aiming to provide real portability of automation across different cloud providers and infrastructure setups. To achieve this, we need to define infrastructure abstractions that are provider-agnostic and flexible enough to accommodate various use cases. **Decision**: We will define our infrastructure abstractions using a domain-driven approach, focusing on the core logic of Harmony. These abstractions will only include the absolutely required elements for a specific resource, without referencing specific providers or implementations. @@ -50,6 +52,5 @@ impl Database for AmazonRDS { ``` By defining our infrastructure abstractions in this way, we ensure that Harmony remains provider-agnostic and flexible enough to accommodate various use cases. This approach enables real portability of automation across different cloud providers and infrastructure setups. -**Status**: Accepted **Consequences**: This decision will lead to a more modular and flexible architecture for Harmony, allowing users to easily adopt harmony on their own infrastructure and eventually switch between different infrastructure providers and reuse their existing automation scripts. It will also simplify the development process for new features and use cases, as we can focus on implementing the core domain logic without worrying about provider-specific details. diff --git a/examples/nanodc/Cargo.toml b/examples/nanodc/Cargo.toml new file mode 100644 index 0000000..ccd3a3a --- /dev/null +++ b/examples/nanodc/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "example-nanodc" +edition = "2024" +version.workspace = true +readme.workspace = true +license.workspace = true +publish = false + +[dependencies] +harmony = { path = "../../harmony" } +harmony_tui = { path = "../../harmony_tui" } +harmony_types = { path = "../../harmony_types" } +cidr = { workspace = true } +tokio = { workspace = true } +harmony_macros = { path = "../../harmony_macros" } +log = { workspace = true } +env_logger = { workspace = true } +url = { workspace = true } diff --git a/examples/nanodc/src/main.rs b/examples/nanodc/src/main.rs new file mode 100644 index 0000000..3a683d0 --- /dev/null +++ b/examples/nanodc/src/main.rs @@ -0,0 +1,20 @@ +use harmony::{ + inventory::Inventory, + maestro::Maestro, + modules::{dummy::{ErrorScore, PanicScore, SuccessScore}, k8s::deployment::K8sDeploymentScore}, + topology::HAClusterTopology, +}; + +#[tokio::main] +async fn main() { + let inventory = Inventory::autoload(); + let topology = HAClusterTopology::autoload(); + let mut maestro = Maestro::new(inventory, topology); + + maestro.register_all(vec![ + Box::new(SuccessScore {}), + Box::new(ErrorScore {}), + Box::new(PanicScore {}), + ]); + harmony_tui::init(maestro).await.unwrap(); +} diff --git a/examples/opnsense/src/main.rs b/examples/opnsense/src/main.rs index fac1080..6315390 100644 --- a/examples/opnsense/src/main.rs +++ b/examples/opnsense/src/main.rs @@ -13,7 +13,7 @@ use harmony::{ dummy::{ErrorScore, PanicScore, SuccessScore}, http::HttpScore, okd::{dhcp::OKDDhcpScore, dns::OKDDnsScore}, - opnsense::OPNSenseShellCommandScore, + opnsense::OPNsenseShellCommandScore, tftp::TftpScore, }, topology::{LogicalHost, UnmanagedRouter, Url}, @@ -92,7 +92,7 @@ async fn main() { Box::new(load_balancer_score), Box::new(tftp_score), Box::new(http_score), - Box::new(OPNSenseShellCommandScore { + Box::new(OPNsenseShellCommandScore { opnsense: opnsense.get_opnsense_config(), command: "touch /tmp/helloharmonytouching".to_string(), }), diff --git a/harmony-rs/.gitignore b/harmony-rs/.gitignore deleted file mode 100644 index c607ca7..0000000 --- a/harmony-rs/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -target -private_repos diff --git a/harmony/src/modules/opnsense/mod.rs b/harmony/src/modules/opnsense/mod.rs new file mode 100644 index 0000000..763195d --- /dev/null +++ b/harmony/src/modules/opnsense/mod.rs @@ -0,0 +1,6 @@ + +mod shell; +mod upgrade; +pub use shell::*; +pub use upgrade::*; + diff --git a/harmony/src/modules/opnsense.rs b/harmony/src/modules/opnsense/shell.rs similarity index 85% rename from harmony/src/modules/opnsense.rs rename to harmony/src/modules/opnsense/shell.rs index 9ed1c2e..00fd131 100644 --- a/harmony/src/modules/opnsense.rs +++ b/harmony/src/modules/opnsense/shell.rs @@ -12,14 +12,14 @@ use crate::{ }; #[derive(Debug, Clone)] -pub struct OPNSenseShellCommandScore { +pub struct OPNsenseShellCommandScore { pub opnsense: Arc>, pub command: String, } -impl Score for OPNSenseShellCommandScore { +impl Score for OPNsenseShellCommandScore { fn create_interpret(&self) -> Box { - Box::new(OPNsenseInterpret { + Box::new(OPNsenseShellInterpret { status: InterpretStatus::QUEUED, score: self.clone(), }) @@ -35,13 +35,13 @@ impl Score for OPNSenseShellCommandScore { } #[derive(Debug)] -pub struct OPNsenseInterpret { - status: InterpretStatus, - score: OPNSenseShellCommandScore, +pub struct OPNsenseShellInterpret { + pub status: InterpretStatus, + pub score: OPNsenseShellCommandScore, } #[async_trait] -impl Interpret for OPNsenseInterpret { +impl Interpret for OPNsenseShellInterpret { async fn execute( &self, _inventory: &Inventory, diff --git a/harmony/src/modules/opnsense/upgrade.rs b/harmony/src/modules/opnsense/upgrade.rs new file mode 100644 index 0000000..6b0637d --- /dev/null +++ b/harmony/src/modules/opnsense/upgrade.rs @@ -0,0 +1,37 @@ +use std::sync::Arc; + +use tokio::sync::RwLock; + +use crate::{ + interpret::{Interpret, InterpretStatus}, + score::Score, +}; + +use super::{OPNsenseShellCommandScore, OPNsenseShellInterpret}; + +#[derive(Debug, Clone)] +pub struct OPNSenseLaunchUpgrade { + pub opnsense: Arc>, +} + +impl Score for OPNSenseLaunchUpgrade { + fn create_interpret(&self) -> Box { + let score = OPNsenseShellCommandScore { + opnsense: self.opnsense.clone(), + command: "/usr/local/opnsense/scripts/firmware/update.sh".to_string(), + }; + + Box::new(OPNsenseShellInterpret { + status: InterpretStatus::QUEUED, + score, + }) + } + + fn name(&self) -> String { + "OPNSenseLaunchUpgrade".to_string() + } + + fn clone_box(&self) -> Box { + Box::new(self.clone()) + } +}