100 lines
3.0 KiB
Rust
100 lines
3.0 KiB
Rust
use brocade::BrocadeOptions;
|
|
use cidr::Ipv4Cidr;
|
|
use harmony::{
|
|
config::secret::OPNSenseFirewallCredentials,
|
|
hardware::{Location, SwitchGroup},
|
|
infra::{brocade::BrocadeSwitchClient, opnsense::OPNSenseManagementInterface},
|
|
inventory::Inventory,
|
|
topology::{HAClusterTopology, LogicalHost, UnmanagedRouter},
|
|
};
|
|
use harmony_macros::{ip, ipv4};
|
|
use harmony_secret::{Secret, SecretManager};
|
|
use serde::{Deserialize, Serialize};
|
|
use std::{net::IpAddr, sync::Arc};
|
|
|
|
pub async fn get_topology() -> HAClusterTopology {
|
|
let firewall = harmony::topology::LogicalHost {
|
|
ip: ip!("192.168.1.1"),
|
|
name: String::from("opnsense-1"),
|
|
};
|
|
|
|
let switch_auth = SecretManager::get_or_prompt::<BrocadeSwitchAuth>()
|
|
.await
|
|
.expect("Failed to get credentials");
|
|
|
|
let switches: Vec<IpAddr> = vec![ip!("192.168.1.101")]; // TODO: Adjust me
|
|
let brocade_options = Some(BrocadeOptions {
|
|
dry_run: *harmony::config::DRY_RUN,
|
|
..Default::default()
|
|
});
|
|
let switch_client = BrocadeSwitchClient::init(
|
|
&switches,
|
|
&switch_auth.username,
|
|
&switch_auth.password,
|
|
brocade_options,
|
|
)
|
|
.await
|
|
.expect("Failed to connect to switch");
|
|
|
|
let switch_client = Arc::new(switch_client);
|
|
|
|
let config = SecretManager::get_or_prompt::<OPNSenseFirewallCredentials>().await;
|
|
let config = config.unwrap();
|
|
|
|
let opnsense = Arc::new(
|
|
harmony::infra::opnsense::OPNSenseFirewall::new(
|
|
firewall,
|
|
None,
|
|
&config.username,
|
|
&config.password,
|
|
)
|
|
.await,
|
|
);
|
|
let lan_subnet = ipv4!("192.168.1.0");
|
|
let gateway_ipv4 = ipv4!("192.168.1.1");
|
|
let gateway_ip = IpAddr::V4(gateway_ipv4);
|
|
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_client: switch_client.clone(),
|
|
}
|
|
}
|
|
|
|
pub fn get_inventory() -> Inventory {
|
|
Inventory {
|
|
location: Location::new(
|
|
"Some virtual machine or maybe a physical machine if you're cool".to_string(),
|
|
"testopnsense".to_string(),
|
|
),
|
|
switch: SwitchGroup::from([]),
|
|
firewall_mgmt: Box::new(OPNSenseManagementInterface::new()),
|
|
storage_host: vec![],
|
|
worker_host: vec![],
|
|
control_plane_host: vec![],
|
|
}
|
|
}
|
|
|
|
#[derive(Secret, Serialize, Deserialize, Debug)]
|
|
pub struct BrocadeSwitchAuth {
|
|
pub username: String,
|
|
pub password: String,
|
|
}
|