From ec719ba890281c40445ce2b08f7849b572f0d5ce Mon Sep 17 00:00:00 2001 From: Gregor Reitzenstein Date: Fri, 20 Nov 2020 14:03:16 +0100 Subject: [PATCH] Adds minfo command --- src/app.rs | 24 ++++++++++++++++++++++++ src/commands.rs | 6 ++++-- src/schema/api.rs | 12 ++++++++++++ src/schema/authentication.rs | 1 - src/schema/machine.rs | 30 ++++++++++++++++++++++++++++++ src/schema/machines.rs | 28 ++++++++++++++++++++++++++++ src/schema/mod.rs | 6 ++++++ 7 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 src/schema/machine.rs create mode 100644 src/schema/machines.rs diff --git a/src/app.rs b/src/app.rs index 98bba6e..7b24499 100644 --- a/src/app.rs +++ b/src/app.rs @@ -95,6 +95,30 @@ impl<'a, S: Unpin> Sute<'a, S> { } } } + Some(("minfo", m)) => { + if let Some(uuid) = m.value_of("uuid") { + let uuid = uuid.to_string(); + if let Some(mut api) = self.session.as_ref().map(|s| s.bootstrap.clone()) { + let log = self.log.clone(); + + let f = api.machines().map(|mut machines| { + machines.get_machine(uuid).map(move |res| { + res.map(|m| { + m.get_info().map(move |info| { + info!(log, "Yay, stuff! {:?}", info); + }) + }) + }) + }); + let old_f = self.future.replace(Box::pin(f.map(|_| ()))); + if !old_f.is_none() { + warn!(self.log, "Dropping a future"); + } + } + } else { + error!(self.log, "minfo ") + } + } Some((s, m)) => info!(self.log, "Got Command {} with params {:?}", s, m), None => error!(self.log, "No command provided."), } diff --git a/src/commands.rs b/src/commands.rs index cddd962..f061b53 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -28,8 +28,10 @@ impl<'help> CommandParser<'help> { .arg(Arg::new("user") .takes_value(true)) .arg(Arg::new("pass") - .takes_value(true)) - ) + .takes_value(true))) + .subcommand(App::new("minfo") + .arg(Arg::new("uuid") + .takes_value(true))) , } } diff --git a/src/schema/api.rs b/src/schema/api.rs index 6afe176..332106d 100644 --- a/src/schema/api.rs +++ b/src/schema/api.rs @@ -6,6 +6,7 @@ use slog::Logger; use super::connection_capnp::bootstrap::Client; use super::Authentication; +use super::Machines; #[derive(Clone)] pub struct API { @@ -28,4 +29,15 @@ impl API { Authentication::new(moretmp.get_auth().unwrap()) }) } + + pub fn machines(&mut self) -> impl Future { + let req = self.inner.machines_request().send().promise; + // TODO: When's that an Err? + req.map(|res| { + // TODO: When's that an Err? + let tmp = res.unwrap(); + let moretmp = tmp.get().unwrap(); + Machines::new(moretmp.get_machines().unwrap()) + }) + } } diff --git a/src/schema/authentication.rs b/src/schema/authentication.rs index 9577c05..c7b46b0 100644 --- a/src/schema/authentication.rs +++ b/src/schema/authentication.rs @@ -4,7 +4,6 @@ use std::future::Future; use futures::FutureExt; -use slog::Logger; use super::auth_capnp::authentication::Client; pub struct Authentication { diff --git a/src/schema/machine.rs b/src/schema/machine.rs new file mode 100644 index 0000000..02c3382 --- /dev/null +++ b/src/schema/machine.rs @@ -0,0 +1,30 @@ +use std::fmt; +use std::any::Any; +use std::future::Future; + +use super::api_capnp::machine::read::Client; + +pub struct Machine { + read: Option, +} +impl fmt::Debug for Machine { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let mut b = f.debug_struct("Machine"); + if let Some(r) = self.read.as_ref() { + b.field("read", &r.type_id()); + } + b.finish() + } +} + +impl Machine { + pub fn new(read: Option) -> Self { + Machine { + read, + } + } + + pub fn get_info(&self) -> impl Future> { + futures::future::ready(None) + } +} diff --git a/src/schema/machines.rs b/src/schema/machines.rs new file mode 100644 index 0000000..b8f95eb --- /dev/null +++ b/src/schema/machines.rs @@ -0,0 +1,28 @@ +use std::fmt; +use std::any::Any; +use std::future::Future; + +use super::api_capnp::machines::Client; + +use super::machine::Machine; + +pub struct Machines { + inner: Client, +} +impl fmt::Debug for Machines { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Machines") + .field("inner", &self.inner.type_id()) + .finish() + } +} + +impl Machines { + pub fn new(inner: Client) -> Self { + Self { inner } + } + + pub fn get_machine(&mut self, uuid: String) -> impl Future> { + futures::future::ready(None) + } +} diff --git a/src/schema/mod.rs b/src/schema/mod.rs index 790f43c..84ebb5a 100644 --- a/src/schema/mod.rs +++ b/src/schema/mod.rs @@ -28,6 +28,12 @@ pub use api::API; mod authentication; pub use authentication::Authentication; +mod machines; +pub use machines::Machines; + +mod machine; +pub use machine::Machine; + pub fn bootstrap(log: Logger, stream: TcpStream) -> (RpcSystem, API) { let network = Box::new(twoparty::VatNetwork::new(stream.clone(), stream, Side::Client, Default::default()));