mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-11 01:53:23 +01:00
Implement parts of the Machine API
This commit is contained in:
parent
ec20859f6d
commit
cca5bddbb8
@ -5,21 +5,21 @@ use capnp::Error;
|
|||||||
|
|
||||||
use crate::schema::api_capnp::State;
|
use crate::schema::api_capnp::State;
|
||||||
use crate::schema::api_capnp::machine::*;
|
use crate::schema::api_capnp::machine::*;
|
||||||
use crate::db::machine::MachineIdentifier;
|
|
||||||
use crate::connection::Session;
|
use crate::connection::Session;
|
||||||
use crate::db::Databases;
|
use crate::db::Databases;
|
||||||
use crate::db::machine::Status;
|
use crate::db::machine::Status;
|
||||||
|
use crate::machine::Machine as NwMachine;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Machine {
|
pub struct Machine {
|
||||||
session: Arc<Session>,
|
session: Arc<Session>,
|
||||||
id: MachineIdentifier,
|
machine: NwMachine,
|
||||||
db: Databases,
|
db: Databases,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Machine {
|
impl Machine {
|
||||||
pub fn new(session: Arc<Session>, id: MachineIdentifier, db: Databases) -> Self {
|
pub fn new(session: Arc<Session>, machine: NwMachine, db: Databases) -> Self {
|
||||||
Machine { session, id, db }
|
Machine { session, machine, db }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fill(self: Arc<Self>, builder: &mut Builder) {
|
pub fn fill(self: Arc<Self>, builder: &mut Builder) {
|
||||||
|
@ -36,6 +36,19 @@ impl machines::Server for Machines {
|
|||||||
mut results: machines::ListMachinesResults)
|
mut results: machines::ListMachinesResults)
|
||||||
-> Promise<(), Error>
|
-> 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(())
|
Promise::ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,6 +57,14 @@ impl machines::Server for Machines {
|
|||||||
mut results: machines::GetMachineResults)
|
mut results: machines::GetMachineResults)
|
||||||
-> Promise<(), Error>
|
-> 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(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ pub struct Network {
|
|||||||
// Store connections
|
// Store connections
|
||||||
//miconn: Vec<(String, String)>,
|
//miconn: Vec<(String, String)>,
|
||||||
|
|
||||||
machines: MachineMap,
|
pub machines: MachineMap,
|
||||||
|
|
||||||
// Store connections
|
// Store connections
|
||||||
//maconn: Vec<(String, String)>,
|
//maconn: Vec<(String, String)>,
|
||||||
|
Loading…
Reference in New Issue
Block a user