diff --git a/harmony/src/domain/data/id.rs b/harmony/src/domain/data/id.rs index a710721..e215eb4 100644 --- a/harmony/src/domain/data/id.rs +++ b/harmony/src/domain/data/id.rs @@ -10,3 +10,9 @@ impl Id { Self { value } } } + +impl std::fmt::Display for Id { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(&self.value) + } +} diff --git a/harmony/src/domain/interpret/mod.rs b/harmony/src/domain/interpret/mod.rs index d0e00d6..5e928cb 100644 --- a/harmony/src/domain/interpret/mod.rs +++ b/harmony/src/domain/interpret/mod.rs @@ -20,6 +20,7 @@ pub enum InterpretName { Panic, OPNSense, K3dInstallation, + TenantInterpret, } impl std::fmt::Display for InterpretName { @@ -35,6 +36,7 @@ impl std::fmt::Display for InterpretName { InterpretName::Panic => f.write_str("Panic"), InterpretName::OPNSense => f.write_str("OPNSense"), InterpretName::K3dInstallation => f.write_str("K3dInstallation"), + InterpretName::TenantInterpret => f.write_str("Tenant"), } } } diff --git a/harmony/src/modules/mod.rs b/harmony/src/modules/mod.rs index 07f489e..1427515 100644 --- a/harmony/src/modules/mod.rs +++ b/harmony/src/modules/mod.rs @@ -12,4 +12,5 @@ pub mod load_balancer; pub mod monitoring; pub mod okd; pub mod opnsense; +pub mod tenant; pub mod tftp; diff --git a/harmony/src/modules/tenant/mod.rs b/harmony/src/modules/tenant/mod.rs new file mode 100644 index 0000000..5ee212c --- /dev/null +++ b/harmony/src/modules/tenant/mod.rs @@ -0,0 +1,67 @@ +use async_trait::async_trait; +use serde::Serialize; + +use crate::{ + data::{Id, Version}, + interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, + inventory::Inventory, + score::Score, + topology::{ + Topology, + tenant::{TenantConfig, TenantManager}, + }, +}; + +#[derive(Debug, Serialize, Clone)] +pub struct TenantScore { + config: TenantConfig, +} + +impl Score for TenantScore { + fn create_interpret(&self) -> Box> { + Box::new(TenantInterpret { + tenant_config: self.config.clone(), + }) + } + + fn name(&self) -> String { + format!("{} TenantScore", self.config.name) + } +} + +#[derive(Debug)] +pub struct TenantInterpret { + tenant_config: TenantConfig, +} + +#[async_trait] +impl Interpret for TenantInterpret { + async fn execute( + &self, + _inventory: &Inventory, + topology: &T, + ) -> Result { + topology.provision_tenant(&self.tenant_config).await?; + + Ok(Outcome::success(format!( + "Successfully provisioned tenant {} with id {}", + self.tenant_config.name, self.tenant_config.id + ))) + } + + fn get_name(&self) -> InterpretName { + InterpretName::TenantInterpret + } + + fn get_version(&self) -> Version { + todo!() + } + + fn get_status(&self) -> InterpretStatus { + todo!() + } + + fn get_children(&self) -> Vec { + todo!() + } +}