updater #1
| @ -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, | ||||
| ) -> 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,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?; | ||||
|     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!( | ||||
|                 "Received error when updating VM on node {}: {e:?}", | ||||
|                     &node.node_pubkey | ||||
|                 &contract.node_pubkey | ||||
|             ); | ||||
|         } | ||||
|     } | ||||
|     } | ||||
| 
 | ||||
|     if std::env::var("DELETE_VMS").is_err() { | ||||
|         return Ok(()); | ||||
|  | ||||
| @ -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"); | ||||
| } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user