updater #1

Merged
ghe0 merged 13 commits from updater into master 2024-12-25 23:00:16 +00:00
4 changed files with 26 additions and 33 deletions
Showing only changes of commit eb9d8f921f - Show all commits

@ -42,7 +42,6 @@ message NewVMReq {
message UpdateVMReq { message UpdateVMReq {
string uuid = 1; string uuid = 1;
string node_pubkey = 2;
uint32 disk_size_gb = 3; uint32 disk_size_gb = 3;
uint32 vcpus = 4; uint32 vcpus = 4;
uint32 memory_mb = 5; uint32 memory_mb = 5;

@ -5,8 +5,8 @@ pub mod brain {
use anyhow::Result; use anyhow::Result;
use brain::{ use brain::{
brain_cli_service_client::BrainCliServiceClient, DeleteVmReq, ListVmContractsReq, brain_cli_service_client::BrainCliServiceClient, DeleteVmReq, ListVmContractsReq, NewVmReq,
NewVmReq, NodeFilters, NodeListResp, VmContract, UpdateVmReq, NodeFilters, NodeListResp, UpdateVmReq, VmContract,
}; };
use lazy_static::lazy_static; use lazy_static::lazy_static;
use log::{debug, info, warn}; use log::{debug, info, warn};
@ -84,12 +84,12 @@ async fn submit_vm_request(
info!("Creating VM {req:?}"); info!("Creating VM {req:?}");
let result = client.create_vm_contract(req).await; let result = client.create_vm_contract(req).await;
match result { match result {
Ok(confirmation) => { Ok(resp) => {
let confirmation = confirmation.into_inner(); let resp = resp.into_inner();
if confirmation.error.is_empty() { if resp.error.is_empty() {
info!("Got VM confirmation: {confirmation:?}"); info!("Got NewVMResp: {resp:?}");
} else { } else {
warn!("Got VM confirmation error: {}", confirmation.error); warn!("Got new VM error: {}", resp.error);
}; };
} }
Err(e) => log::error!("Could not create vm: {e:?}"), Err(e) => log::error!("Could not create vm: {e:?}"),
@ -137,12 +137,10 @@ async fn delete_vm(mut client: BrainCliServiceClient<Channel>, uuid: &str) -> Re
async fn update_vm_request( async fn update_vm_request(
mut client: BrainCliServiceClient<Channel>, mut client: BrainCliServiceClient<Channel>,
node_pubkey: &str,
uuid: &str, uuid: &str,
) -> Result<()> { ) -> Result<()> {
let req = UpdateVmReq { let req = UpdateVmReq {
uuid: uuid.to_string(), uuid: uuid.to_string(),
node_pubkey: node_pubkey.to_string(),
vcpus: 4, vcpus: 4,
memory_mb: 4096, memory_mb: 4096,
disk_size_gb: 40, disk_size_gb: 40,
@ -154,12 +152,12 @@ async fn update_vm_request(
info!("Updating VM {req:?}"); info!("Updating VM {req:?}");
let result = client.update_vm(req).await; let result = client.update_vm(req).await;
match result { match result {
Ok(confirmation) => { Ok(resp) => {
let confirmation = confirmation.into_inner(); let resp = resp.into_inner();
if confirmation.error.is_empty() { if resp.error.is_empty() {
info!("Got VM update confirmation: {confirmation:?}"); info!("Got VM update response: {resp:?}");
} else { } else {
warn!("Got VM update confirmation error: {}", confirmation.error); warn!("Got VM update error: {}", resp.error);
}; };
} }
Err(e) => log::error!("Could not update vm: {e:?}"), Err(e) => log::error!("Could not update vm: {e:?}"),
@ -186,18 +184,15 @@ async fn main() -> Result<()> {
} }
} }
let nodes = get_node_list(client.clone()).await?;
for node in nodes {
let contracts = list_contracts(client.clone()).await?; let contracts = list_contracts(client.clone()).await?;
for contract in contracts { for contract in contracts {
if let Err(e) = update_vm_request(client.clone(), &node.node_pubkey, &contract.uuid).await { if let Err(e) = update_vm_request(client.clone(), &contract.uuid).await {
log::error!( log::error!(
"Received error when updating VM on node {}: {e:?}", "Received error when updating VM on node {}: {e:?}",
&node.node_pubkey &contract.node_pubkey
); );
} }
} }
}
if std::env::var("DELETE_VMS").is_err() { if std::env::var("DELETE_VMS").is_err() {
return Ok(()); return Ok(());

@ -42,7 +42,6 @@ message NewVMReq {
message UpdateVMReq { message UpdateVMReq {
string uuid = 1; string uuid = 1;
string node_pubkey = 2;
uint32 disk_size_gb = 3; uint32 disk_size_gb = 3;
uint32 vcpus = 4; uint32 vcpus = 4;
uint32 memory_mb = 5; uint32 memory_mb = 5;

@ -142,16 +142,16 @@ async fn listen_for_update_vm_reqs(
async fn handle_update_vm_requests( async fn handle_update_vm_requests(
mut req: Receiver<UpdateVmReq>, mut req: Receiver<UpdateVmReq>,
resp: Sender<UpdateVmResp> resp_chan: Sender<UpdateVmResp>
) { ) {
info!("Started to handle update vm requests."); info!("Started to handle update vm requests.");
while let Some(update_vm) = req.recv().await { while let Some(update_vm) = req.recv().await {
let confirmation = UpdateVmResp { let update_vm_resp = UpdateVmResp {
uuid: update_vm.uuid, uuid: update_vm.uuid,
error: "".to_string(), error: "".to_string(),
}; };
ghe0 marked this conversation as resolved Outdated
Outdated
Review

The timestamp must be set from the brain, for security reasons.
Also, this does not require chrono.

Check this:

src/data.rs Line 191 in 7905c1c165
created_at: format!("{:?}", std::time::SystemTime::now()),

The timestamp must be set from the brain, for security reasons. Also, this does not require chrono. Check this: https://gitea.detee.cloud/ghe0/brain-mock/src/commit/7905c1c165ca6911ad8f3d9f83ff160b2d9dc9bb/src/data.rs#L191
info!("Sending UpdateVmResp: {confirmation:?}"); info!("Sending UpdateVmResp: {update_vm_resp:?}");
let _ = resp.send(confirmation).await; let _ = resp_chan.send(update_vm_resp).await;
}; };
warn!("update vm request handler is ending"); warn!("update vm request handler is ending");
} }
@ -180,7 +180,7 @@ async fn handle_vm_requests(mut req: Receiver<NewVmReq>, resp: Sender<NewVmResp>
false => String::new(), false => String::new(),
}; };
let public_ipv6 = match new_vm.public_ipv6 { let public_ipv6 = match new_vm.public_ipv6 {
true => " 2a02:2f2d:d301:3100:afe8:a85e:54a0:dd28".to_string(), true => "2a02:2f2d:d301:3100:afe8:a85e:54a0:dd28".to_string(),
false => String::new(), false => String::new(),
}; };
if i != 3 { if i != 3 {