generated from Patagia/template-nix
This commit is contained in:
parent
8e99ab4555
commit
0e10762517
18 changed files with 1632 additions and 52 deletions
hostd/src
45
hostd/src/machine.rs
Normal file
45
hostd/src/machine.rs
Normal file
|
@ -0,0 +1,45 @@
|
|||
use dropshot::{endpoint, HttpError, HttpResponseOk, RequestContext};
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use std::sync::Arc;
|
||||
use trace_request::trace_request;
|
||||
|
||||
use crate::context::ControllerContext;
|
||||
|
||||
/// Machine information
|
||||
#[derive(Serialize, JsonSchema)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct MachineInfo {
|
||||
machine_id: String,
|
||||
}
|
||||
|
||||
/// Fetch machine info
|
||||
#[endpoint {
|
||||
method = GET,
|
||||
path = "/machine_info",
|
||||
}]
|
||||
#[trace_request]
|
||||
pub async fn describe(
|
||||
rqctx: RequestContext<Arc<ControllerContext>>,
|
||||
) -> Result<HttpResponseOk<MachineInfo>, HttpError> {
|
||||
let conn = zbus::Connection::system().await.unwrap();
|
||||
let manager = zbus_systemd::hostname1::HostnamedProxy::new(&conn)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let machine_id = manager
|
||||
.machine_id()
|
||||
.await
|
||||
.unwrap()
|
||||
// convert bytes to hex string
|
||||
.iter()
|
||||
.map(|&b| format!("{:02x}", b))
|
||||
.collect::<String>();
|
||||
|
||||
let machine_info = MachineInfo { machine_id };
|
||||
|
||||
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