forked from NationTech/harmony
wip: FQM topology with OKDHaCluster, not satisfied yet with the cluster topology data structure
This commit is contained in:
@@ -20,8 +20,9 @@ pub enum HostCategory {
|
||||
|
||||
#[derive(Debug, new)]
|
||||
pub struct NetworkInterface {
|
||||
speed: u64,
|
||||
name: String,
|
||||
mac_address: MacAddress,
|
||||
speed: u64,
|
||||
plugged_in: bool,
|
||||
}
|
||||
type MacAddress = String;
|
||||
@@ -40,7 +41,7 @@ pub enum StorageKind {
|
||||
NVME,
|
||||
HDD,
|
||||
}
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, new)]
|
||||
pub struct Storage {
|
||||
connection: StorageConnectionType,
|
||||
kind: StorageKind,
|
||||
@@ -56,7 +57,7 @@ pub struct Switch {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Firewall {}
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, new)]
|
||||
pub struct Label {
|
||||
name: String,
|
||||
value: String,
|
||||
|
||||
@@ -1,13 +1,48 @@
|
||||
mod network;
|
||||
pub use network::*;
|
||||
|
||||
use std::net::IpAddr;
|
||||
|
||||
use super::hardware::HostGroup;
|
||||
use derive_new::new;
|
||||
|
||||
pub struct OKDHACluster {
|
||||
firewall: HostGroup,
|
||||
control_plane: HostGroup,
|
||||
workers: HostGroup,
|
||||
ceph_hosts: HostGroup,
|
||||
switch: HostGroup,
|
||||
use super::hardware::{Host, HostGroup};
|
||||
|
||||
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 control_plane: Vec<ClusterMember>,
|
||||
pub workers: Vec<ClusterMember>,
|
||||
pub ceph_hosts: Vec<ClusterMember>,
|
||||
pub switch: Vec<ClusterMember>,
|
||||
}
|
||||
|
||||
pub struct IpAddress(IpAddr);
|
||||
pub type IpAddress = IpAddr;
|
||||
|
||||
pub struct ClusterMember {
|
||||
pub management: Box<dyn ManagementInterface>,
|
||||
pub host: Host,
|
||||
}
|
||||
|
||||
pub trait ManagementInterface {
|
||||
fn boot_to_pxe(&self);
|
||||
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!()
|
||||
}
|
||||
}
|
||||
|
||||
94
harmony-rs/harmony/src/domain/topology/network.rs
Normal file
94
harmony-rs/harmony/src/domain/topology/network.rs
Normal file
@@ -0,0 +1,94 @@
|
||||
use std::net::{IpAddr, Ipv4Addr};
|
||||
|
||||
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>;
|
||||
}
|
||||
|
||||
pub trait DhcpServer {
|
||||
fn add_static_mapping(&mut self, mac: MacAddress, ip: Ipv4Addr) -> Result<(), DhcpError>;
|
||||
fn remove_static_mapping(&mut self, mac: &MacAddress) -> Result<(), DhcpError>;
|
||||
fn list_static_mappings(&self) -> Vec<(MacAddress, Ipv4Addr)>;
|
||||
}
|
||||
|
||||
pub trait DnsServer {
|
||||
fn add_record(&mut self, name: &str, record_type: DnsRecordType, value: &str) -> Result<(), DnsError>;
|
||||
fn remove_record(&mut self, name: &str, record_type: DnsRecordType) -> Result<(), DnsError>;
|
||||
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 port: u16,
|
||||
pub protocol: Protocol,
|
||||
pub action: Action,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Protocol {
|
||||
TCP,
|
||||
UDP,
|
||||
ICMP,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Action {
|
||||
Allow,
|
||||
Deny,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct MacAddress([u8; 6]);
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum DnsRecordType {
|
||||
A,
|
||||
AAAA,
|
||||
CNAME,
|
||||
MX,
|
||||
TXT,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct DnsRecord {
|
||||
pub name: String,
|
||||
pub record_type: DnsRecordType,
|
||||
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;
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod domain;
|
||||
mod domain;
|
||||
pub use domain::*;
|
||||
pub mod infra;
|
||||
pub mod modules;
|
||||
|
||||
Reference in New Issue
Block a user