From eb9d8f921f218b4243d8fef91b72d14d845d9192 Mon Sep 17 00:00:00 2001 From: ghe0 Date: Thu, 26 Dec 2024 00:56:56 +0200 Subject: [PATCH] remove node_pubkey from UpdateVmReq --- cli-mock/brain.proto | 1 - cli-mock/src/main.rs | 45 ++++++++++++++++++----------------------- daemon-mock/brain.proto | 1 - daemon-mock/src/main.rs | 12 +++++------ 4 files changed, 26 insertions(+), 33 deletions(-) diff --git a/cli-mock/brain.proto b/cli-mock/brain.proto index fd8662f..9a9e84f 100644 --- a/cli-mock/brain.proto +++ b/cli-mock/brain.proto @@ -42,7 +42,6 @@ message NewVMReq { message UpdateVMReq { string uuid = 1; - string node_pubkey = 2; uint32 disk_size_gb = 3; uint32 vcpus = 4; uint32 memory_mb = 5; diff --git a/cli-mock/src/main.rs b/cli-mock/src/main.rs index 31a4d54..2b4655b 100644 --- a/cli-mock/src/main.rs +++ b/cli-mock/src/main.rs @@ -5,8 +5,8 @@ pub mod brain { use anyhow::Result; use brain::{ - brain_cli_service_client::BrainCliServiceClient, DeleteVmReq, ListVmContractsReq, - NewVmReq, NodeFilters, NodeListResp, VmContract, UpdateVmReq, + brain_cli_service_client::BrainCliServiceClient, DeleteVmReq, ListVmContractsReq, NewVmReq, + NodeFilters, NodeListResp, UpdateVmReq, VmContract, }; use lazy_static::lazy_static; use log::{debug, info, warn}; @@ -84,12 +84,12 @@ async fn submit_vm_request( info!("Creating VM {req:?}"); let result = client.create_vm_contract(req).await; match result { - Ok(confirmation) => { - let confirmation = confirmation.into_inner(); - if confirmation.error.is_empty() { - info!("Got VM confirmation: {confirmation:?}"); + Ok(resp) => { + let resp = resp.into_inner(); + if resp.error.is_empty() { + info!("Got NewVMResp: {resp:?}"); } else { - warn!("Got VM confirmation error: {}", confirmation.error); + warn!("Got new VM error: {}", resp.error); }; } Err(e) => log::error!("Could not create vm: {e:?}"), @@ -137,12 +137,10 @@ async fn delete_vm(mut client: BrainCliServiceClient, uuid: &str) -> Re async fn update_vm_request( mut client: BrainCliServiceClient, - node_pubkey: &str, - uuid: &str, + uuid: &str, ) -> Result<()> { let req = UpdateVmReq { uuid: uuid.to_string(), - node_pubkey: node_pubkey.to_string(), vcpus: 4, memory_mb: 4096, disk_size_gb: 40, @@ -154,12 +152,12 @@ async fn update_vm_request( info!("Updating VM {req:?}"); let result = client.update_vm(req).await; match result { - Ok(confirmation) => { - let confirmation = confirmation.into_inner(); - if confirmation.error.is_empty() { - info!("Got VM update confirmation: {confirmation:?}"); + Ok(resp) => { + let resp = resp.into_inner(); + if resp.error.is_empty() { + info!("Got VM update response: {resp:?}"); } 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:?}"), @@ -186,16 +184,13 @@ async fn main() -> Result<()> { } } - let nodes = get_node_list(client.clone()).await?; - for node in nodes { - let contracts = list_contracts(client.clone()).await?; - for contract in contracts { - if let Err(e) = update_vm_request(client.clone(), &node.node_pubkey, &contract.uuid).await { - log::error!( - "Received error when updating VM on node {}: {e:?}", - &node.node_pubkey - ); - } + let contracts = list_contracts(client.clone()).await?; + for contract in contracts { + if let Err(e) = update_vm_request(client.clone(), &contract.uuid).await { + log::error!( + "Received error when updating VM on node {}: {e:?}", + &contract.node_pubkey + ); } } diff --git a/daemon-mock/brain.proto b/daemon-mock/brain.proto index fd8662f..9a9e84f 100644 --- a/daemon-mock/brain.proto +++ b/daemon-mock/brain.proto @@ -42,7 +42,6 @@ message NewVMReq { message UpdateVMReq { string uuid = 1; - string node_pubkey = 2; uint32 disk_size_gb = 3; uint32 vcpus = 4; uint32 memory_mb = 5; diff --git a/daemon-mock/src/main.rs b/daemon-mock/src/main.rs index 783f4a9..1233265 100644 --- a/daemon-mock/src/main.rs +++ b/daemon-mock/src/main.rs @@ -142,16 +142,16 @@ async fn listen_for_update_vm_reqs( async fn handle_update_vm_requests( mut req: Receiver, - resp: Sender + resp_chan: Sender ) { info!("Started to handle update vm requests."); while let Some(update_vm) = req.recv().await { - let confirmation = UpdateVmResp { + let update_vm_resp = UpdateVmResp { uuid: update_vm.uuid, error: "".to_string(), }; - info!("Sending UpdateVmResp: {confirmation:?}"); - let _ = resp.send(confirmation).await; + info!("Sending UpdateVmResp: {update_vm_resp:?}"); + let _ = resp_chan.send(update_vm_resp).await; }; warn!("update vm request handler is ending"); } @@ -180,7 +180,7 @@ async fn handle_vm_requests(mut req: Receiver, resp: Sender false => String::new(), }; 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(), }; if i != 3 { @@ -269,4 +269,4 @@ async fn main() { .init(); info!("Hello! My name is {}", SECURE_PUBLIC_KEY.clone()); connection_wrapper().await; -} \ No newline at end of file +}