enable update for VM hostname

This commit is contained in:
ghe0 2025-03-21 23:05:45 +02:00
parent c48b4bf75e
commit 78525cc638
Signed by: ghe0
GPG Key ID: 451028EE56A0FBB4
2 changed files with 332 additions and 199 deletions

487
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -890,7 +890,7 @@ impl BrainData {
) { ) {
let uuid = req.uuid.clone(); let uuid = req.uuid.clone();
info!("Inserting new vm update request in memory: {req:?}"); info!("Inserting new vm update request in memory: {req:?}");
let node_pubkey = match self.find_contract_by_uuid(&req.uuid) { let contract = match self.find_contract_by_uuid(&req.uuid) {
Ok(contract) => { Ok(contract) => {
if contract.admin_pubkey != req.admin_pubkey { if contract.admin_pubkey != req.admin_pubkey {
let _ = tx.send(grpc::UpdateVmResp { let _ = tx.send(grpc::UpdateVmResp {
@ -900,7 +900,7 @@ impl BrainData {
}); });
return; return;
} }
contract.node_pubkey contract
} }
Err(_) => { Err(_) => {
log::warn!( log::warn!(
@ -915,8 +915,29 @@ impl BrainData {
return; return;
} }
}; };
let node_pubkey = contract.node_pubkey;
self.tmp_updatevm_reqs self.tmp_updatevm_reqs
.insert(req.uuid.clone(), (req.clone(), tx)); .insert(req.uuid.clone(), (req.clone(), tx));
let hostname_changed = self.set_vm_hostname(&uuid, &req.hostname);
if !((req.vcpus != 0 && contract.vcpus != req.vcpus)
|| (req.memory_mb != 0 && contract.memory_mb != req.memory_mb)
|| (!req.dtrfs_sha.is_empty() && contract.dtrfs_sha != req.dtrfs_sha)
|| (req.disk_size_gb != 0 && contract.disk_size_gb != req.disk_size_gb))
{
let mut error = String::new();
if !hostname_changed {
error = "No modification required".to_string()
};
self.submit_updatevm_resp(grpc::UpdateVmResp {
uuid,
error,
args: None,
})
.await;
return;
}
if let Some(server_tx) = self.daemon_tx.get(&node_pubkey) { if let Some(server_tx) = self.daemon_tx.get(&node_pubkey) {
debug!( debug!(
"Found daemon TX for {}. Sending updateVMReq {}", "Found daemon TX for {}. Sending updateVMReq {}",
@ -953,6 +974,25 @@ impl BrainData {
} }
} }
/// Return true if the name of the VM got changed.
pub fn set_vm_hostname(&self, uuid: &str, hostname: &str) -> bool {
if hostname.is_empty() {
return false;
}
let mut contracts = self.vm_contracts.write().unwrap();
for c in contracts.iter_mut() {
if c.uuid == uuid {
if c.hostname != hostname {
c.hostname = hostname.to_string();
return true;
} else {
return false;
}
}
}
false
}
pub fn find_node_by_pubkey(&self, public_key: &str) -> Option<VmNode> { pub fn find_node_by_pubkey(&self, public_key: &str) -> Option<VmNode> {
let nodes = self.vm_nodes.read().unwrap(); let nodes = self.vm_nodes.read().unwrap();
nodes.iter().cloned().find(|n| n.public_key == public_key) nodes.iter().cloned().find(|n| n.public_key == public_key)