From a6d4bc06de27b25ea7a188e13a785f9aecccdee8 Mon Sep 17 00:00:00 2001 From: Gregor Reitzenstein Date: Mon, 8 Feb 2021 18:39:26 +0000 Subject: [PATCH] Status commit --- schema | 2 +- src/app.rs | 21 +++++++++++++++++++++ src/commands.rs | 1 + src/schema/machines.rs | 22 ++++++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/schema b/schema index d930c70..1dc6781 160000 --- a/schema +++ b/schema @@ -1 +1 @@ -Subproject commit d930c70978e8bd5b28b9c19c907d2fe457797a89 +Subproject commit 1dc6781a26af42312acefa6981d3cac2aa1345d6 diff --git a/src/app.rs b/src/app.rs index 265468b..47512f6 100644 --- a/src/app.rs +++ b/src/app.rs @@ -119,6 +119,27 @@ impl<'a, S: Unpin> Sute<'a, S> { error!(self.log, "minfo ") } } + Some(("list", _m)) => { + if let Some(mut machines) = self.session.as_mut().map(|s| s.bootstrap.machines()) { + let log = self.log.clone(); + + let f = async move { + let machlist = machines.await.list_machines().await; + info!(log, "Listing all machines"); + for m in machlist { + m.get_info().map(|info| { + info!(log, "A machine: {:?}", info); + }).await; + } + info!(log, "Listed all machines"); + }; + + let old_f = self.future.replace(Box::pin(f.map(|_| ()))); + if !old_f.is_none() { + warn!(self.log, "Dropping a future"); + } + } + }, 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 ce8d3fc..53d90c9 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -32,6 +32,7 @@ impl<'help> CommandParser<'help> { .subcommand(App::new("minfo") .arg(Arg::new("uid") .takes_value(true))) + .subcommand(App::new("list")) , } } diff --git a/src/schema/machines.rs b/src/schema/machines.rs index a775fa7..db7f53a 100644 --- a/src/schema/machines.rs +++ b/src/schema/machines.rs @@ -47,6 +47,28 @@ impl Machines { None }) } + + pub fn list_machines(&mut self) -> impl Future> { + let req = self.inner.list_machines_request(); + let promise = req.send().promise; + + promise.map(|res| { + let tmp = res.unwrap(); + let moretmp = tmp.get().unwrap(); + let mut out = Vec::new(); + if let Ok(m) = moretmp.get_machines() { + for machine in m.iter() { + match machine.get_read() { + Ok(read) => out.push(Machine::new(read)), + Err(e) => println!("{}", e), + } + } + } else { + println!("No get_machines? :(") + } + return out; + }) + } } pub fn uuid_from_api(uuid: crate::schema::api_capnp::u_u_i_d::Reader) -> Uuid {