generated from Patagia/template-nix
Compare commits
1 commit
d545425128
...
54c1cca8c8
Author | SHA1 | Date | |
---|---|---|---|
54c1cca8c8 |
6 changed files with 45 additions and 37 deletions
|
@ -1,6 +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);
|
||||
varlink_generator::cargo_build_tosource("src/io.systemd.hostname.varlink", true);
|
||||
varlink_generator::cargo_build_tosource("src/io.patagia.hostd.varlink", true);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
interface io.patagia.Hostd
|
||||
interface io.patagia.hostd
|
||||
|
||||
type Label (
|
||||
key: string,
|
||||
|
@ -6,8 +6,7 @@ type Label (
|
|||
)
|
||||
|
||||
type PatagiaAgentConfig (
|
||||
url: string,
|
||||
extraMounts: [string]string
|
||||
url: ?string
|
||||
)
|
||||
|
||||
type Machine(
|
|
@ -19,7 +19,7 @@ impl ::std::fmt::Display for ErrorKind {
|
|||
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)
|
||||
write!(f, "io.patagia.hostd.InvalidMachineConfig: {:#?}", v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ impl From<&varlink::Reply> for ErrorKind {
|
|||
match e {
|
||||
varlink::Reply {
|
||||
error: Some(ref t), ..
|
||||
} if t == "io.patagia.Hostd.InvalidMachineConfig" => match e {
|
||||
} if t == "io.patagia.hostd.InvalidMachineConfig" => match e {
|
||||
varlink::Reply {
|
||||
parameters: Some(p),
|
||||
..
|
||||
|
@ -125,7 +125,7 @@ impl From<&varlink::Reply> for ErrorKind {
|
|||
pub trait VarlinkCallError: varlink::CallTrait {
|
||||
fn reply_invalid_machine_config(&mut self) -> varlink::Result<()> {
|
||||
self.reply_struct(varlink::Reply::error(
|
||||
"io.patagia.Hostd.InvalidMachineConfig",
|
||||
"io.patagia.hostd.InvalidMachineConfig",
|
||||
None,
|
||||
))
|
||||
}
|
||||
|
@ -144,8 +144,7 @@ pub struct r#Machine {
|
|||
}
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
|
||||
pub struct r#PatagiaAgentConfig {
|
||||
pub r#url: String,
|
||||
pub r#extraMounts: varlink::StringHashMap<String>,
|
||||
pub r#url: Option<String>,
|
||||
}
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
|
||||
pub struct InvalidMachineConfig_Args {}
|
||||
|
@ -204,14 +203,14 @@ 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",
|
||||
"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",
|
||||
"io.patagia.hostd.Describe",
|
||||
Describe_Args {},
|
||||
)
|
||||
}
|
||||
|
@ -226,10 +225,10 @@ pub fn new(inner: Box<dyn VarlinkInterface + Send + Sync>) -> VarlinkInterfacePr
|
|||
}
|
||||
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"
|
||||
"interface io.patagia.hostd\n\ntype Label (\n key: string,\n value: string\n)\n\ntype PatagiaAgentConfig (\n url: ?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"
|
||||
"io.patagia.hostd"
|
||||
}
|
||||
fn call_upgraded(
|
||||
&self,
|
||||
|
@ -241,7 +240,7 @@ impl varlink::Interface for VarlinkInterfaceProxy {
|
|||
fn call(&self, call: &mut varlink::Call) -> varlink::Result<()> {
|
||||
let req = call.request.unwrap();
|
||||
match req.method.as_ref() {
|
||||
"io.patagia.Hostd.Apply" => {
|
||||
"io.patagia.hostd.Apply" => {
|
||||
if let Some(args) = req.parameters.clone() {
|
||||
let args: Apply_Args = match serde_json::from_value(args) {
|
||||
Ok(v) => v,
|
||||
|
@ -257,7 +256,7 @@ impl varlink::Interface for VarlinkInterfaceProxy {
|
|||
call.reply_invalid_parameter("parameters".into())
|
||||
}
|
||||
}
|
||||
"io.patagia.Hostd.Describe" => self.inner.describe(call as &mut dyn Call_Describe),
|
||||
"io.patagia.hostd.Describe" => self.inner.describe(call as &mut dyn Call_Describe),
|
||||
m => call.reply_method_not_found(String::from(m)),
|
||||
}
|
||||
}
|
|
@ -1,48 +1,57 @@
|
|||
use std::{collections::HashMap, process::exit};
|
||||
use std::process::exit;
|
||||
|
||||
use crate::io_patagia_Hostd::{
|
||||
use crate::io_patagia_hostd::{
|
||||
Call_Apply, Call_Describe, Label, Machine, PatagiaAgentConfig, VarlinkInterface,
|
||||
};
|
||||
|
||||
mod io_patagia_Hostd;
|
||||
mod io_patagia_hostd;
|
||||
|
||||
const LISTEN_ADDRESS: &str = "unix:/tmp/io.patagia.Hostd";
|
||||
const LISTEN_ADDRESS: &str = "unix:/tmp/io.patagia.hostd";
|
||||
|
||||
struct Hostd;
|
||||
struct PatagiaHostd;
|
||||
|
||||
impl VarlinkInterface for Hostd {
|
||||
impl VarlinkInterface for PatagiaHostd {
|
||||
fn apply(&self, call: &mut dyn Call_Apply, machine: Machine) -> varlink::Result<()> {
|
||||
println!("Machine: {:#?}", machine);
|
||||
return call.reply();
|
||||
// FIXME: Do something useful
|
||||
println!("Applying machine config: {:#?}", machine);
|
||||
call.reply()
|
||||
}
|
||||
|
||||
fn describe(&self, call: &mut dyn Call_Describe) -> varlink::Result<()> {
|
||||
// FIXME: Do something useful
|
||||
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(),
|
||||
machineId: "123456789".to_string(),
|
||||
nodeLabels: Some(vec![
|
||||
Label {
|
||||
key: "foo".to_string(),
|
||||
value: "bar".to_string(),
|
||||
},
|
||||
Label {
|
||||
key: "baz".to_string(),
|
||||
value: "quz".to_string(),
|
||||
},
|
||||
]),
|
||||
patagiaAgent: Some(PatagiaAgentConfig {
|
||||
url: None, // Some("https://cdn.patagia.dev/patagia-agent/stable".to_string()),
|
||||
}),
|
||||
};
|
||||
return call.reply(machine);
|
||||
call.reply(machine)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let hostd = Hostd;
|
||||
let hostd_interface = io_patagia_Hostd::new(Box::new(hostd));
|
||||
let hostd = PatagiaHostd;
|
||||
let hostd_iface = io_patagia_hostd::new(Box::new(hostd));
|
||||
|
||||
let svc = varlink::VarlinkService::new(
|
||||
"io.patagia.Hostd",
|
||||
"io.patagia.hostd",
|
||||
"Host controller for patagia",
|
||||
"0.1",
|
||||
"https://patagia.dev",
|
||||
vec![Box::new(hostd_interface)],
|
||||
vec![Box::new(hostd_iface)],
|
||||
);
|
||||
|
||||
println!("Varlink Listening on {}", LISTEN_ADDRESS);
|
||||
let ret: Result<(), varlink::Error> = varlink::listen(
|
||||
svc,
|
||||
LISTEN_ADDRESS,
|
||||
|
@ -53,6 +62,7 @@ fn main() {
|
|||
},
|
||||
);
|
||||
|
||||
// Exit with error code
|
||||
exit(match ret {
|
||||
Ok(_) => 0,
|
||||
Err(e) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue