Files
harmony/harmony-rs/demo/vbox-opnsense/src/main.rs
jeangab bec96c2954 feat(bootstrapping): add bootstrap load balancer and DHCP configurations
- Introduce `bootstrap_load_balancer` module for handling initial load balancing configuration.
- Add `bootstrap_dhcp` module for bootstrapping DHCP settings.
- Create `harmony_types` crate to house shared types, including `MacAddress`.
- Update `harmony_macros` to use `harmony_types` instead of directly referencing `harmony`.
2025-01-09 11:58:49 -05:00

98 lines
3.2 KiB
Rust

use std::{
net::{IpAddr, Ipv4Addr},
sync::Arc,
};
use cidr::Ipv4Cidr;
use harmony::{
hardware::{FirewallGroup, HostCategory, Location, PhysicalHost, SwitchGroup},
infra::opnsense::OPNSenseManagementInterface,
inventory::Inventory,
maestro::Maestro,
modules::{
http::HttpScore,
okd::{dhcp::OKDDhcpScore, dns::OKDDnsScore},
tftp::TftpScore,
},
topology::{LogicalHost, UnmanagedRouter, Url},
};
use harmony_macros::ip;
#[tokio::main]
async fn main() {
env_logger::init();
let firewall = harmony::topology::LogicalHost {
ip: ip!("192.168.5.229"),
name: String::from("opnsense-1"),
};
let opnsense = Arc::new(
harmony::infra::opnsense::OPNSenseFirewall::new(firewall, None, "lan", "root", "opnsense")
.await,
);
let lan_subnet = Ipv4Addr::new(10, 100, 8, 0);
let gateway_ipv4 = Ipv4Addr::new(10, 100, 8, 1);
let gateway_ip = IpAddr::V4(gateway_ipv4);
let topology = harmony::topology::HAClusterTopology {
domain_name: "demo.harmony.mcd".to_string(),
router: Arc::new(UnmanagedRouter::new(
gateway_ip,
Ipv4Cidr::new(lan_subnet, 24).unwrap(),
)),
load_balancer: opnsense.clone(),
firewall: opnsense.clone(),
tftp_server: opnsense.clone(),
http_server: opnsense.clone(),
dhcp_server: opnsense.clone(),
dns_server: opnsense.clone(),
control_plane: vec![LogicalHost {
ip: ip!("10.100.8.20"),
name: "cp0".to_string(),
}],
bootstrap_host: LogicalHost {
ip: ip!("10.100.8.20"),
name: "cp0".to_string(),
},
workers: vec![],
switch: vec![],
};
let inventory = Inventory {
location: Location::new(
"232 des Éperviers, Wendake, Qc, G0A 4V0".to_string(),
"wk".to_string(),
),
switch: SwitchGroup::from([]),
firewall: FirewallGroup::from([PhysicalHost {
category: HostCategory::Firewall,
network: vec![],
management: Arc::new(OPNSenseManagementInterface::new()),
storage: vec![],
labels: vec![],
}]),
worker_host: vec![],
storage_host: vec![],
control_plane_host: vec![],
};
// TODO regroup smaller scores in a larger one such as this
// let okd_boostrap_preparation();
// let dhcp_score = OKDDhcpScore::new(&topology, &inventory);
// let dns_score = OKDDnsScore::new(&topology);
// let load_balancer_score =
// harmony::modules::okd::load_balancer::OKDLoadBalancerScore::new(&topology);
let tftp_score = TftpScore::new(Url::LocalFolder("../../../watchguard/tftpboot".to_string()));
let http_score = HttpScore::new(Url::LocalFolder(
"../../../watchguard/pxe-http-files".to_string(),
));
let maestro = Maestro::new(inventory, topology);
// maestro.interpret(dns_score).await.unwrap();
// maestro.interpret(dhcp_score).await.unwrap();
// maestro.interpret(load_balancer_score).await.unwrap();
// maestro.interpret(tftp_score).await.unwrap();
maestro.interpret(http_score).await.unwrap();
}