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 d9472f8e3b
No known key found for this signature in database
16 changed files with 975 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" }

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

@ -0,0 +1,67 @@
use anyhow::Result;
use internal::ipc::patagia::io_patagia_hostd;
use internal::ipc::systemd::io_systemd_hostname::{self, VarlinkClientInterface};
const LISTEN_ADDRESS: &str = "unix:/tmp/patagia/io.patagia.hostd";
const SYSTEMD_ADDRESS: &str = "unix:/run/systemd/io.systemd.Hostname";
struct PatagiaHostd;
impl io_patagia_hostd::VarlinkInterface for PatagiaHostd {
fn apply(
&self,
call: &mut dyn io_patagia_hostd::Call_Apply,
machine: io_patagia_hostd::Machine,
) -> varlink::Result<()> {
// FIXME: Do something useful
println!("Applying machine config: {:#?}", machine);
call.reply()
}
fn describe(&self, call: &mut dyn io_patagia_hostd::Call_Describe) -> varlink::Result<()> {
// Connect to systemd.Hostname
let conn = varlink::Connection::with_address(SYSTEMD_ADDRESS).unwrap();
let mut sd = io_systemd_hostname::VarlinkClient::new(conn);
let machine = io_patagia_hostd::Machine {
machineId: sd.describe().call().unwrap().MachineID,
nodeLabels: None,
patagiaAgent: None,
};
call.reply(machine)
}
}
fn main() -> Result<()> {
let hostd = PatagiaHostd;
let hostd_iface = 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(())
}