refactored the vm update process
This commit is contained in:
parent
1a4cec421b
commit
56f88aad3f
38
src/state.rs
38
src/state.rs
@ -401,22 +401,14 @@ impl From<VM> for snp_proto::MeasurementArgs {
|
||||
impl From<VM> for snp_proto::NewVmResp {
|
||||
fn from(vm: VM) -> Self {
|
||||
let uuid = vm.uuid.clone();
|
||||
snp_proto::NewVmResp {
|
||||
uuid,
|
||||
args: Some(vm.into()),
|
||||
error: "".to_string(),
|
||||
}
|
||||
snp_proto::NewVmResp { uuid, args: Some(vm.into()), error: "".to_string() }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<VM> for snp_proto::UpdateVmResp {
|
||||
fn from(vm: VM) -> Self {
|
||||
let uuid = vm.uuid.clone();
|
||||
snp_proto::UpdateVmResp {
|
||||
uuid,
|
||||
args: Some(vm.into()),
|
||||
error: "".to_string(),
|
||||
}
|
||||
snp_proto::UpdateVmResp { uuid, args: Some(vm.into()), error: "".to_string() }
|
||||
}
|
||||
}
|
||||
|
||||
@ -628,20 +620,22 @@ impl VM {
|
||||
config: &Config,
|
||||
res: &mut Resources,
|
||||
) -> Result<(), VMCreationErrors> {
|
||||
if config.max_cores_per_vm < req.vcpus {
|
||||
if req.vcpus > 0 && config.max_cores_per_vm < req.vcpus {
|
||||
return Err(VMCreationErrors::TooManyCores);
|
||||
}
|
||||
if config.max_vcpu_reservation
|
||||
< res.reserved_vcpus.saturating_sub(self.vcpus).saturating_add(req.vcpus)
|
||||
if req.vcpus > 0
|
||||
&& config.max_vcpu_reservation
|
||||
< res.reserved_vcpus.saturating_sub(self.vcpus).saturating_add(req.vcpus)
|
||||
{
|
||||
return Err(VMCreationErrors::NotEnoughCPU);
|
||||
}
|
||||
if config.max_mem_reservation_mb
|
||||
< res.reserved_memory.saturating_sub(self.memory_mb).saturating_add(req.memory_mb)
|
||||
if req.memory_mb > 0
|
||||
&& config.max_mem_reservation_mb
|
||||
< res.reserved_memory.saturating_sub(self.memory_mb).saturating_add(req.memory_mb)
|
||||
{
|
||||
return Err(VMCreationErrors::NotEnoughMemory);
|
||||
}
|
||||
if req.disk_size_gb < self.disk_size_gb {
|
||||
if req.disk_size_gb > 0 && req.disk_size_gb < self.disk_size_gb {
|
||||
return Err(VMCreationErrors::DiskTooSmall);
|
||||
}
|
||||
|
||||
@ -683,9 +677,15 @@ impl VM {
|
||||
});
|
||||
let _ = res.save_to_disk();
|
||||
|
||||
self.memory_mb = req.memory_mb;
|
||||
self.vcpus = req.vcpus;
|
||||
self.disk_size_gb = req.disk_size_gb;
|
||||
if req.memory_mb != 0 {
|
||||
self.memory_mb = req.memory_mb;
|
||||
}
|
||||
if req.vcpus != 0 {
|
||||
self.vcpus = req.vcpus;
|
||||
}
|
||||
if req.disk_size_gb != 0 {
|
||||
self.disk_size_gb = req.disk_size_gb;
|
||||
}
|
||||
|
||||
if let Err(e) = systemctl_stop_and_disable(&self.uuid) {
|
||||
return Err(VMCreationErrors::HypervizorError(e.to_string()));
|
||||
|
Loading…
Reference in New Issue
Block a user