updater #1
| @ -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,16 +184,13 @@ async fn main() -> Result<()> { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     let nodes = get_node_list(client.clone()).await?; |     let contracts = list_contracts(client.clone()).await?; | ||||||
|     for node in nodes { |     for contract in contracts { | ||||||
|         let contracts = list_contracts(client.clone()).await?; |         if let Err(e) = update_vm_request(client.clone(), &contract.uuid).await { | ||||||
|         for contract in contracts { |             log::error!( | ||||||
|             if let Err(e) = update_vm_request(client.clone(), &node.node_pubkey, &contract.uuid).await { |                 "Received error when updating VM on node {}: {e:?}", | ||||||
|                 log::error!( |                 &contract.node_pubkey | ||||||
|                     "Received error when updating VM on node {}: {e:?}", |             ); | ||||||
|                     &node.node_pubkey |  | ||||||
|                 ); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -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
						
					
				 | |||||||
|         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 { | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	
The timestamp must be set from the brain, for security reasons.
Also, this does not require chrono.
Check this: