Now new_vm_resp.args.dtrfs_api_endpoint also get modified if there is no public ip of the vm

Also removed the unnecessary else clause
This commit is contained in:
Ramil_Algayev 2025-01-07 00:08:57 +04:00
parent ab4361ad5e
commit 02ff2f6991

@ -185,7 +185,7 @@ impl BrainData {
} }
pub async fn submit_newvm_resp(&self, mut new_vm_resp: grpc::NewVmResp) { pub async fn submit_newvm_resp(&self, mut new_vm_resp: grpc::NewVmResp) {
let newvmreq = match self.tmp_newvm_reqs.remove(&new_vm_resp.uuid) { let new_vm_req = match self.tmp_newvm_reqs.remove(&new_vm_resp.uuid) {
Some((_, r)) => r, Some((_, r)) => r,
None => { None => {
log::error!( log::error!(
@ -204,10 +204,10 @@ impl BrainData {
return; return;
} }
}; };
if let Err(e) = newvmreq.1.send(new_vm_resp.clone()) { if let Err(e) = new_vm_req.1.send(new_vm_resp.clone()) {
log::error!( log::error!(
"CLI RX for {} dropped before receiving confirmation {:?}. Error is: {:?}", "CLI RX for {} dropped before receiving confirmation {:?}. Error is: {:?}",
&newvmreq.0.admin_pubkey, &new_vm_req.0.admin_pubkey,
new_vm_resp, new_vm_resp,
e e
); );
@ -229,6 +229,7 @@ impl BrainData {
public_ipv6 = ipv6_addr.to_string(); public_ipv6 = ipv6_addr.to_string();
} }
} }
let contract = Contract { let contract = Contract {
uuid: new_vm_resp.uuid, uuid: new_vm_resp.uuid,
exposed_ports: args.exposed_ports, exposed_ports: args.exposed_ports,
@ -236,17 +237,24 @@ impl BrainData {
public_ipv6, public_ipv6,
created_at: Utc::now().to_rfc3339(), created_at: Utc::now().to_rfc3339(),
updated_at: String::new(), updated_at: String::new(),
hostname: newvmreq.0.hostname, hostname: new_vm_req.0.hostname,
admin_pubkey: newvmreq.0.admin_pubkey, admin_pubkey: new_vm_req.0.admin_pubkey,
node_pubkey: newvmreq.0.node_pubkey, node_pubkey: new_vm_req.0.node_pubkey.clone(),
disk_size_gb: newvmreq.0.disk_size_gb, disk_size_gb: new_vm_req.0.disk_size_gb,
vcpus: newvmreq.0.vcpus, vcpus: new_vm_req.0.vcpus,
memory_mb: newvmreq.0.memory_mb, memory_mb: new_vm_req.0.memory_mb,
kernel_sha: newvmreq.0.kernel_sha, kernel_sha: new_vm_req.0.kernel_sha,
dtrfs_sha: newvmreq.0.dtrfs_sha, dtrfs_sha: new_vm_req.0.dtrfs_sha,
}; };
info!("Created new contract: {contract:?}"); info!("Created new contract: {contract:?}");
self.contracts.write().unwrap().push(contract); self.contracts.write().unwrap().push(contract);
let args = new_vm_resp.args.as_mut().unwrap();
if args.dtrfs_api_endpoint.starts_with(':') {
if let Some(node) = self.find_nodes_by_pubkey(&new_vm_req.0.node_pubkey) {
args.dtrfs_api_endpoint = format!("{}{}", node.ip, args.dtrfs_api_endpoint);
}
}
} }
pub async fn submit_updatevm_resp(&self, mut resp: grpc::UpdateVmResp) { pub async fn submit_updatevm_resp(&self, mut resp: grpc::UpdateVmResp) {
@ -278,15 +286,7 @@ impl BrainData {
if args.dtrfs_api_endpoint.starts_with(':') { if args.dtrfs_api_endpoint.starts_with(':') {
if let Some(node) = self.find_nodes_by_pubkey(&contract.node_pubkey) { if let Some(node) = self.find_nodes_by_pubkey(&contract.node_pubkey) {
args.dtrfs_api_endpoint = format!("{}{}", node.ip, args.dtrfs_api_endpoint); args.dtrfs_api_endpoint = format!("{}{}", node.ip, args.dtrfs_api_endpoint);
} else { }
// This should never happen.
log::error!(
"Node {} not found for contract {}. Cannot update contract.",
contract.node_pubkey,
contract.uuid
);
return;
}
} }
contract.disk_size_gb = updatevmreq.0.disk_size_gb; contract.disk_size_gb = updatevmreq.0.disk_size_gb;