Name update
This commit is contained in:
+50
-18
@@ -4,16 +4,16 @@
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
use openpxe_core::{
|
||||
ClientRegistry, Config, DhcpMode, DeploymentQueue, HostBindings, LogBus, LogBusLayer, Metrics,
|
||||
ClientRegistry, Config, DeploymentQueue, DhcpMode, HostBindings, LogBus, LogBusLayer, Metrics,
|
||||
SettingsStore,
|
||||
};
|
||||
use openpxe_dhcp_proxy::DhcpProxyServer;
|
||||
use openpxe_http_api::{build_router, AppState};
|
||||
use openpxe_iso_store::{IsoStore, NfsManager, SmbManager};
|
||||
use std::sync::Arc;
|
||||
use openpxe_tftp::TftpServer;
|
||||
use std::net::{Ipv4Addr, SocketAddr};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use tokio::io::AsyncReadExt;
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
@@ -39,7 +39,7 @@ enum Command {
|
||||
/// docker run --rm \
|
||||
/// -v /my/isos:/seed:ro \
|
||||
/// -v openpxe-data:/var/lib/openpxe/isos \
|
||||
/// openpxe:0.1.0 seed --from /seed
|
||||
/// openpxe:0.3.2 seed --from /seed
|
||||
Seed {
|
||||
/// Source directory containing one or more `.iso` files.
|
||||
#[arg(long)]
|
||||
@@ -100,7 +100,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
let iso_store = IsoStore::new(config.paths.iso_dir.clone());
|
||||
iso_store.load_from_disk().await?;
|
||||
let clients = ClientRegistry::new();
|
||||
let gates = DeploymentQueue::new();
|
||||
let queue = DeploymentQueue::new();
|
||||
let settings = SettingsStore::load_or_default(&config.paths.work_dir);
|
||||
let hosts = HostBindings::load_or_default(&config.paths.work_dir);
|
||||
let metrics = Metrics::new();
|
||||
@@ -138,7 +138,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
iso_store: iso_store.clone(),
|
||||
clients: clients.clone(),
|
||||
settings: settings.clone(),
|
||||
queue: gates.clone(),
|
||||
queue: queue.clone(),
|
||||
hosts: hosts.clone(),
|
||||
metrics: metrics.clone(),
|
||||
smb: Some(smb.clone()),
|
||||
@@ -210,7 +210,11 @@ async fn run_command(cmd: Command, config: Config) -> anyhow::Result<()> {
|
||||
/// Reuses `IsoStore::begin_upload` / `finish` so the resulting meta on disk
|
||||
/// is identical to a web upload — same slug rules, same introspection, same
|
||||
/// sha256.
|
||||
async fn seed_from_dir(src: &std::path::Path, config: &Config, dry_run: bool) -> anyhow::Result<()> {
|
||||
async fn seed_from_dir(
|
||||
src: &std::path::Path,
|
||||
config: &Config,
|
||||
dry_run: bool,
|
||||
) -> anyhow::Result<()> {
|
||||
let store = IsoStore::new(config.paths.iso_dir.clone());
|
||||
store.load_from_disk().await?;
|
||||
let mut entries = tokio::fs::read_dir(src).await?;
|
||||
@@ -218,7 +222,12 @@ async fn seed_from_dir(src: &std::path::Path, config: &Config, dry_run: bool) ->
|
||||
let mut skipped = 0u32;
|
||||
while let Some(entry) = entries.next_entry().await? {
|
||||
let p = entry.path();
|
||||
if p.extension().and_then(|e| e.to_str()).map(str::to_ascii_lowercase).as_deref() != Some("iso") {
|
||||
if p.extension()
|
||||
.and_then(|e| e.to_str())
|
||||
.map(str::to_ascii_lowercase)
|
||||
.as_deref()
|
||||
!= Some("iso")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
let filename = p
|
||||
@@ -226,8 +235,14 @@ async fn seed_from_dir(src: &std::path::Path, config: &Config, dry_run: bool) ->
|
||||
.and_then(|s| s.to_str())
|
||||
.ok_or_else(|| anyhow::anyhow!("non-utf8 filename: {}", p.display()))?
|
||||
.to_string();
|
||||
println!(" {} ({} bytes)", filename, tokio::fs::metadata(&p).await?.len());
|
||||
if dry_run { continue; }
|
||||
println!(
|
||||
" {} ({} bytes)",
|
||||
filename,
|
||||
tokio::fs::metadata(&p).await?.len()
|
||||
);
|
||||
if dry_run {
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut handle = match store.begin_upload(&filename).await {
|
||||
Ok(h) => h,
|
||||
@@ -242,15 +257,23 @@ async fn seed_from_dir(src: &std::path::Path, config: &Config, dry_run: bool) ->
|
||||
let mut buf = vec![0u8; 1024 * 1024];
|
||||
loop {
|
||||
let n = file.read(&mut buf).await?;
|
||||
if n == 0 { break; }
|
||||
if n == 0 {
|
||||
break;
|
||||
}
|
||||
let chunk: bytes::Bytes = buf[..n].to_vec().into();
|
||||
handle.write_chunk(&chunk).await?;
|
||||
}
|
||||
let meta = handle.finish(&store).await?;
|
||||
println!(" -> id={} family={:?}", meta.id, meta.introspection.family);
|
||||
println!(
|
||||
" -> id={} family={:?}",
|
||||
meta.id, meta.introspection.family
|
||||
);
|
||||
imported += 1;
|
||||
}
|
||||
println!("\nimported={imported} skipped={skipped} {}", if dry_run { "(dry run)" } else { "" });
|
||||
println!(
|
||||
"\nimported={imported} skipped={skipped} {}",
|
||||
if dry_run { "(dry run)" } else { "" }
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -294,9 +317,8 @@ fn hostname() -> std::io::Result<String> {
|
||||
if let Ok(h) = std::fs::read_to_string("/proc/sys/kernel/hostname") {
|
||||
return Ok(h.trim().to_string());
|
||||
}
|
||||
std::env::var("HOSTNAME").map_err(|_| std::io::Error::new(
|
||||
std::io::ErrorKind::NotFound, "no hostname",
|
||||
))
|
||||
std::env::var("HOSTNAME")
|
||||
.map_err(|_| std::io::Error::new(std::io::ErrorKind::NotFound, "no hostname"))
|
||||
}
|
||||
|
||||
fn init_tracing(bus: Arc<LogBus>) {
|
||||
@@ -328,7 +350,10 @@ fn detect_network_info(our_ip: Ipv4Addr) -> NetworkInfo {
|
||||
|
||||
// `ip -o -f inet addr show` lists every interface with its
|
||||
// `inet a.b.c.d/mask`. We match the line that mentions our IP.
|
||||
if let Ok(out) = Command::new("ip").args(["-o", "-f", "inet", "addr", "show"]).output() {
|
||||
if let Ok(out) = Command::new("ip")
|
||||
.args(["-o", "-f", "inet", "addr", "show"])
|
||||
.output()
|
||||
{
|
||||
if let Ok(text) = String::from_utf8(out.stdout) {
|
||||
for line in text.lines() {
|
||||
if !line.contains(&our_ip.to_string()) {
|
||||
@@ -353,7 +378,10 @@ fn detect_network_info(our_ip: Ipv4Addr) -> NetworkInfo {
|
||||
}
|
||||
|
||||
// `ip route show default` -> "default via 10.0.0.1 dev enp1s0 ..."
|
||||
if let Ok(out) = Command::new("ip").args(["route", "show", "default"]).output() {
|
||||
if let Ok(out) = Command::new("ip")
|
||||
.args(["route", "show", "default"])
|
||||
.output()
|
||||
{
|
||||
if let Ok(text) = String::from_utf8(out.stdout) {
|
||||
if let Some(line) = text.lines().next() {
|
||||
let mut parts = line.split_whitespace();
|
||||
@@ -374,7 +402,11 @@ fn detect_network_info(our_ip: Ipv4Addr) -> NetworkInfo {
|
||||
|
||||
fn prefix_to_dotted(prefix: u8) -> String {
|
||||
let prefix = prefix.min(32);
|
||||
let mask: u32 = if prefix == 0 { 0 } else { u32::MAX << (32 - prefix) };
|
||||
let mask: u32 = if prefix == 0 {
|
||||
0
|
||||
} else {
|
||||
u32::MAX << (32 - prefix)
|
||||
};
|
||||
format!(
|
||||
"{}.{}.{}.{}",
|
||||
(mask >> 24) & 0xff,
|
||||
|
||||
Reference in New Issue
Block a user