enable update for VM hostname
This commit is contained in:
parent
c48b4bf75e
commit
78525cc638
487
Cargo.lock
generated
487
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
44
src/data.rs
44
src/data.rs
@ -890,7 +890,7 @@ impl BrainData {
|
||||
) {
|
||||
let uuid = req.uuid.clone();
|
||||
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) => {
|
||||
if contract.admin_pubkey != req.admin_pubkey {
|
||||
let _ = tx.send(grpc::UpdateVmResp {
|
||||
@ -900,7 +900,7 @@ impl BrainData {
|
||||
});
|
||||
return;
|
||||
}
|
||||
contract.node_pubkey
|
||||
contract
|
||||
}
|
||||
Err(_) => {
|
||||
log::warn!(
|
||||
@ -915,8 +915,29 @@ impl BrainData {
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let node_pubkey = contract.node_pubkey;
|
||||
self.tmp_updatevm_reqs
|
||||
.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) {
|
||||
debug!(
|
||||
"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> {
|
||||
let nodes = self.vm_nodes.read().unwrap();
|
||||
nodes.iter().cloned().find(|n| n.public_key == public_key)
|
||||
|
Loading…
Reference in New Issue
Block a user