forked from NationTech/harmony
wip: Working hard on topology, seems to have something that may work, next step is put the building blocks together for real
This commit is contained in:
@@ -16,3 +16,4 @@ derive-new = { workspace = true }
|
||||
log = { workspace = true }
|
||||
env_logger = { workspace = true }
|
||||
async-trait = { workspace = true }
|
||||
cidr = { workspace = true }
|
||||
|
||||
@@ -2,7 +2,7 @@ use derive_new::new;
|
||||
|
||||
pub type HostGroup = Vec<Host>;
|
||||
pub type SwitchGroup = Vec<Switch>;
|
||||
pub type FirewallGroup = Vec<Firewall>;
|
||||
pub type FirewallGroup = Vec<Host>;
|
||||
#[derive(Debug)]
|
||||
pub struct Host {
|
||||
pub category: HostCategory,
|
||||
@@ -55,8 +55,6 @@ pub struct Switch {
|
||||
management_interface: NetworkInterface,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Firewall {}
|
||||
#[derive(Debug, new)]
|
||||
pub struct Label {
|
||||
name: String,
|
||||
|
||||
27
harmony-rs/harmony/src/domain/topology/load_balancer.rs
Normal file
27
harmony-rs/harmony/src/domain/topology/load_balancer.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use super::IpAddress;
|
||||
|
||||
pub trait LoadBalancer {
|
||||
fn add_backend(&mut self, backend: Backend) -> Result<(), LoadBalancerError>;
|
||||
fn remove_backend(&mut self, backend_id: &str) -> Result<(), LoadBalancerError>;
|
||||
fn add_frontend(&mut self, frontend: Frontend) -> Result<(), LoadBalancerError>;
|
||||
fn remove_frontend(&mut self, frontend_id: &str) -> Result<(), LoadBalancerError>;
|
||||
fn list_backends(&self) -> Vec<Backend>;
|
||||
fn list_frontends(&self) -> Vec<Frontend>;
|
||||
}
|
||||
pub struct LoadBalancerError;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Backend {
|
||||
pub id: String,
|
||||
pub ip: IpAddress,
|
||||
pub port: u16,
|
||||
pub weight: u8,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Frontend {
|
||||
pub id: String,
|
||||
pub ip: IpAddress,
|
||||
pub port: u16,
|
||||
pub backend_ids: Vec<String>,
|
||||
}
|
||||
@@ -1,18 +1,20 @@
|
||||
mod router;
|
||||
mod load_balancer;
|
||||
pub use router::*;
|
||||
pub use load_balancer::*;
|
||||
mod network;
|
||||
pub use network::*;
|
||||
|
||||
use std::net::IpAddr;
|
||||
|
||||
use derive_new::new;
|
||||
|
||||
use super::hardware::{Host, HostGroup};
|
||||
use super::hardware::Host;
|
||||
|
||||
pub struct HAClusterTopology {
|
||||
pub gateway: IpAddress,
|
||||
pub load_balancer: IpAddress,
|
||||
pub firewall: Box<dyn Firewall>,
|
||||
pub dhcp_server: Box<dyn DhcpServer>,
|
||||
pub dns_server: Box<dyn DnsServer>,
|
||||
pub router: Box<dyn Router + Send>,
|
||||
pub load_balancer: Box<dyn LoadBalancer + Send>,
|
||||
pub firewall: Box<dyn Firewall + Send>,
|
||||
pub dhcp_server: Box<dyn DhcpServer + Send>,
|
||||
pub dns_server: Box<dyn DnsServer + Send>,
|
||||
pub control_plane: Vec<ClusterMember>,
|
||||
pub workers: Vec<ClusterMember>,
|
||||
pub ceph_hosts: Vec<ClusterMember>,
|
||||
@@ -22,7 +24,7 @@ pub struct HAClusterTopology {
|
||||
pub type IpAddress = IpAddr;
|
||||
|
||||
pub struct ClusterMember {
|
||||
pub management: Box<dyn ManagementInterface>,
|
||||
pub management: Box<dyn ManagementInterface + Send>,
|
||||
pub host: Host,
|
||||
}
|
||||
|
||||
@@ -31,18 +33,3 @@ pub trait ManagementInterface {
|
||||
fn get_ip(&self) -> IpAddress;
|
||||
}
|
||||
|
||||
#[derive(new)]
|
||||
pub struct OPNSenseManagement {
|
||||
username: String,
|
||||
password: String,
|
||||
}
|
||||
|
||||
impl ManagementInterface for OPNSenseManagement {
|
||||
fn boot_to_pxe(&self) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn get_ip(&self) -> IpAddress {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
use std::net::{IpAddr, Ipv4Addr};
|
||||
use super::IpAddress;
|
||||
|
||||
pub trait Firewall {
|
||||
fn add_rule(&mut self, rule: FirewallRule) -> Result<(), FirewallError>;
|
||||
fn remove_rule(&mut self, rule_id: &str) -> Result<(), FirewallError>;
|
||||
fn list_rules(&self) -> Vec<FirewallRule>;
|
||||
fn get_ip(&self) -> IpAddress;
|
||||
}
|
||||
|
||||
pub struct NetworkDomain {
|
||||
pub name: String
|
||||
}
|
||||
|
||||
pub trait DhcpServer {
|
||||
fn add_static_mapping(&mut self, mac: MacAddress, ip: Ipv4Addr) -> Result<(), DhcpError>;
|
||||
fn add_static_mapping(&mut self, mac: MacAddress, ip: IpAddress) -> Result<(), DhcpError>;
|
||||
fn remove_static_mapping(&mut self, mac: &MacAddress) -> Result<(), DhcpError>;
|
||||
fn list_static_mappings(&self) -> Vec<(MacAddress, Ipv4Addr)>;
|
||||
fn list_static_mappings(&self) -> Vec<(MacAddress, IpAddress)>;
|
||||
}
|
||||
|
||||
pub trait DnsServer {
|
||||
@@ -18,22 +23,11 @@ pub trait DnsServer {
|
||||
fn list_records(&self) -> Vec<DnsRecord>;
|
||||
}
|
||||
|
||||
pub trait LoadBalancer {
|
||||
fn add_backend(&mut self, backend: Backend) -> Result<(), LoadBalancerError>;
|
||||
fn remove_backend(&mut self, backend_id: &str) -> Result<(), LoadBalancerError>;
|
||||
fn add_frontend(&mut self, frontend: Frontend) -> Result<(), LoadBalancerError>;
|
||||
fn remove_frontend(&mut self, frontend_id: &str) -> Result<(), LoadBalancerError>;
|
||||
fn list_backends(&self) -> Vec<Backend>;
|
||||
fn list_frontends(&self) -> Vec<Frontend>;
|
||||
}
|
||||
|
||||
// Supporting types
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct FirewallRule {
|
||||
pub id: String,
|
||||
pub source: IpAddr,
|
||||
pub destination: IpAddr,
|
||||
pub source: IpAddress,
|
||||
pub destination: IpAddress,
|
||||
pub port: u16,
|
||||
pub protocol: Protocol,
|
||||
pub action: Action,
|
||||
@@ -71,24 +65,7 @@ pub struct DnsRecord {
|
||||
pub value: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Backend {
|
||||
pub id: String,
|
||||
pub ip: IpAddr,
|
||||
pub port: u16,
|
||||
pub weight: u8,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Frontend {
|
||||
pub id: String,
|
||||
pub ip: IpAddr,
|
||||
pub port: u16,
|
||||
pub backend_ids: Vec<String>,
|
||||
}
|
||||
|
||||
// Error types
|
||||
pub struct FirewallError;
|
||||
pub struct DhcpError;
|
||||
pub struct DnsError;
|
||||
pub struct LoadBalancerError;
|
||||
|
||||
25
harmony-rs/harmony/src/domain/topology/router.rs
Normal file
25
harmony-rs/harmony/src/domain/topology/router.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use cidr::Ipv4Cidr;
|
||||
use derive_new::new;
|
||||
|
||||
use super::IpAddress;
|
||||
|
||||
pub trait Router {
|
||||
fn get_gateway(&self) -> IpAddress;
|
||||
fn get_cidr(&self) -> Ipv4Cidr;
|
||||
}
|
||||
|
||||
#[derive(new)]
|
||||
pub struct UnmanagedRouter {
|
||||
gateway: IpAddress,
|
||||
cidr: Ipv4Cidr,
|
||||
}
|
||||
|
||||
impl Router for UnmanagedRouter {
|
||||
fn get_gateway(&self) -> IpAddress {
|
||||
self.gateway.clone()
|
||||
}
|
||||
|
||||
fn get_cidr(&self) -> Ipv4Cidr {
|
||||
self.cidr.clone()
|
||||
}
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
pub mod executors;
|
||||
pub mod opnsense;
|
||||
|
||||
78
harmony-rs/harmony/src/infra/opnsense/mod.rs
Normal file
78
harmony-rs/harmony/src/infra/opnsense/mod.rs
Normal file
@@ -0,0 +1,78 @@
|
||||
use derive_new::new;
|
||||
use crate::topology::{Backend, DhcpServer, DnsServer, Firewall, FirewallError, FirewallRule, Frontend, IpAddress, LoadBalancer, LoadBalancerError};
|
||||
|
||||
#[derive(new, Clone)]
|
||||
pub struct OPNSenseFirewall {
|
||||
ip_address: IpAddress,
|
||||
}
|
||||
|
||||
impl Firewall for OPNSenseFirewall {
|
||||
fn add_rule(&mut self, _rule: FirewallRule) -> Result<(), FirewallError> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn remove_rule(&mut self, _rule_id: &str) -> Result<(), FirewallError> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn list_rules(&self) -> Vec<FirewallRule> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn get_ip(&self) -> IpAddress {
|
||||
self.ip_address.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl LoadBalancer for OPNSenseFirewall {
|
||||
fn add_backend(&mut self, _backend: Backend) -> Result<(), LoadBalancerError> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn remove_backend(&mut self, _backend_id: &str) -> Result<(), LoadBalancerError> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn add_frontend(&mut self, _frontend: Frontend) -> Result<(), LoadBalancerError> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn remove_frontend(&mut self, _frontend_id: &str) -> Result<(), LoadBalancerError> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn list_backends(&self) -> Vec<Backend> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn list_frontends(&self) -> Vec<Frontend> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl DhcpServer for OPNSenseFirewall {
|
||||
fn add_static_mapping(&mut self, mac: crate::topology::MacAddress, ip: IpAddress) -> Result<(), crate::topology::DhcpError> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn remove_static_mapping(&mut self, mac: &crate::topology::MacAddress) -> Result<(), crate::topology::DhcpError> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn list_static_mappings(&self) -> Vec<(crate::topology::MacAddress, IpAddress)> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
impl DnsServer for OPNSenseFirewall {
|
||||
fn add_record(&mut self, name: &str, record_type: crate::topology::DnsRecordType, value: &str) -> Result<(), crate::topology::DnsError> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn remove_record(&mut self, name: &str, record_type: crate::topology::DnsRecordType) -> Result<(), crate::topology::DnsError> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn list_records(&self) -> Vec<crate::topology::DnsRecord> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user