generated from Patagia/template-nix
This commit is contained in:
parent
8e99ab4555
commit
f61563dcae
18 changed files with 1221 additions and 51 deletions
hostd/src
42
hostd/src/machine.rs
Normal file
42
hostd/src/machine.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
use dropshot::{endpoint, HttpError, HttpResponseOk, RequestContext};
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use std::sync::Arc;
|
||||
use trace_request::trace_request;
|
||||
|
||||
use systemd_ipc::addrs::SYSTEMD_HOSTNAME;
|
||||
use systemd_ipc::io_systemd_hostname::{self, VarlinkClientInterface};
|
||||
|
||||
use crate::context::ControllerContext;
|
||||
|
||||
/// Version and build information
|
||||
#[derive(Serialize, JsonSchema)]
|
||||
struct MachineInfo {
|
||||
machine_id: String,
|
||||
}
|
||||
|
||||
/// Fetch machine id
|
||||
#[endpoint {
|
||||
method = GET,
|
||||
path = "/machine_id",
|
||||
}]
|
||||
#[trace_request]
|
||||
pub async fn describe(
|
||||
rqctx: RequestContext<Arc<ControllerContext>>,
|
||||
) -> Result<HttpResponseOk<MachineInfo>, HttpError> {
|
||||
let machine_info = tokio::task::spawn_blocking(move || {
|
||||
// Connect to systemd.Hostname
|
||||
let conn = varlink::Connection::with_address(SYSTEMD_HOSTNAME).unwrap();
|
||||
let mut sd = io_systemd_hostname::VarlinkClient::new(conn);
|
||||
|
||||
let machine_id = sd.describe().call().unwrap().MachineID;
|
||||
MachineInfo { machine_id }
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
tracing::info_span!("Hello, span hostd!");
|
||||
|
||||
tracing::info!(monotonic_counter.version_calls = 1);
|
||||
Ok(HttpResponseOk(machine_info))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue