forked from ghe0/brain-mock
change NewVmResp to allow the CLI to build params
This commit is contained in:
parent
0dcacf6f98
commit
7b3ee9319f
15
brain.proto
15
brain.proto
@ -79,12 +79,21 @@ message ListVMContractsReq {
|
|||||||
string node_pubkey = 2;
|
string node_pubkey = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message NewVmRespIP {
|
||||||
|
uint32 nic_index = 1;
|
||||||
|
string address = 2;
|
||||||
|
string mask = 3;
|
||||||
|
string gateway = 4;
|
||||||
|
}
|
||||||
|
|
||||||
message NewVMResp {
|
message NewVMResp {
|
||||||
string uuid = 1;
|
string uuid = 1;
|
||||||
repeated uint32 exposed_ports = 2;
|
repeated uint32 exposed_ports = 2;
|
||||||
string public_ipv4 = 3;
|
string ovmf_hash = 5;
|
||||||
string public_ipv6 = 4;
|
// This is needed to allow the CLI to build the kernel params from known data.
|
||||||
string error = 5;
|
// The CLI will use the kernel params to get the measurement.
|
||||||
|
repeated NewVmRespIP ips = 6;
|
||||||
|
string error = 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
message DeleteVMReq {
|
message DeleteVMReq {
|
||||||
|
48
src/data.rs
48
src/data.rs
@ -3,6 +3,7 @@ use crate::grpc::brain as grpc;
|
|||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use log::{debug, info, warn};
|
use log::{debug, info, warn};
|
||||||
|
use std::str::FromStr;
|
||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
use tokio::sync::mpsc::Sender;
|
use tokio::sync::mpsc::Sender;
|
||||||
use tokio::sync::oneshot::Sender as OneshotSender;
|
use tokio::sync::oneshot::Sender as OneshotSender;
|
||||||
@ -126,7 +127,10 @@ impl BrainData {
|
|||||||
let mut nodes = self.nodes.write().unwrap();
|
let mut nodes = self.nodes.write().unwrap();
|
||||||
for n in nodes.iter_mut() {
|
for n in nodes.iter_mut() {
|
||||||
if n.public_key == res.node_pubkey {
|
if n.public_key == res.node_pubkey {
|
||||||
debug!("Found node {}. Updating resources to {:?}", n.public_key, res);
|
debug!(
|
||||||
|
"Found node {}. Updating resources to {:?}",
|
||||||
|
n.public_key, res
|
||||||
|
);
|
||||||
n.avail_ipv4 = res.avail_ipv4;
|
n.avail_ipv4 = res.avail_ipv4;
|
||||||
n.avail_ipv6 = res.avail_ipv6;
|
n.avail_ipv6 = res.avail_ipv6;
|
||||||
n.avail_vcpus = res.avail_vcpus;
|
n.avail_vcpus = res.avail_vcpus;
|
||||||
@ -137,7 +141,10 @@ impl BrainData {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
debug!("Node {} not found when trying to update resources.", res.node_pubkey);
|
debug!(
|
||||||
|
"Node {} not found when trying to update resources.",
|
||||||
|
res.node_pubkey
|
||||||
|
);
|
||||||
debug!("Node list:\n{:?}", nodes);
|
debug!("Node list:\n{:?}", nodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,33 +184,46 @@ impl BrainData {
|
|||||||
self.daemon_newvm_tx.insert(node_pubkey.to_string(), tx);
|
self.daemon_newvm_tx.insert(node_pubkey.to_string(), tx);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn submit_newvm_resp(&self, confirmation: grpc::NewVmResp) {
|
pub async fn submit_newvm_resp(&self, new_vm_resp: grpc::NewVmResp) {
|
||||||
let newvmreq = match self.tmp_newvm_reqs.remove(&confirmation.uuid) {
|
let newvmreq = match self.tmp_newvm_reqs.remove(&new_vm_resp.uuid) {
|
||||||
Some((_, r)) => r,
|
Some((_, r)) => r,
|
||||||
None => {
|
None => {
|
||||||
log::error!(
|
log::error!(
|
||||||
"Received confirmation for ghost NewVMReq {}",
|
"Received confirmation for ghost NewVMReq {}",
|
||||||
confirmation.uuid
|
new_vm_resp.uuid
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if let Err(e) = newvmreq.1.send(confirmation.clone()) {
|
if let Err(e) = newvmreq.1.send(new_vm_resp.clone()) {
|
||||||
log::error!(
|
log::error!(
|
||||||
"CLI RX for {} dropped before receiving confirmation {:?}. Error is: {:?}",
|
"CLI RX for {} dropped before receiving confirmation {:?}. Error is: {:?}",
|
||||||
&newvmreq.0.admin_pubkey,
|
&newvmreq.0.admin_pubkey,
|
||||||
confirmation,
|
new_vm_resp,
|
||||||
e
|
e
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if confirmation.error != "" {
|
if new_vm_resp.error != "" {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
let mut public_ipv4 = String::new();
|
||||||
|
let mut public_ipv6 = String::new();
|
||||||
|
for ip in new_vm_resp.ips {
|
||||||
|
if let Ok(ipv4_addr) = std::net::Ipv4Addr::from_str(&ip.address) {
|
||||||
|
if !ipv4_addr.is_private() && !ipv4_addr.is_link_local() {
|
||||||
|
public_ipv4 = ipv4_addr.to_string();
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if let Ok(ipv6_addr) = std::net::Ipv6Addr::from_str(&ip.address) {
|
||||||
|
public_ipv6 = ipv6_addr.to_string();
|
||||||
|
}
|
||||||
|
}
|
||||||
let contract = Contract {
|
let contract = Contract {
|
||||||
uuid: confirmation.uuid,
|
uuid: new_vm_resp.uuid,
|
||||||
exposed_ports: confirmation.exposed_ports,
|
exposed_ports: new_vm_resp.exposed_ports,
|
||||||
public_ipv4: confirmation.public_ipv4,
|
public_ipv4,
|
||||||
public_ipv6: confirmation.public_ipv6,
|
public_ipv6,
|
||||||
created_at: Utc::now().to_rfc3339(),
|
created_at: Utc::now().to_rfc3339(),
|
||||||
updated_at: String::new(),
|
updated_at: String::new(),
|
||||||
hostname: newvmreq.0.hostname,
|
hostname: newvmreq.0.hostname,
|
||||||
@ -274,8 +294,8 @@ impl BrainData {
|
|||||||
error: "Daemon is offline.".to_string(),
|
error: "Daemon is offline.".to_string(),
|
||||||
uuid,
|
uuid,
|
||||||
exposed_ports: Vec::new(),
|
exposed_ports: Vec::new(),
|
||||||
public_ipv4: "".to_string(),
|
ovmf_hash: "".to_string(),
|
||||||
public_ipv6: "".to_string(),
|
ips: Vec::new(),
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user