feat(hostd): varlink interfaced host controller to manage machine configuration and boot mgmt

This commit is contained in:
Lars Sjöström 2025-01-08 11:09:34 +01:00
parent 8e99ab4555
commit f8c7dc96a2
No known key found for this signature in database
16 changed files with 968 additions and 51 deletions

1
hostd/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

9
hostd/Cargo.toml Normal file
View file

@ -0,0 +1,9 @@
[package]
name = "hostd"
version.workspace = true
edition.workspace = true
[dependencies]
anyhow.workspace = true
varlink = "11.0.1"
internal = { path = "../internal" }

60
hostd/src/main.rs Normal file
View file

@ -0,0 +1,60 @@
use anyhow::Result;
use internal::ipc::patagia::io_patagia_hostd::{
Call_Apply, Call_Describe, Machine, VarlinkInterface,
};
const LISTEN_ADDRESS: &str = "unix:/tmp/patagia/io.patagia.hostd";
struct PatagiaHostd;
impl VarlinkInterface for PatagiaHostd {
fn apply(&self, call: &mut dyn Call_Apply, machine: Machine) -> varlink::Result<()> {
// FIXME: Do something useful
println!("Applying machine config: {:#?}", machine);
call.reply()
}
fn describe(&self, call: &mut dyn Call_Describe) -> varlink::Result<()> {
// FIXME: Do something useful
let machine = Machine {
machineId: "123456789".to_string(),
nodeLabels: None,
patagiaAgent: None,
};
call.reply(machine)
}
}
fn main() -> Result<()> {
let hostd = PatagiaHostd;
let hostd_iface = internal::ipc::patagia::io_patagia_hostd::new(Box::new(hostd));
let svc = varlink::VarlinkService::new(
"io.patagia.hostd",
"Host controller for patagia",
"0.1",
"https://patagia.dev",
vec![Box::new(hostd_iface)],
);
let addr_path = std::path::Path::new(LISTEN_ADDRESS.strip_prefix("unix:").unwrap())
.parent()
.unwrap();
std::fs::create_dir_all(addr_path)?;
println!("Varlink Listening on {}", LISTEN_ADDRESS);
varlink::listen(
svc,
LISTEN_ADDRESS,
&varlink::ListenConfig {
// Listen forever (0 = forever)
idle_timeout: 0,
..Default::default()
},
)?;
Ok(())
}