diff --git a/hostd/build.rs b/hostd/build.rs index bea0698..c12279a 100644 --- a/hostd/build.rs +++ b/hostd/build.rs @@ -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); } diff --git a/hostd/src/io.patagia.hostd.varlink b/hostd/src/io.patagia.Hostd.varlink similarity index 80% rename from hostd/src/io.patagia.hostd.varlink rename to hostd/src/io.patagia.Hostd.varlink index ea34a12..46123a8 100644 --- a/hostd/src/io.patagia.hostd.varlink +++ b/hostd/src/io.patagia.Hostd.varlink @@ -1,4 +1,4 @@ -interface io.patagia.hostd +interface io.patagia.Hostd type Label ( key: string, @@ -6,7 +6,8 @@ type Label ( ) type PatagiaAgentConfig ( - url: ?string + url: string, + extraMounts: [string]string ) type Machine( diff --git a/hostd/src/io.systemd.hostname.varlink b/hostd/src/io.systemd.Hostname.varlink similarity index 100% rename from hostd/src/io.systemd.hostname.varlink rename to hostd/src/io.systemd.Hostname.varlink diff --git a/hostd/src/io_patagia_hostd.rs b/hostd/src/io_patagia_Hostd.rs similarity index 90% rename from hostd/src/io_patagia_hostd.rs rename to hostd/src/io_patagia_Hostd.rs index 19d0df5..a2de13d 100644 --- a/hostd/src/io_patagia_hostd.rs +++ b/hostd/src/io_patagia_Hostd.rs @@ -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,7 +144,8 @@ pub struct r#Machine { } #[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] pub struct r#PatagiaAgentConfig { - pub r#url: Option<String>, + pub r#url: String, + pub r#extraMounts: varlink::StringHashMap<String>, } #[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] pub struct InvalidMachineConfig_Args {} @@ -203,14 +204,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 {}, ) } @@ -225,10 +226,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)\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 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" + "io.patagia.Hostd" } fn call_upgraded( &self, @@ -240,7 +241,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, @@ -256,7 +257,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)), } } diff --git a/hostd/src/io_systemd_hostname.rs b/hostd/src/io_systemd_Hostname.rs similarity index 100% rename from hostd/src/io_systemd_hostname.rs rename to hostd/src/io_systemd_Hostname.rs diff --git a/hostd/src/main.rs b/hostd/src/main.rs index 7f886ef..01ff4d2 100644 --- a/hostd/src/main.rs +++ b/hostd/src/main.rs @@ -1,57 +1,48 @@ -use std::process::exit; +use std::{collections::HashMap, 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 PatagiaHostd; +struct Hostd; -impl VarlinkInterface for PatagiaHostd { +impl VarlinkInterface for Hostd { fn apply(&self, call: &mut dyn Call_Apply, machine: Machine) -> varlink::Result<()> { - // FIXME: Do something useful - println!("Applying machine config: {:#?}", machine); - call.reply() + println!("Machine: {:#?}", machine); + return call.reply(); } fn describe(&self, call: &mut dyn Call_Describe) -> varlink::Result<()> { - // FIXME: Do something useful let machine = Machine { - 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()), + 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(), }), }; - call.reply(machine) + return call.reply(machine); } } fn main() { - let hostd = PatagiaHostd; - let hostd_iface = io_patagia_hostd::new(Box::new(hostd)); + let hostd = Hostd; + let hostd_interface = 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_iface)], + vec![Box::new(hostd_interface)], ); - - println!("Varlink Listening on {}", LISTEN_ADDRESS); let ret: Result<(), varlink::Error> = varlink::listen( svc, LISTEN_ADDRESS, @@ -62,7 +53,6 @@ fn main() { }, ); - // Exit with error code exit(match ret { Ok(_) => 0, Err(e) => {