wip: FQM topology with OKDHaCluster, not satisfied yet with the cluster topology data structure
This commit is contained in:
parent
8592a3bc36
commit
87a9ec3ec4
@ -1,4 +1,5 @@
|
|||||||
pub mod inventory;
|
pub mod inventory;
|
||||||
|
pub mod topology;
|
||||||
pub fn add(left: usize, right: usize) -> usize {
|
pub fn add(left: usize, right: usize) -> usize {
|
||||||
left + right
|
left + right
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,5 +18,5 @@ async fn main() {
|
|||||||
let score = OPNSenseDhcpScore::new(InventoryFilter::new(vec![]));
|
let score = OPNSenseDhcpScore::new(InventoryFilter::new(vec![]));
|
||||||
let result = maestro.interpret(score).await.unwrap();
|
let result = maestro.interpret(score).await.unwrap();
|
||||||
info!("{result}");
|
info!("{result}");
|
||||||
}).await;
|
}).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
86
harmony-rs/fqm/src/topology.rs
Normal file
86
harmony-rs/fqm/src/topology.rs
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
use std::net::{IpAddr, Ipv4Addr};
|
||||||
|
|
||||||
|
use harmony::{
|
||||||
|
hardware::*,
|
||||||
|
topology::{ClusterMember, HAClusterTopology, IpAddress, OPNSenseManagement},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn fqm_topology() -> HAClusterTopology {
|
||||||
|
HAClusterTopology {
|
||||||
|
firewall: vec![ClusterMember {
|
||||||
|
management: Box::new(OPNSenseManagement::new(
|
||||||
|
"user".to_string(),
|
||||||
|
"password".to_string(),
|
||||||
|
)),
|
||||||
|
host: Host {
|
||||||
|
category: HostCategory::Firewall,
|
||||||
|
network: vec![
|
||||||
|
NetworkInterface::new(
|
||||||
|
"igb0".to_string(),
|
||||||
|
"00:90:7f:df:2c:1f".to_string(),
|
||||||
|
1_000_000_000,
|
||||||
|
true,
|
||||||
|
),
|
||||||
|
NetworkInterface::new(
|
||||||
|
"igb1".to_string(),
|
||||||
|
"00:90:7f:df:2c:20".to_string(),
|
||||||
|
1_000_000_000,
|
||||||
|
true,
|
||||||
|
),
|
||||||
|
NetworkInterface::new(
|
||||||
|
"igb2".to_string(),
|
||||||
|
"00:90:7f:df:2c:21".to_string(),
|
||||||
|
1_000_000_000,
|
||||||
|
true,
|
||||||
|
),
|
||||||
|
NetworkInterface::new(
|
||||||
|
"igb3".to_string(),
|
||||||
|
"00:90:7f:df:2c:22".to_string(),
|
||||||
|
1_000_000_000,
|
||||||
|
true,
|
||||||
|
),
|
||||||
|
NetworkInterface::new(
|
||||||
|
"igb4".to_string(),
|
||||||
|
"00:90:7f:df:2c:23".to_string(),
|
||||||
|
1_000_000_000,
|
||||||
|
true,
|
||||||
|
),
|
||||||
|
NetworkInterface::new(
|
||||||
|
"igb5".to_string(),
|
||||||
|
"00:90:7f:df:2c:24".to_string(),
|
||||||
|
1_000_000_000,
|
||||||
|
true,
|
||||||
|
),
|
||||||
|
NetworkInterface::new(
|
||||||
|
"igb6".to_string(),
|
||||||
|
"00:90:7f:df:2c:25".to_string(),
|
||||||
|
1_000_000_000,
|
||||||
|
true,
|
||||||
|
),
|
||||||
|
NetworkInterface::new(
|
||||||
|
"igb7".to_string(),
|
||||||
|
"00:90:7f:df:2c:26".to_string(),
|
||||||
|
1_000_000_000,
|
||||||
|
true,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
storage: vec![Storage::new(
|
||||||
|
StorageConnectionType::Sata6g,
|
||||||
|
StorageKind::SSD,
|
||||||
|
240_000_000_000,
|
||||||
|
"TODO".to_string(),
|
||||||
|
)],
|
||||||
|
labels: vec![Label::new(
|
||||||
|
"operatingSystem".to_string(),
|
||||||
|
"opnsense".to_string(),
|
||||||
|
)],
|
||||||
|
},
|
||||||
|
}],
|
||||||
|
control_plane: todo!(),
|
||||||
|
workers: todo!(),
|
||||||
|
ceph_hosts: todo!(),
|
||||||
|
switch: todo!(),
|
||||||
|
gateway: IpAddress::V4(Ipv4Addr::new(10, 10, 8, 1)),
|
||||||
|
load_balancer: IpAddress::V4(Ipv4Addr::new(10, 10, 8, 1)),
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -20,8 +20,9 @@ pub enum HostCategory {
|
|||||||
|
|
||||||
#[derive(Debug, new)]
|
#[derive(Debug, new)]
|
||||||
pub struct NetworkInterface {
|
pub struct NetworkInterface {
|
||||||
speed: u64,
|
name: String,
|
||||||
mac_address: MacAddress,
|
mac_address: MacAddress,
|
||||||
|
speed: u64,
|
||||||
plugged_in: bool,
|
plugged_in: bool,
|
||||||
}
|
}
|
||||||
type MacAddress = String;
|
type MacAddress = String;
|
||||||
@ -40,7 +41,7 @@ pub enum StorageKind {
|
|||||||
NVME,
|
NVME,
|
||||||
HDD,
|
HDD,
|
||||||
}
|
}
|
||||||
#[derive(Debug)]
|
#[derive(Debug, new)]
|
||||||
pub struct Storage {
|
pub struct Storage {
|
||||||
connection: StorageConnectionType,
|
connection: StorageConnectionType,
|
||||||
kind: StorageKind,
|
kind: StorageKind,
|
||||||
@ -56,7 +57,7 @@ pub struct Switch {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Firewall {}
|
pub struct Firewall {}
|
||||||
#[derive(Debug)]
|
#[derive(Debug, new)]
|
||||||
pub struct Label {
|
pub struct Label {
|
||||||
name: String,
|
name: String,
|
||||||
value: String,
|
value: String,
|
||||||
|
|||||||
@ -1,13 +1,48 @@
|
|||||||
|
mod network;
|
||||||
|
pub use network::*;
|
||||||
|
|
||||||
use std::net::IpAddr;
|
use std::net::IpAddr;
|
||||||
|
|
||||||
use super::hardware::HostGroup;
|
use derive_new::new;
|
||||||
|
|
||||||
pub struct OKDHACluster {
|
use super::hardware::{Host, HostGroup};
|
||||||
firewall: HostGroup,
|
|
||||||
control_plane: HostGroup,
|
pub struct HAClusterTopology {
|
||||||
workers: HostGroup,
|
pub gateway: IpAddress,
|
||||||
ceph_hosts: HostGroup,
|
pub load_balancer: IpAddress,
|
||||||
switch: HostGroup,
|
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 infra;
|
||||||
pub mod modules;
|
pub mod modules;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user