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 d8c9107839
No known key found for this signature in database
18 changed files with 1012 additions and 51 deletions

1
hostd/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

10
hostd/Cargo.toml Normal file
View file

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

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

@ -0,0 +1,59 @@
use anyhow::Result;
use ipc::io_patagia_hostd;
use systemd_ipc::addrs::SYSTEMD_HOSTNAME;
use systemd_ipc::io_systemd_hostname::{self, VarlinkClientInterface};
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_HOSTNAME).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 = format!("unix:{}/{}", env!("XDG_RUNTIME_DIR"), "io.patagia.hostd");
println!("Varlink Listening on {}", addr);
varlink::listen(
svc,
&addr,
&varlink::ListenConfig {
..Default::default()
},
)?;
Ok(())
}