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