Compare commits
2 Commits
chore/clea
...
feat/st_te
| Author | SHA1 | Date | |
|---|---|---|---|
| 001dd5269c | |||
| 9978acf16d |
20
Cargo.lock
generated
20
Cargo.lock
generated
@@ -1754,24 +1754,6 @@ dependencies = [
|
|||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "example-ha-cluster"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"brocade",
|
|
||||||
"cidr",
|
|
||||||
"env_logger",
|
|
||||||
"harmony",
|
|
||||||
"harmony_macros",
|
|
||||||
"harmony_secret",
|
|
||||||
"harmony_tui",
|
|
||||||
"harmony_types",
|
|
||||||
"log",
|
|
||||||
"serde",
|
|
||||||
"tokio",
|
|
||||||
"url",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "example-kube-rs"
|
name = "example-kube-rs"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@@ -1960,9 +1942,9 @@ dependencies = [
|
|||||||
"cidr",
|
"cidr",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"harmony",
|
"harmony",
|
||||||
"harmony_cli",
|
|
||||||
"harmony_macros",
|
"harmony_macros",
|
||||||
"harmony_secret",
|
"harmony_secret",
|
||||||
|
"harmony_tui",
|
||||||
"harmony_types",
|
"harmony_types",
|
||||||
"log",
|
"log",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ use std::{
|
|||||||
sync::{Arc, OnceLock},
|
sync::{Arc, OnceLock},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use brocade::BrocadeOptions;
|
||||||
use cidr::Ipv4Cidr;
|
use cidr::Ipv4Cidr;
|
||||||
use harmony::{
|
use harmony::{
|
||||||
config::secret::SshKeyPair,
|
config::secret::SshKeyPair,
|
||||||
data::{FileContent, FilePath},
|
data::{FileContent, FilePath},
|
||||||
hardware::{HostCategory, Location, PhysicalHost, SwitchGroup},
|
hardware::{HostCategory, Location, PhysicalHost, SwitchGroup},
|
||||||
infra::{brocade::UnmanagedSwitch, opnsense::OPNSenseManagementInterface},
|
infra::{brocade::BrocadeSwitchClient, opnsense::OPNSenseManagementInterface},
|
||||||
inventory::Inventory,
|
inventory::Inventory,
|
||||||
modules::{
|
modules::{
|
||||||
http::StaticFilesHttpScore,
|
http::StaticFilesHttpScore,
|
||||||
@@ -22,11 +23,10 @@ use harmony::{
|
|||||||
topology::{LogicalHost, UnmanagedRouter},
|
topology::{LogicalHost, UnmanagedRouter},
|
||||||
};
|
};
|
||||||
use harmony_macros::{ip, mac_address};
|
use harmony_macros::{ip, mac_address};
|
||||||
use harmony_secret::SecretManager;
|
use harmony_secret::{Secret, SecretManager};
|
||||||
use harmony_types::net::Url;
|
use harmony_types::net::Url;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// This example can be run this way
|
|
||||||
/// KUBECONFIG=~/path/to/ncd/kubeconfig HARMONY_USE_LOCAL_K3D=false HARMONY_SECRET_STORE=file HARMONY_SECRET_NAMESPACE=ncd0 cargo run
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let firewall = harmony::topology::LogicalHost {
|
let firewall = harmony::topology::LogicalHost {
|
||||||
@@ -34,7 +34,24 @@ async fn main() {
|
|||||||
name: String::from("fw0"),
|
name: String::from("fw0"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let switch_client = UnmanagedSwitch {};
|
let switch_auth = SecretManager::get_or_prompt::<BrocadeSwitchAuth>()
|
||||||
|
.await
|
||||||
|
.expect("Failed to get credentials");
|
||||||
|
|
||||||
|
let switches: Vec<IpAddr> = vec![ip!("192.168.33.101")];
|
||||||
|
let brocade_options = 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 switch_client = Arc::new(switch_client);
|
||||||
|
|
||||||
let opnsense = Arc::new(
|
let opnsense = Arc::new(
|
||||||
@@ -174,3 +191,9 @@ async fn main() {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Secret, Serialize, Deserialize, Debug)]
|
||||||
|
pub struct BrocadeSwitchAuth {
|
||||||
|
pub username: String,
|
||||||
|
pub password: String,
|
||||||
|
}
|
||||||
|
|||||||
21
examples/sttest/Cargo.toml
Normal file
21
examples/sttest/Cargo.toml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
[package]
|
||||||
|
name = "sttest"
|
||||||
|
edition = "2024"
|
||||||
|
version.workspace = true
|
||||||
|
readme.workspace = true
|
||||||
|
license.workspace = true
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
harmony = { path = "../../harmony" }
|
||||||
|
harmony_tui = { path = "../../harmony_tui" }
|
||||||
|
harmony_types = { path = "../../harmony_types" }
|
||||||
|
cidr = { workspace = true }
|
||||||
|
tokio = { workspace = true }
|
||||||
|
harmony_macros = { path = "../../harmony_macros" }
|
||||||
|
harmony_secret = { path = "../../harmony_secret" }
|
||||||
|
log = { workspace = true }
|
||||||
|
env_logger = { workspace = true }
|
||||||
|
url = { workspace = true }
|
||||||
|
serde = { workspace = true }
|
||||||
|
brocade = { path = "../../brocade" }
|
||||||
160
examples/sttest/src/main.rs
Normal file
160
examples/sttest/src/main.rs
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
use std::{
|
||||||
|
net::{IpAddr, Ipv4Addr},
|
||||||
|
sync::{Arc, OnceLock},
|
||||||
|
};
|
||||||
|
|
||||||
|
use cidr::Ipv4Cidr;
|
||||||
|
use harmony::{
|
||||||
|
config::secret::SshKeyPair,
|
||||||
|
data::{FileContent, FilePath},
|
||||||
|
hardware::{HostCategory, Location, PhysicalHost, SwitchGroup},
|
||||||
|
infra::{brocade::UnmanagedSwitch, opnsense::OPNSenseManagementInterface},
|
||||||
|
inventory::Inventory,
|
||||||
|
modules::{
|
||||||
|
http::StaticFilesHttpScore,
|
||||||
|
okd::{
|
||||||
|
bootstrap_dhcp::OKDBootstrapDhcpScore,
|
||||||
|
bootstrap_load_balancer::OKDBootstrapLoadBalancerScore, dhcp::OKDDhcpScore,
|
||||||
|
dns::OKDDnsScore, ipxe::OKDIpxeScore,
|
||||||
|
},
|
||||||
|
tftp::TftpScore,
|
||||||
|
},
|
||||||
|
topology::{LogicalHost, UnmanagedRouter},
|
||||||
|
};
|
||||||
|
use harmony_macros::{ip, mac_address};
|
||||||
|
use harmony_secret::{Secret, SecretManager};
|
||||||
|
use harmony_types::net::Url;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
// env_logger::init();
|
||||||
|
let firewall = harmony::topology::LogicalHost {
|
||||||
|
ip: ip!("192.168.40.1"),
|
||||||
|
name: String::from("fw0"), // settings -> general -> hostname on the opnsense firewall
|
||||||
|
};
|
||||||
|
|
||||||
|
let switch_client = UnmanagedSwitch::init()
|
||||||
|
.await
|
||||||
|
.expect("Failed to connect to switch");
|
||||||
|
|
||||||
|
let switch_client = Arc::new(switch_client);
|
||||||
|
|
||||||
|
let opnsense = Arc::new(
|
||||||
|
harmony::infra::opnsense::OPNSenseFirewall::new(firewall, None, "root", "opnsense").await,
|
||||||
|
);
|
||||||
|
let lan_subnet = Ipv4Addr::new(192, 168, 40, 0);
|
||||||
|
let gateway_ipv4 = Ipv4Addr::new(192, 168, 40, 1);
|
||||||
|
let gateway_ip = IpAddr::V4(gateway_ipv4);
|
||||||
|
let topology = harmony::topology::HAClusterTopology {
|
||||||
|
kubeconfig: None,
|
||||||
|
domain_name: "sttest0.harmony.mcd".to_string(), // TODO this must be set manually correctly
|
||||||
|
// when setting up the opnsense firewall in settings -> general -> domain
|
||||||
|
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.40.20"),
|
||||||
|
name: "cp0".to_string(),
|
||||||
|
},
|
||||||
|
LogicalHost {
|
||||||
|
ip: ip!("192.168.40.21"),
|
||||||
|
name: "cp1".to_string(),
|
||||||
|
},
|
||||||
|
LogicalHost {
|
||||||
|
ip: ip!("192.168.40.22"),
|
||||||
|
name: "cp2".to_string(),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
bootstrap_host: LogicalHost {
|
||||||
|
ip: ip!("192.168.40.66"),
|
||||||
|
name: "bootstrap".to_string(),
|
||||||
|
},
|
||||||
|
workers: vec![
|
||||||
|
LogicalHost {
|
||||||
|
ip: ip!("192.168.40.30"),
|
||||||
|
name: "wk0".to_string(),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
node_exporter: opnsense.clone(),
|
||||||
|
switch_client: switch_client.clone(),
|
||||||
|
network_manager: OnceLock::new(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let inventory = Inventory {
|
||||||
|
location: Location::new("I am mobile".to_string(), "earth".to_string()),
|
||||||
|
switch: SwitchGroup::from([]),
|
||||||
|
firewall_mgmt: Box::new(OPNSenseManagementInterface::new()),
|
||||||
|
storage_host: vec![],
|
||||||
|
worker_host: vec![
|
||||||
|
PhysicalHost::empty(HostCategory::Server)
|
||||||
|
.mac_address(mac_address!("64:00:6A:88:A3:50")),
|
||||||
|
],
|
||||||
|
control_plane_host: vec![
|
||||||
|
PhysicalHost::empty(HostCategory::Server)
|
||||||
|
.mac_address(mac_address!("F4:39:09:16:65:33")),
|
||||||
|
PhysicalHost::empty(HostCategory::Server)
|
||||||
|
.mac_address(mac_address!("F4:39:09:07:C8:F2")),
|
||||||
|
PhysicalHost::empty(HostCategory::Server)
|
||||||
|
.mac_address(mac_address!("F4:39:09:16:65:EA")),
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO regroup smaller scores in a larger one such as this
|
||||||
|
// let okd_boostrap_preparation();
|
||||||
|
|
||||||
|
let bootstrap_dhcp_score = OKDBootstrapDhcpScore::new(&topology, &inventory);
|
||||||
|
let bootstrap_load_balancer_score = OKDBootstrapLoadBalancerScore::new(&topology);
|
||||||
|
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 ssh_key = SecretManager::get_or_prompt::<SshKeyPair>().await.unwrap();
|
||||||
|
|
||||||
|
let tftp_score = TftpScore::new(Url::LocalFolder("./data/watchguard/tftpboot".to_string()));
|
||||||
|
let http_score = StaticFilesHttpScore {
|
||||||
|
folder_to_serve: Some(Url::LocalFolder(
|
||||||
|
"./data/watchguard/pxe-http-files".to_string(),
|
||||||
|
)),
|
||||||
|
files: vec![],
|
||||||
|
remote_path: None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let kickstart_filename = "inventory.kickstart".to_string();
|
||||||
|
let harmony_inventory_agent = "harmony_inventory_agent".to_string();
|
||||||
|
|
||||||
|
let ipxe_score = OKDIpxeScore {
|
||||||
|
kickstart_filename,
|
||||||
|
harmony_inventory_agent,
|
||||||
|
cluster_pubkey: FileContent {
|
||||||
|
path: FilePath::Relative("cluster_ssh_key.pub".to_string()),
|
||||||
|
content: ssh_key.public,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
harmony_tui::run(
|
||||||
|
inventory,
|
||||||
|
topology,
|
||||||
|
vec![
|
||||||
|
// Box::new(dns_score),
|
||||||
|
Box::new(bootstrap_dhcp_score),
|
||||||
|
// Box::new(bootstrap_load_balancer_score),
|
||||||
|
// Box::new(load_balancer_score),
|
||||||
|
// Box::new(tftp_score),
|
||||||
|
// Box::new(http_score),
|
||||||
|
// Box::new(ipxe_score),
|
||||||
|
// Box::new(dhcp_score),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
@@ -21,9 +21,7 @@ use serde::Serialize;
|
|||||||
// -------------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, new)]
|
#[derive(Debug, Clone, Serialize, new)]
|
||||||
pub struct OKDSetup01InventoryScore {
|
pub struct OKDSetup01InventoryScore {}
|
||||||
discovery_strategy: HarmonyDiscoveryStrategy,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Score<HAClusterTopology> for OKDSetup01InventoryScore {
|
impl Score<HAClusterTopology> for OKDSetup01InventoryScore {
|
||||||
fn create_interpret(&self) -> Box<dyn Interpret<HAClusterTopology>> {
|
fn create_interpret(&self) -> Box<dyn Interpret<HAClusterTopology>> {
|
||||||
@@ -79,8 +77,6 @@ impl Interpret<HAClusterTopology> for OKDSetup01InventoryInterpret {
|
|||||||
info!("Setting up base DNS config for OKD");
|
info!("Setting up base DNS config for OKD");
|
||||||
let cluster_domain = &topology.domain_name;
|
let cluster_domain = &topology.domain_name;
|
||||||
let load_balancer_ip = &topology.load_balancer.get_ip();
|
let load_balancer_ip = &topology.load_balancer.get_ip();
|
||||||
// TODO reactivate automatic dns config when migration from unbound to dnsmasq is done
|
|
||||||
// For now we output the instruction for the user to do it manually
|
|
||||||
inquire::Confirm::new(&format!(
|
inquire::Confirm::new(&format!(
|
||||||
"Set hostnames manually in your opnsense dnsmasq config :
|
"Set hostnames manually in your opnsense dnsmasq config :
|
||||||
*.apps.{cluster_domain} -> {load_balancer_ip}
|
*.apps.{cluster_domain} -> {load_balancer_ip}
|
||||||
@@ -92,6 +88,7 @@ When you can dig them, confirm to continue.
|
|||||||
))
|
))
|
||||||
.prompt()
|
.prompt()
|
||||||
.expect("Prompt error");
|
.expect("Prompt error");
|
||||||
|
// TODO reactivate automatic dns config when migration from unbound to dnsmasq is done
|
||||||
// OKDDnsScore::new(topology)
|
// OKDDnsScore::new(topology)
|
||||||
// .interpret(inventory, topology)
|
// .interpret(inventory, topology)
|
||||||
// .await?;
|
// .await?;
|
||||||
@@ -108,7 +105,7 @@ When you can dig them, confirm to continue.
|
|||||||
DiscoverHostForRoleScore {
|
DiscoverHostForRoleScore {
|
||||||
role: HostRole::Bootstrap,
|
role: HostRole::Bootstrap,
|
||||||
number_desired_hosts: 1,
|
number_desired_hosts: 1,
|
||||||
discovery_strategy: self.score.discovery_strategy.clone(),
|
discovery_strategy: HarmonyDiscoveryStrategy::MDNS,
|
||||||
}
|
}
|
||||||
.interpret(inventory, topology)
|
.interpret(inventory, topology)
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
@@ -76,8 +76,6 @@ impl OKDSetup02BootstrapInterpret {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs the openshift-install commands locally to prepare ignition files
|
|
||||||
/// Uploads the ignition files to the statis http server
|
|
||||||
async fn prepare_ignition_files(
|
async fn prepare_ignition_files(
|
||||||
&self,
|
&self,
|
||||||
inventory: &Inventory,
|
inventory: &Inventory,
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ impl OKDInstallationPipeline {
|
|||||||
discovery_strategy: HarmonyDiscoveryStrategy,
|
discovery_strategy: HarmonyDiscoveryStrategy,
|
||||||
) -> Vec<Box<dyn Score<HAClusterTopology>>> {
|
) -> Vec<Box<dyn Score<HAClusterTopology>>> {
|
||||||
vec![
|
vec![
|
||||||
Box::new(OKDSetup01InventoryScore::new(discovery_strategy.clone())),
|
Box::new(OKDSetup01InventoryScore::new()),
|
||||||
Box::new(OKDSetup02BootstrapScore::new()),
|
Box::new(OKDSetup02BootstrapScore::new()),
|
||||||
Box::new(OKDSetup03ControlPlaneScore {
|
Box::new(OKDSetup03ControlPlaneScore {
|
||||||
discovery_strategy: discovery_strategy.clone(),
|
discovery_strategy: discovery_strategy.clone(),
|
||||||
|
|||||||
@@ -1153,7 +1153,7 @@ pub struct UnboundGeneral {
|
|||||||
pub local_zone_type: String,
|
pub local_zone_type: String,
|
||||||
pub outgoing_interface: MaybeString,
|
pub outgoing_interface: MaybeString,
|
||||||
pub enable_wpad: MaybeString,
|
pub enable_wpad: MaybeString,
|
||||||
pub safesearch: MaybeString,
|
pub safesearch: Option<MaybeString>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
|
#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
|
||||||
@@ -1421,7 +1421,7 @@ pub struct StaticRoutes {
|
|||||||
#[yaserde(attribute = true)]
|
#[yaserde(attribute = true)]
|
||||||
pub version: String,
|
pub version: String,
|
||||||
#[yaserde(rename = "route")]
|
#[yaserde(rename = "route")]
|
||||||
pub route: Option<MaybeString>,
|
pub route: Option<RawXml>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
|
#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
|
||||||
|
|||||||
Reference in New Issue
Block a user