Adds minfo command

This commit is contained in:
Gregor Reitzenstein 2020-11-20 14:03:16 +01:00
parent 8dc2a156bb
commit ec719ba890
7 changed files with 104 additions and 3 deletions

View File

@ -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 <uuid>")
}
}
Some((s, m)) => info!(self.log, "Got Command {} with params {:?}", s, m), Some((s, m)) => info!(self.log, "Got Command {} with params {:?}", s, m),
None => error!(self.log, "No command provided."), None => error!(self.log, "No command provided."),
} }

View File

@ -28,8 +28,10 @@ impl<'help> CommandParser<'help> {
.arg(Arg::new("user") .arg(Arg::new("user")
.takes_value(true)) .takes_value(true))
.arg(Arg::new("pass") .arg(Arg::new("pass")
.takes_value(true)) .takes_value(true)))
) .subcommand(App::new("minfo")
.arg(Arg::new("uuid")
.takes_value(true)))
, ,
} }
} }

View File

@ -6,6 +6,7 @@ use slog::Logger;
use super::connection_capnp::bootstrap::Client; use super::connection_capnp::bootstrap::Client;
use super::Authentication; use super::Authentication;
use super::Machines;
#[derive(Clone)] #[derive(Clone)]
pub struct API { pub struct API {
@ -28,4 +29,15 @@ impl API {
Authentication::new(moretmp.get_auth().unwrap()) Authentication::new(moretmp.get_auth().unwrap())
}) })
} }
pub fn machines(&mut self) -> impl Future<Output=Machines> {
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())
})
}
} }

View File

@ -4,7 +4,6 @@ use std::future::Future;
use futures::FutureExt; use futures::FutureExt;
use slog::Logger;
use super::auth_capnp::authentication::Client; use super::auth_capnp::authentication::Client;
pub struct Authentication { pub struct Authentication {

30
src/schema/machine.rs Normal file
View File

@ -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<Client>,
}
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<Client>) -> Self {
Machine {
read,
}
}
pub fn get_info(&self) -> impl Future<Output=Option<String>> {
futures::future::ready(None)
}
}

28
src/schema/machines.rs Normal file
View File

@ -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<Output=Option<Machine>> {
futures::future::ready(None)
}
}

View File

@ -28,6 +28,12 @@ pub use api::API;
mod authentication; mod authentication;
pub use authentication::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<Side>, API) { pub fn bootstrap(log: Logger, stream: TcpStream) -> (RpcSystem<Side>, API) {
let network = Box::new(twoparty::VatNetwork::new(stream.clone(), stream, let network = Box::new(twoparty::VatNetwork::new(stream.clone(), stream,
Side::Client, Default::default())); Side::Client, Default::default()));