Implement parts of the Machine API

This commit is contained in:
Gregor Reitzenstein 2020-12-16 11:32:31 +01:00
parent ec20859f6d
commit cca5bddbb8
3 changed files with 27 additions and 6 deletions

View File

@ -5,21 +5,21 @@ use capnp::Error;
use crate::schema::api_capnp::State;
use crate::schema::api_capnp::machine::*;
use crate::db::machine::MachineIdentifier;
use crate::connection::Session;
use crate::db::Databases;
use crate::db::machine::Status;
use crate::machine::Machine as NwMachine;
#[derive(Clone)]
pub struct Machine {
session: Arc<Session>,
id: MachineIdentifier,
machine: NwMachine,
db: Databases,
}
impl Machine {
pub fn new(session: Arc<Session>, id: MachineIdentifier, db: Databases) -> Self {
Machine { session, id, db }
pub fn new(session: Arc<Session>, machine: NwMachine, db: Databases) -> Self {
Machine { session, machine, db }
}
pub fn fill(self: Arc<Self>, builder: &mut Builder) {

View File

@ -36,6 +36,19 @@ impl machines::Server for Machines {
mut results: machines::ListMachinesResults)
-> Promise<(), Error>
{
let v: Vec<(String, crate::machine::Machine)> = self.network.machines.iter()
.map(|(n, m)| (n.clone(), m.clone()))
.collect();
let mut res = results.get();
let mut machines = res.init_machines(v.len() as u32);
for (i, (name, machine)) in v.into_iter().enumerate() {
let machine = Arc::new(Machine::new(self.session.clone(), machine, self.db.clone()));
let mut builder = machines.reborrow().get(i as u32);
Machine::fill(machine, &mut builder);
}
Promise::ok(())
}
@ -44,6 +57,14 @@ impl machines::Server for Machines {
mut results: machines::GetMachineResults)
-> Promise<(), Error>
{
unimplemented!()
if let Ok(uid) = params.get().and_then(|x| x.get_uid()) {
if let Some(machine_inner) = self.network.machines.get(uid) {
let machine = Arc::new(Machine::new(self.session.clone(), machine_inner.clone(), self.db.clone()));
let mut builder = results.get().init_machine();
Machine::fill(machine, &mut builder);
}
}
Promise::ok(())
}
}

View File

@ -46,7 +46,7 @@ pub struct Network {
// Store connections
//miconn: Vec<(String, String)>,
machines: MachineMap,
pub machines: MachineMap,
// Store connections
//maconn: Vec<(String, String)>,