98 lines
3.2 KiB
Rust
98 lines
3.2 KiB
Rust
mod topology;
|
|
|
|
use std::net::IpAddr;
|
|
|
|
use askama::Template;
|
|
use harmony::{
|
|
data::{FileContent, FilePath},
|
|
modules::{dhcp::DhcpScore, http::StaticFilesHttpScore, tftp::TftpScore},
|
|
score::Score,
|
|
topology::{HAClusterTopology, Url},
|
|
};
|
|
|
|
use crate::topology::{get_inventory, get_topology};
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
let inventory = get_inventory();
|
|
let topology = get_topology().await;
|
|
let gateway_ip = &topology.router.get_gateway();
|
|
|
|
let kickstart_filename = "inventory.kickstart";
|
|
let cluster_pubkey_filename = "cluster_ssh_key.pub";
|
|
let harmony_inventory_agent = "harmony_inventory_agent";
|
|
|
|
// TODO: this should be a single IPXEScore instead of having the user do this step by step
|
|
let scores: Vec<Box<dyn Score<HAClusterTopology>>> = vec![
|
|
Box::new(DhcpScore {
|
|
host_binding: vec![],
|
|
next_server: Some(topology.router.get_gateway()),
|
|
boot_filename: None,
|
|
filename: Some("undionly.kpxe".to_string()),
|
|
filename64: Some("ipxe.efi".to_string()),
|
|
filenameipxe: Some(format!("http://{gateway_ip}:8080/boot.ipxe").to_string()),
|
|
}),
|
|
Box::new(TftpScore {
|
|
files_to_serve: Url::LocalFolder("./data/pxe/okd/tftpboot/".to_string()),
|
|
}),
|
|
Box::new(StaticFilesHttpScore {
|
|
// TODO The current russh based copy is way too slow, check for a lib update or use scp
|
|
// when available
|
|
//
|
|
// For now just run :
|
|
// scp -r data/pxe/okd/http_files/* root@192.168.1.1:/usr/local/http/
|
|
//
|
|
folder_to_serve: None,
|
|
// folder_to_serve: Some(Url::LocalFolder("./data/pxe/okd/http_files/".to_string())),
|
|
files: vec![
|
|
FileContent {
|
|
path: FilePath::Relative("boot.ipxe".to_string()),
|
|
content: BootIpxeTpl { gateway_ip }.to_string(),
|
|
},
|
|
FileContent {
|
|
path: FilePath::Relative(kickstart_filename.to_string()),
|
|
content: InventoryKickstartTpl {
|
|
gateway_ip,
|
|
harmony_inventory_agent,
|
|
cluster_pubkey_filename,
|
|
}
|
|
.to_string(),
|
|
},
|
|
FileContent {
|
|
path: FilePath::Relative("fallback.ipxe".to_string()),
|
|
content: FallbackIpxeTpl {
|
|
gateway_ip,
|
|
kickstart_filename,
|
|
}
|
|
.to_string(),
|
|
},
|
|
],
|
|
}),
|
|
];
|
|
|
|
harmony_cli::run(inventory, topology, scores, None)
|
|
.await
|
|
.unwrap();
|
|
}
|
|
|
|
#[derive(Template)]
|
|
#[template(path = "boot.ipxe.j2")]
|
|
struct BootIpxeTpl<'a> {
|
|
gateway_ip: &'a IpAddr,
|
|
}
|
|
|
|
#[derive(Template)]
|
|
#[template(path = "fallback.ipxe.j2")]
|
|
struct FallbackIpxeTpl<'a> {
|
|
gateway_ip: &'a IpAddr,
|
|
kickstart_filename: &'a str,
|
|
}
|
|
|
|
#[derive(Template)]
|
|
#[template(path = "inventory.kickstart.j2")]
|
|
struct InventoryKickstartTpl<'a> {
|
|
gateway_ip: &'a IpAddr,
|
|
cluster_pubkey_filename: &'a str,
|
|
harmony_inventory_agent: &'a str,
|
|
}
|