Some checks failed
Run Check Script / check (pull_request) Failing after 10s
101 lines
3.2 KiB
Rust
101 lines
3.2 KiB
Rust
use brocade::BrocadeOptions;
|
|
use cidr::Ipv4Cidr;
|
|
use harmony::{
|
|
config::secret::{OPNSenseApiCredentials, OPNSenseFirewallCredentials},
|
|
hardware::{Location, SwitchGroup},
|
|
infra::{
|
|
brocade::{BrocadeSwitchClient, BrocadeSwitchConfig},
|
|
opnsense::OPNSenseManagementInterface,
|
|
},
|
|
inventory::Inventory,
|
|
modules::brocade::BrocadeSwitchAuth,
|
|
topology::{HAClusterTopology, LogicalHost, UnmanagedRouter},
|
|
};
|
|
use harmony_macros::{ip, ipv4};
|
|
use harmony_secret::SecretManager;
|
|
use std::{
|
|
net::IpAddr,
|
|
sync::{Arc, OnceLock},
|
|
};
|
|
|
|
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 = BrocadeOptions {
|
|
dry_run: *harmony::config::DRY_RUN,
|
|
..Default::default()
|
|
};
|
|
let switch_client = BrocadeSwitchClient::init(BrocadeSwitchConfig {
|
|
ips: switches,
|
|
auth: switch_auth,
|
|
options: brocade_options,
|
|
})
|
|
.await
|
|
.expect("Failed to connect to switch");
|
|
|
|
let switch_client = Arc::new(switch_client);
|
|
|
|
let ssh_creds = SecretManager::get_or_prompt::<OPNSenseFirewallCredentials>()
|
|
.await
|
|
.unwrap();
|
|
let api_creds = SecretManager::get_or_prompt::<OPNSenseApiCredentials>()
|
|
.await
|
|
.unwrap();
|
|
|
|
let opnsense = Arc::new(
|
|
harmony::infra::opnsense::OPNSenseFirewall::new(firewall, None, &api_creds, &ssh_creds)
|
|
.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 {
|
|
kubeconfig: None,
|
|
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!("192.168.1.20"),
|
|
name: "master".to_string(),
|
|
}],
|
|
bootstrap_host: LogicalHost {
|
|
ip: ip!("192.168.1.10"),
|
|
name: "bootstrap".to_string(),
|
|
},
|
|
workers: vec![],
|
|
node_exporter: opnsense.clone(),
|
|
switch_client: switch_client.clone(),
|
|
network_manager: OnceLock::new(),
|
|
}
|
|
}
|
|
|
|
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![],
|
|
}
|
|
}
|