generated from Patagia/template-nix
Compare commits
3 commits
6899ba21ad
...
d545425128
Author | SHA1 | Date | |
---|---|---|---|
d545425128 | |||
8e99ab4555 | |||
eb8926c091 |
10 changed files with 1018 additions and 173 deletions
481
Cargo.lock
generated
481
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -4,6 +4,7 @@ members = [
|
|||
"agent",
|
||||
"controller",
|
||||
"instrumentation",
|
||||
"hostd",
|
||||
"trace-request",
|
||||
"xtask",
|
||||
]
|
||||
|
@ -24,7 +25,7 @@ name = "patagia-run"
|
|||
|
||||
[workspace.dependencies]
|
||||
anyhow = "1.0.95"
|
||||
clap = { version = "4.5.23", features = [
|
||||
clap = { version = "4.5.26", features = [
|
||||
"derive",
|
||||
"deprecated",
|
||||
"env",
|
||||
|
@ -35,14 +36,14 @@ dropshot = "0.15.1"
|
|||
futures = "0.3"
|
||||
http = "1.2.0"
|
||||
once_cell = "1.20.2"
|
||||
progenitor = "0.8.0"
|
||||
progenitor = "0.9"
|
||||
reqwest = { version = "0.12.12", features = ["json", "stream", "rustls-tls"] }
|
||||
schemars = "0.8.21"
|
||||
semver = "1.0.24"
|
||||
serde = { version = "1.0.217", features = ["derive"] }
|
||||
slog = "2.7.0"
|
||||
slog-async = "2.8.0"
|
||||
tokio = { version = "1.42.0", features = ["full"] }
|
||||
tokio = { version = "1.43.0", features = ["full"] }
|
||||
tracing = "0.1.41"
|
||||
tracing-core = "0.1.33"
|
||||
tracing-chrome = "0.7.2"
|
||||
|
|
1
hostd/.gitignore
vendored
Normal file
1
hostd/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
15
hostd/Cargo.toml
Normal file
15
hostd/Cargo.toml
Normal file
|
@ -0,0 +1,15 @@
|
|||
[package]
|
||||
name = "hostd"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
serde.workspace = true
|
||||
serde_derive = "1.0.217"
|
||||
serde_json = "1.0.135"
|
||||
tokio.workspace = true
|
||||
varlink = "11.0.1"
|
||||
|
||||
[build-dependencies]
|
||||
varlink_generator = "10.1.0"
|
6
hostd/build.rs
Normal file
6
hostd/build.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
extern crate varlink_generator;
|
||||
|
||||
fn main() {
|
||||
varlink_generator::cargo_build_tosource("src/io.systemd.Hostname.varlink", true);
|
||||
varlink_generator::cargo_build_tosource("src/io.patagia.Hostd.varlink", true);
|
||||
}
|
27
hostd/src/io.patagia.Hostd.varlink
Normal file
27
hostd/src/io.patagia.Hostd.varlink
Normal file
|
@ -0,0 +1,27 @@
|
|||
interface io.patagia.Hostd
|
||||
|
||||
type Label (
|
||||
key: string,
|
||||
value: string
|
||||
)
|
||||
|
||||
type PatagiaAgentConfig (
|
||||
url: string,
|
||||
extraMounts: [string]string
|
||||
)
|
||||
|
||||
type Machine(
|
||||
machineId: string,
|
||||
nodeLabels: ?[]Label,
|
||||
patagiaAgent: ?PatagiaAgentConfig
|
||||
)
|
||||
|
||||
method Describe() -> (
|
||||
machine: Machine
|
||||
)
|
||||
|
||||
method Apply(
|
||||
machine: Machine
|
||||
) -> ()
|
||||
|
||||
error InvalidMachineConfig()
|
32
hostd/src/io.systemd.Hostname.varlink
Normal file
32
hostd/src/io.systemd.Hostname.varlink
Normal file
|
@ -0,0 +1,32 @@
|
|||
interface io.systemd.Hostname
|
||||
|
||||
method Describe() -> (
|
||||
Hostname: string,
|
||||
StaticHostname: ?string,
|
||||
PrettyHostname: ?string,
|
||||
DefaultHostname: ?string,
|
||||
HostnameSource: string,
|
||||
IconName: ?string,
|
||||
Chassis: ?string,
|
||||
Deployment: ?string,
|
||||
Location: ?string,
|
||||
KernelName: string,
|
||||
KernelRelease: string,
|
||||
KernelVersion: string,
|
||||
OperatingSystemPrettyName: ?string,
|
||||
OperatingSystemCPEName: ?string,
|
||||
OperatingSystemHomeURL: ?string,
|
||||
OperatingSystemSupportEnd: ?int,
|
||||
OperatingSystemReleaseData: ?[]string,
|
||||
MachineInformationData: ?[]string,
|
||||
HardwareVendor: ?string,
|
||||
HardwareModel: ?string,
|
||||
HardwareSerial: ?string,
|
||||
FirmwareVersion: ?string,
|
||||
FirmwareVendor: ?string,
|
||||
FirmwareDate: ?int,
|
||||
MachineID: string,
|
||||
BootID: string,
|
||||
ProductUUID: ?string,
|
||||
VSockCID: ?int
|
||||
)
|
264
hostd/src/io_patagia_Hostd.rs
Normal file
264
hostd/src/io_patagia_Hostd.rs
Normal file
|
@ -0,0 +1,264 @@
|
|||
#![doc = "This file was automatically generated by the varlink rust generator"]
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(non_snake_case)]
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::io::BufRead;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use varlink::{self, CallTrait};
|
||||
#[allow(dead_code)]
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
#[allow(clippy::enum_variant_names)]
|
||||
pub enum ErrorKind {
|
||||
Varlink_Error,
|
||||
VarlinkReply_Error,
|
||||
InvalidMachineConfig(Option<InvalidMachineConfig_Args>),
|
||||
}
|
||||
impl ::std::fmt::Display for ErrorKind {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||
match self {
|
||||
ErrorKind::Varlink_Error => write!(f, "Varlink Error"),
|
||||
ErrorKind::VarlinkReply_Error => write!(f, "Varlink error reply"),
|
||||
ErrorKind::InvalidMachineConfig(v) => {
|
||||
write!(f, "io.patagia.Hostd.InvalidMachineConfig: {:#?}", v)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pub struct Error(
|
||||
pub ErrorKind,
|
||||
pub Option<Box<dyn std::error::Error + 'static + Send + Sync>>,
|
||||
pub Option<&'static str>,
|
||||
);
|
||||
impl Error {
|
||||
#[allow(dead_code)]
|
||||
pub fn kind(&self) -> &ErrorKind {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
impl From<ErrorKind> for Error {
|
||||
fn from(e: ErrorKind) -> Self {
|
||||
Error(e, None, None)
|
||||
}
|
||||
}
|
||||
impl std::error::Error for Error {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
self.1
|
||||
.as_ref()
|
||||
.map(|e| e.as_ref() as &(dyn std::error::Error + 'static))
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(&self.0, f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Debug for Error {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
use std::error::Error as StdError;
|
||||
if let Some(ref o) = self.2 {
|
||||
std::fmt::Display::fmt(o, f)?;
|
||||
}
|
||||
std::fmt::Debug::fmt(&self.0, f)?;
|
||||
if let Some(e) = self.source() {
|
||||
std::fmt::Display::fmt("\nCaused by:\n", f)?;
|
||||
std::fmt::Debug::fmt(&e, f)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
impl From<varlink::Error> for Error {
|
||||
fn from(e: varlink::Error) -> Self {
|
||||
match e.kind() {
|
||||
varlink::ErrorKind::VarlinkErrorReply(r) => Error(
|
||||
ErrorKind::from(r),
|
||||
Some(Box::from(e)),
|
||||
Some(concat!(file!(), ":", line!(), ": ")),
|
||||
),
|
||||
_ => Error(
|
||||
ErrorKind::Varlink_Error,
|
||||
Some(Box::from(e)),
|
||||
Some(concat!(file!(), ":", line!(), ": ")),
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
impl Error {
|
||||
pub fn source_varlink_kind(&self) -> Option<&varlink::ErrorKind> {
|
||||
use std::error::Error as StdError;
|
||||
let mut s: &dyn StdError = self;
|
||||
while let Some(c) = s.source() {
|
||||
let k = self
|
||||
.source()
|
||||
.and_then(|e| e.downcast_ref::<varlink::Error>())
|
||||
.map(|e| e.kind());
|
||||
if k.is_some() {
|
||||
return k;
|
||||
}
|
||||
s = c;
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
impl From<&varlink::Reply> for ErrorKind {
|
||||
#[allow(unused_variables)]
|
||||
fn from(e: &varlink::Reply) -> Self {
|
||||
match e {
|
||||
varlink::Reply {
|
||||
error: Some(ref t), ..
|
||||
} if t == "io.patagia.Hostd.InvalidMachineConfig" => match e {
|
||||
varlink::Reply {
|
||||
parameters: Some(p),
|
||||
..
|
||||
} => match serde_json::from_value(p.clone()) {
|
||||
Ok(v) => ErrorKind::InvalidMachineConfig(v),
|
||||
Err(_) => ErrorKind::InvalidMachineConfig(None),
|
||||
},
|
||||
_ => ErrorKind::InvalidMachineConfig(None),
|
||||
},
|
||||
_ => ErrorKind::VarlinkReply_Error,
|
||||
}
|
||||
}
|
||||
}
|
||||
pub trait VarlinkCallError: varlink::CallTrait {
|
||||
fn reply_invalid_machine_config(&mut self) -> varlink::Result<()> {
|
||||
self.reply_struct(varlink::Reply::error(
|
||||
"io.patagia.Hostd.InvalidMachineConfig",
|
||||
None,
|
||||
))
|
||||
}
|
||||
}
|
||||
impl<'a> VarlinkCallError for varlink::Call<'a> {}
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
|
||||
pub struct r#Label {
|
||||
pub r#key: String,
|
||||
pub r#value: String,
|
||||
}
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
|
||||
pub struct r#Machine {
|
||||
pub r#machineId: String,
|
||||
pub r#nodeLabels: Option<Vec<Label>>,
|
||||
pub r#patagiaAgent: Option<PatagiaAgentConfig>,
|
||||
}
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
|
||||
pub struct r#PatagiaAgentConfig {
|
||||
pub r#url: String,
|
||||
pub r#extraMounts: varlink::StringHashMap<String>,
|
||||
}
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
|
||||
pub struct InvalidMachineConfig_Args {}
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
|
||||
pub struct Apply_Reply {}
|
||||
impl varlink::VarlinkReply for Apply_Reply {}
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
|
||||
pub struct Apply_Args {
|
||||
pub r#machine: Machine,
|
||||
}
|
||||
pub trait Call_Apply: VarlinkCallError {
|
||||
fn reply(&mut self) -> varlink::Result<()> {
|
||||
self.reply_struct(varlink::Reply::parameters(None))
|
||||
}
|
||||
}
|
||||
impl<'a> Call_Apply for varlink::Call<'a> {}
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
|
||||
pub struct Describe_Reply {
|
||||
pub r#machine: Machine,
|
||||
}
|
||||
impl varlink::VarlinkReply for Describe_Reply {}
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
|
||||
pub struct Describe_Args {}
|
||||
pub trait Call_Describe: VarlinkCallError {
|
||||
fn reply(&mut self, r#machine: Machine) -> varlink::Result<()> {
|
||||
self.reply_struct(Describe_Reply { r#machine }.into())
|
||||
}
|
||||
}
|
||||
impl<'a> Call_Describe for varlink::Call<'a> {}
|
||||
pub trait VarlinkInterface {
|
||||
fn apply(&self, call: &mut dyn Call_Apply, r#machine: Machine) -> varlink::Result<()>;
|
||||
fn describe(&self, call: &mut dyn Call_Describe) -> varlink::Result<()>;
|
||||
fn call_upgraded(
|
||||
&self,
|
||||
_call: &mut varlink::Call,
|
||||
_bufreader: &mut dyn BufRead,
|
||||
) -> varlink::Result<Vec<u8>> {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
}
|
||||
pub trait VarlinkClientInterface {
|
||||
fn apply(&mut self, r#machine: Machine) -> varlink::MethodCall<Apply_Args, Apply_Reply, Error>;
|
||||
fn describe(&mut self) -> varlink::MethodCall<Describe_Args, Describe_Reply, Error>;
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
pub struct VarlinkClient {
|
||||
connection: Arc<RwLock<varlink::Connection>>,
|
||||
}
|
||||
impl VarlinkClient {
|
||||
#[allow(dead_code)]
|
||||
pub fn new(connection: Arc<RwLock<varlink::Connection>>) -> Self {
|
||||
VarlinkClient { connection }
|
||||
}
|
||||
}
|
||||
impl VarlinkClientInterface for VarlinkClient {
|
||||
fn apply(&mut self, r#machine: Machine) -> varlink::MethodCall<Apply_Args, Apply_Reply, Error> {
|
||||
varlink::MethodCall::<Apply_Args, Apply_Reply, Error>::new(
|
||||
self.connection.clone(),
|
||||
"io.patagia.Hostd.Apply",
|
||||
Apply_Args { r#machine },
|
||||
)
|
||||
}
|
||||
fn describe(&mut self) -> varlink::MethodCall<Describe_Args, Describe_Reply, Error> {
|
||||
varlink::MethodCall::<Describe_Args, Describe_Reply, Error>::new(
|
||||
self.connection.clone(),
|
||||
"io.patagia.Hostd.Describe",
|
||||
Describe_Args {},
|
||||
)
|
||||
}
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
pub struct VarlinkInterfaceProxy {
|
||||
inner: Box<dyn VarlinkInterface + Send + Sync>,
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
pub fn new(inner: Box<dyn VarlinkInterface + Send + Sync>) -> VarlinkInterfaceProxy {
|
||||
VarlinkInterfaceProxy { inner }
|
||||
}
|
||||
impl varlink::Interface for VarlinkInterfaceProxy {
|
||||
fn get_description(&self) -> &'static str {
|
||||
"interface io.patagia.Hostd\n\ntype Label (\n key: string,\n value: string\n)\n\ntype PatagiaAgentConfig (\n url: string,\n extraMounts: [string]string\n)\n\ntype Machine(\n machineId: string,\n nodeLabels: ?[]Label,\n patagiaAgent: ?PatagiaAgentConfig\n)\n\nmethod Describe() -> (\n machine: Machine\n)\n\nmethod Apply(\n machine: Machine\n) -> ()\n\nerror InvalidMachineConfig()\n"
|
||||
}
|
||||
fn get_name(&self) -> &'static str {
|
||||
"io.patagia.Hostd"
|
||||
}
|
||||
fn call_upgraded(
|
||||
&self,
|
||||
call: &mut varlink::Call,
|
||||
bufreader: &mut dyn BufRead,
|
||||
) -> varlink::Result<Vec<u8>> {
|
||||
self.inner.call_upgraded(call, bufreader)
|
||||
}
|
||||
fn call(&self, call: &mut varlink::Call) -> varlink::Result<()> {
|
||||
let req = call.request.unwrap();
|
||||
match req.method.as_ref() {
|
||||
"io.patagia.Hostd.Apply" => {
|
||||
if let Some(args) = req.parameters.clone() {
|
||||
let args: Apply_Args = match serde_json::from_value(args) {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
let es = format!("{}", e);
|
||||
let _ = call.reply_invalid_parameter(es.clone());
|
||||
return Err(varlink::context!(varlink::ErrorKind::SerdeJsonDe(es)));
|
||||
}
|
||||
};
|
||||
self.inner
|
||||
.apply(call as &mut dyn Call_Apply, args.r#machine)
|
||||
} else {
|
||||
call.reply_invalid_parameter("parameters".into())
|
||||
}
|
||||
}
|
||||
"io.patagia.Hostd.Describe" => self.inner.describe(call as &mut dyn Call_Describe),
|
||||
m => call.reply_method_not_found(String::from(m)),
|
||||
}
|
||||
}
|
||||
}
|
295
hostd/src/io_systemd_Hostname.rs
Normal file
295
hostd/src/io_systemd_Hostname.rs
Normal file
|
@ -0,0 +1,295 @@
|
|||
#![doc = "This file was automatically generated by the varlink rust generator"]
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(non_snake_case)]
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::io::BufRead;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use varlink::{self, CallTrait};
|
||||
#[allow(dead_code)]
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
#[allow(clippy::enum_variant_names)]
|
||||
pub enum ErrorKind {
|
||||
Varlink_Error,
|
||||
VarlinkReply_Error,
|
||||
}
|
||||
impl ::std::fmt::Display for ErrorKind {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||
match self {
|
||||
ErrorKind::Varlink_Error => write!(f, "Varlink Error"),
|
||||
ErrorKind::VarlinkReply_Error => write!(f, "Varlink error reply"),
|
||||
}
|
||||
}
|
||||
}
|
||||
pub struct Error(
|
||||
pub ErrorKind,
|
||||
pub Option<Box<dyn std::error::Error + 'static + Send + Sync>>,
|
||||
pub Option<&'static str>,
|
||||
);
|
||||
impl Error {
|
||||
#[allow(dead_code)]
|
||||
pub fn kind(&self) -> &ErrorKind {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
impl From<ErrorKind> for Error {
|
||||
fn from(e: ErrorKind) -> Self {
|
||||
Error(e, None, None)
|
||||
}
|
||||
}
|
||||
impl std::error::Error for Error {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
self.1
|
||||
.as_ref()
|
||||
.map(|e| e.as_ref() as &(dyn std::error::Error + 'static))
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(&self.0, f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Debug for Error {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
use std::error::Error as StdError;
|
||||
if let Some(ref o) = self.2 {
|
||||
std::fmt::Display::fmt(o, f)?;
|
||||
}
|
||||
std::fmt::Debug::fmt(&self.0, f)?;
|
||||
if let Some(e) = self.source() {
|
||||
std::fmt::Display::fmt("\nCaused by:\n", f)?;
|
||||
std::fmt::Debug::fmt(&e, f)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
impl From<varlink::Error> for Error {
|
||||
fn from(e: varlink::Error) -> Self {
|
||||
match e.kind() {
|
||||
varlink::ErrorKind::VarlinkErrorReply(r) => Error(
|
||||
ErrorKind::from(r),
|
||||
Some(Box::from(e)),
|
||||
Some(concat!(file!(), ":", line!(), ": ")),
|
||||
),
|
||||
_ => Error(
|
||||
ErrorKind::Varlink_Error,
|
||||
Some(Box::from(e)),
|
||||
Some(concat!(file!(), ":", line!(), ": ")),
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
impl Error {
|
||||
pub fn source_varlink_kind(&self) -> Option<&varlink::ErrorKind> {
|
||||
use std::error::Error as StdError;
|
||||
let mut s: &dyn StdError = self;
|
||||
while let Some(c) = s.source() {
|
||||
let k = self
|
||||
.source()
|
||||
.and_then(|e| e.downcast_ref::<varlink::Error>())
|
||||
.map(|e| e.kind());
|
||||
if k.is_some() {
|
||||
return k;
|
||||
}
|
||||
s = c;
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
impl From<&varlink::Reply> for ErrorKind {
|
||||
#[allow(unused_variables)]
|
||||
fn from(e: &varlink::Reply) -> Self {
|
||||
match e {
|
||||
_ => ErrorKind::VarlinkReply_Error,
|
||||
}
|
||||
}
|
||||
}
|
||||
pub trait VarlinkCallError: varlink::CallTrait {}
|
||||
impl<'a> VarlinkCallError for varlink::Call<'a> {}
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
|
||||
pub struct Describe_Reply {
|
||||
pub r#Hostname: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#StaticHostname: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#PrettyHostname: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#DefaultHostname: Option<String>,
|
||||
pub r#HostnameSource: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#IconName: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#Chassis: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#Deployment: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#Location: Option<String>,
|
||||
pub r#KernelName: String,
|
||||
pub r#KernelRelease: String,
|
||||
pub r#KernelVersion: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#OperatingSystemPrettyName: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#OperatingSystemCPEName: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#OperatingSystemHomeURL: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#OperatingSystemSupportEnd: Option<i64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#OperatingSystemReleaseData: Option<Vec<String>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#MachineInformationData: Option<Vec<String>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#HardwareVendor: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#HardwareModel: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#HardwareSerial: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#FirmwareVersion: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#FirmwareVendor: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#FirmwareDate: Option<i64>,
|
||||
pub r#MachineID: String,
|
||||
pub r#BootID: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#ProductUUID: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#VSockCID: Option<i64>,
|
||||
}
|
||||
impl varlink::VarlinkReply for Describe_Reply {}
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
|
||||
pub struct Describe_Args {}
|
||||
pub trait Call_Describe: VarlinkCallError {
|
||||
fn reply(
|
||||
&mut self,
|
||||
r#Hostname: String,
|
||||
r#StaticHostname: Option<String>,
|
||||
r#PrettyHostname: Option<String>,
|
||||
r#DefaultHostname: Option<String>,
|
||||
r#HostnameSource: String,
|
||||
r#IconName: Option<String>,
|
||||
r#Chassis: Option<String>,
|
||||
r#Deployment: Option<String>,
|
||||
r#Location: Option<String>,
|
||||
r#KernelName: String,
|
||||
r#KernelRelease: String,
|
||||
r#KernelVersion: String,
|
||||
r#OperatingSystemPrettyName: Option<String>,
|
||||
r#OperatingSystemCPEName: Option<String>,
|
||||
r#OperatingSystemHomeURL: Option<String>,
|
||||
r#OperatingSystemSupportEnd: Option<i64>,
|
||||
r#OperatingSystemReleaseData: Option<Vec<String>>,
|
||||
r#MachineInformationData: Option<Vec<String>>,
|
||||
r#HardwareVendor: Option<String>,
|
||||
r#HardwareModel: Option<String>,
|
||||
r#HardwareSerial: Option<String>,
|
||||
r#FirmwareVersion: Option<String>,
|
||||
r#FirmwareVendor: Option<String>,
|
||||
r#FirmwareDate: Option<i64>,
|
||||
r#MachineID: String,
|
||||
r#BootID: String,
|
||||
r#ProductUUID: Option<String>,
|
||||
r#VSockCID: Option<i64>,
|
||||
) -> varlink::Result<()> {
|
||||
self.reply_struct(
|
||||
Describe_Reply {
|
||||
r#Hostname,
|
||||
r#StaticHostname,
|
||||
r#PrettyHostname,
|
||||
r#DefaultHostname,
|
||||
r#HostnameSource,
|
||||
r#IconName,
|
||||
r#Chassis,
|
||||
r#Deployment,
|
||||
r#Location,
|
||||
r#KernelName,
|
||||
r#KernelRelease,
|
||||
r#KernelVersion,
|
||||
r#OperatingSystemPrettyName,
|
||||
r#OperatingSystemCPEName,
|
||||
r#OperatingSystemHomeURL,
|
||||
r#OperatingSystemSupportEnd,
|
||||
r#OperatingSystemReleaseData,
|
||||
r#MachineInformationData,
|
||||
r#HardwareVendor,
|
||||
r#HardwareModel,
|
||||
r#HardwareSerial,
|
||||
r#FirmwareVersion,
|
||||
r#FirmwareVendor,
|
||||
r#FirmwareDate,
|
||||
r#MachineID,
|
||||
r#BootID,
|
||||
r#ProductUUID,
|
||||
r#VSockCID,
|
||||
}
|
||||
.into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
impl<'a> Call_Describe for varlink::Call<'a> {}
|
||||
pub trait VarlinkInterface {
|
||||
fn describe(&self, call: &mut dyn Call_Describe) -> varlink::Result<()>;
|
||||
fn call_upgraded(
|
||||
&self,
|
||||
_call: &mut varlink::Call,
|
||||
_bufreader: &mut dyn BufRead,
|
||||
) -> varlink::Result<Vec<u8>> {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
}
|
||||
pub trait VarlinkClientInterface {
|
||||
fn describe(&mut self) -> varlink::MethodCall<Describe_Args, Describe_Reply, Error>;
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
pub struct VarlinkClient {
|
||||
connection: Arc<RwLock<varlink::Connection>>,
|
||||
}
|
||||
impl VarlinkClient {
|
||||
#[allow(dead_code)]
|
||||
pub fn new(connection: Arc<RwLock<varlink::Connection>>) -> Self {
|
||||
VarlinkClient { connection }
|
||||
}
|
||||
}
|
||||
impl VarlinkClientInterface for VarlinkClient {
|
||||
fn describe(&mut self) -> varlink::MethodCall<Describe_Args, Describe_Reply, Error> {
|
||||
varlink::MethodCall::<Describe_Args, Describe_Reply, Error>::new(
|
||||
self.connection.clone(),
|
||||
"io.systemd.Hostname.Describe",
|
||||
Describe_Args {},
|
||||
)
|
||||
}
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
pub struct VarlinkInterfaceProxy {
|
||||
inner: Box<dyn VarlinkInterface + Send + Sync>,
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
pub fn new(inner: Box<dyn VarlinkInterface + Send + Sync>) -> VarlinkInterfaceProxy {
|
||||
VarlinkInterfaceProxy { inner }
|
||||
}
|
||||
impl varlink::Interface for VarlinkInterfaceProxy {
|
||||
fn get_description(&self) -> &'static str {
|
||||
"interface io.systemd.Hostname\n\nmethod Describe() -> (\n\tHostname: string,\n\tStaticHostname: ?string,\n\tPrettyHostname: ?string,\n\tDefaultHostname: ?string,\n\tHostnameSource: string,\n\tIconName: ?string,\n\tChassis: ?string,\n\tDeployment: ?string,\n\tLocation: ?string,\n\tKernelName: string,\n\tKernelRelease: string,\n\tKernelVersion: string,\n\tOperatingSystemPrettyName: ?string,\n\tOperatingSystemCPEName: ?string,\n\tOperatingSystemHomeURL: ?string,\n\tOperatingSystemSupportEnd: ?int,\n\tOperatingSystemReleaseData: ?[]string,\n\tMachineInformationData: ?[]string,\n\tHardwareVendor: ?string,\n\tHardwareModel: ?string,\n\tHardwareSerial: ?string,\n\tFirmwareVersion: ?string,\n\tFirmwareVendor: ?string,\n\tFirmwareDate: ?int,\n\tMachineID: string,\n\tBootID: string,\n\tProductUUID: ?string,\n\tVSockCID: ?int\n)\n"
|
||||
}
|
||||
fn get_name(&self) -> &'static str {
|
||||
"io.systemd.Hostname"
|
||||
}
|
||||
fn call_upgraded(
|
||||
&self,
|
||||
call: &mut varlink::Call,
|
||||
bufreader: &mut dyn BufRead,
|
||||
) -> varlink::Result<Vec<u8>> {
|
||||
self.inner.call_upgraded(call, bufreader)
|
||||
}
|
||||
fn call(&self, call: &mut varlink::Call) -> varlink::Result<()> {
|
||||
let req = call.request.unwrap();
|
||||
match req.method.as_ref() {
|
||||
"io.systemd.Hostname.Describe" => self.inner.describe(call as &mut dyn Call_Describe),
|
||||
m => call.reply_method_not_found(String::from(m)),
|
||||
}
|
||||
}
|
||||
}
|
63
hostd/src/main.rs
Normal file
63
hostd/src/main.rs
Normal file
|
@ -0,0 +1,63 @@
|
|||
use std::{collections::HashMap, process::exit};
|
||||
|
||||
use crate::io_patagia_Hostd::{
|
||||
Call_Apply, Call_Describe, Label, Machine, PatagiaAgentConfig, VarlinkInterface,
|
||||
};
|
||||
|
||||
mod io_patagia_Hostd;
|
||||
|
||||
const LISTEN_ADDRESS: &str = "unix:/tmp/io.patagia.Hostd";
|
||||
|
||||
struct Hostd;
|
||||
|
||||
impl VarlinkInterface for Hostd {
|
||||
fn apply(&self, call: &mut dyn Call_Apply, machine: Machine) -> varlink::Result<()> {
|
||||
println!("Machine: {:#?}", machine);
|
||||
return call.reply();
|
||||
}
|
||||
|
||||
fn describe(&self, call: &mut dyn Call_Describe) -> varlink::Result<()> {
|
||||
let machine = Machine {
|
||||
machineId: "1".to_string(),
|
||||
nodeLabels: Option::from(vec![Label {
|
||||
key: "key".to_string(),
|
||||
value: "value".to_string(),
|
||||
}]),
|
||||
patagiaAgent: Option::from(PatagiaAgentConfig {
|
||||
url: "https://cdn.patagia.dev/patagia-agent/stable".to_string(),
|
||||
extraMounts: HashMap::new(),
|
||||
}),
|
||||
};
|
||||
return call.reply(machine);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let hostd = Hostd;
|
||||
let hostd_interface = 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_interface)],
|
||||
);
|
||||
let ret: Result<(), varlink::Error> = varlink::listen(
|
||||
svc,
|
||||
LISTEN_ADDRESS,
|
||||
&varlink::ListenConfig {
|
||||
// Listen forever (0 = forever)
|
||||
idle_timeout: 0,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
|
||||
exit(match ret {
|
||||
Ok(_) => 0,
|
||||
Err(e) => {
|
||||
println!("Error: {}", e);
|
||||
1
|
||||
}
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue