126 lines
3.1 KiB
Rust
126 lines
3.1 KiB
Rust
use async_trait::async_trait;
|
|
use derive_new::new;
|
|
use log::info;
|
|
|
|
use crate::{domain::{
|
|
data::{Id, Version}, hardware::NetworkInterface, interpret::{InterpretError, InterpretStatus, Outcome}, topology::IpAddress
|
|
}, executors::SshClient, infra::executors::russh::RusshClient, inventory::Inventory, topology::HAClusterTopology};
|
|
|
|
use crate::domain::{
|
|
interpret::Interpret, interpret::InterpretName, inventory::InventorySlice, score::Score,
|
|
};
|
|
|
|
use crate::domain::executors::{ExecutorError, ExecutorResult};
|
|
|
|
#[derive(Debug, new, Clone)]
|
|
pub struct OPNSenseDhcpScore {
|
|
topology: HAClusterTopology,
|
|
}
|
|
|
|
impl Score for OPNSenseDhcpScore {
|
|
type InterpretType = OPNSenseDhcpInterpret;
|
|
|
|
fn get_inventory_filter(&self) -> InventorySlice {
|
|
todo!()
|
|
}
|
|
|
|
fn create_interpret(self) -> OPNSenseDhcpInterpret {
|
|
OPNSenseDhcpInterpret::new(self)
|
|
}
|
|
}
|
|
|
|
/// https://docs.opnsense.org/manual/dhcp.html#advanced-settings
|
|
#[derive(Debug, Clone)]
|
|
pub struct OPNSenseDhcpInterpret {
|
|
score: OPNSenseDhcpScore,
|
|
version: Version,
|
|
id: Id,
|
|
name: String,
|
|
status: InterpretStatus,
|
|
}
|
|
|
|
impl OPNSenseDhcpInterpret {
|
|
pub fn new(score: OPNSenseDhcpScore) -> Self {
|
|
let version = Version::from("1.0.0").expect("Version should be valid");
|
|
let name = "OPNSenseDhcpScore".to_string();
|
|
let id = Id::from_string(format!("{name}_{version}"));
|
|
|
|
Self {
|
|
version,
|
|
id,
|
|
name,
|
|
score,
|
|
status: InterpretStatus::QUEUED,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[async_trait]
|
|
impl Interpret for OPNSenseDhcpInterpret {
|
|
fn get_name(&self) -> InterpretName {
|
|
InterpretName::OPNSenseDHCP
|
|
}
|
|
|
|
fn get_version(&self) -> crate::domain::data::Version {
|
|
self.version.clone()
|
|
}
|
|
|
|
fn get_status(&self) -> InterpretStatus {
|
|
self.status.clone()
|
|
}
|
|
|
|
fn get_children(&self) -> Vec<crate::domain::data::Id> {
|
|
todo!()
|
|
}
|
|
|
|
async fn execute(&self, inventory: &Inventory, _topology: &HAClusterTopology) -> Result<Outcome, InterpretError> {
|
|
info!("Executing {} on inventory {inventory:?}", self.get_name());
|
|
let ssh_client = RusshClient{};
|
|
|
|
info!("RusshClient initiated");
|
|
ssh_client.test_connection("paul", "paul").await?;
|
|
info!("Connection test complete");
|
|
|
|
Ok(Outcome::new(InterpretStatus::SUCCESS, "Connection test successful".to_string()))
|
|
}
|
|
}
|
|
|
|
pub trait OPNSenseDhcpConfigEditor {
|
|
fn add_static_host(
|
|
&self,
|
|
opnsense_host: IpAddress,
|
|
credentials: OPNSenseCredentials,
|
|
interface: NetworkInterface,
|
|
address: IpAddress,
|
|
) -> Result<ExecutorResult, ExecutorError>;
|
|
}
|
|
|
|
pub struct OPNSenseCredentials {
|
|
pub user: String,
|
|
pub password: String,
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod test {
|
|
|
|
#[test]
|
|
fn opnsense_dns_score_should_do_nothing_on_empty_inventory() {
|
|
todo!();
|
|
}
|
|
|
|
#[test]
|
|
fn opnsense_dns_score_should_set_entry_for_bootstrap_node() {
|
|
todo!();
|
|
}
|
|
|
|
#[test]
|
|
fn opnsense_dns_score_should_set_entry_for_control_plane_members() {
|
|
todo!();
|
|
}
|
|
|
|
#[test]
|
|
fn opnsense_dns_score_should_set_entry_for_workers() {
|
|
todo!();
|
|
}
|
|
}
|