remove node_pubkey from UpdateVmReq

This commit is contained in:
ghe0 2024-12-26 00:56:56 +02:00
parent b7c2211d32
commit eb9d8f921f
Signed by: ghe0
GPG Key ID: 451028EE56A0FBB4
4 changed files with 26 additions and 33 deletions

@ -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;

@ -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<Channel>, uuid: &str) -> Re
async fn update_vm_request(
mut client: BrainCliServiceClient<Channel>,
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
);
}
}

@ -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;

@ -142,16 +142,16 @@ async fn listen_for_update_vm_reqs(
async fn handle_update_vm_requests(
mut req: Receiver<UpdateVmReq>,
resp: Sender<UpdateVmResp>
resp_chan: Sender<UpdateVmResp>
) {
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<NewVmReq>, resp: Sender<NewVmResp>
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;
}
}