mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Add "add-pmem" to the API
Add the HTTP and internal API entry points for adding persistent memory at runtime. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
committed by
Sebastien Boeuf
parent
15de30f141
commit
f6f4c68fb4
@@ -5,10 +5,10 @@
|
||||
|
||||
use crate::api::http::EndpointHandler;
|
||||
use crate::api::{
|
||||
vm_add_device, vm_add_disk, vm_boot, vm_create, vm_delete, vm_info, vm_pause, vm_reboot,
|
||||
vm_remove_device, vm_resize, vm_resume, vm_shutdown, vmm_ping, vmm_shutdown, ApiError,
|
||||
ApiRequest, ApiResult, DeviceConfig, DiskConfig, VmAction, VmConfig, VmRemoveDeviceData,
|
||||
VmResizeData,
|
||||
vm_add_device, vm_add_disk, vm_add_pmem, vm_boot, vm_create, vm_delete, vm_info, vm_pause,
|
||||
vm_reboot, vm_remove_device, vm_resize, vm_resume, vm_shutdown, vmm_ping, vmm_shutdown,
|
||||
ApiError, ApiRequest, ApiResult, DeviceConfig, DiskConfig, PmemConfig, VmAction, VmConfig,
|
||||
VmRemoveDeviceData, VmResizeData,
|
||||
};
|
||||
use micro_http::{Body, Method, Request, Response, StatusCode, Version};
|
||||
use serde_json::Error as SerdeError;
|
||||
@@ -63,6 +63,9 @@ pub enum HttpError {
|
||||
|
||||
/// Could not add a disk to a VM
|
||||
VmAddDisk(ApiError),
|
||||
|
||||
/// Could not add a pmem device to a VM
|
||||
VmAddPmem(ApiError),
|
||||
}
|
||||
|
||||
fn error_response(error: HttpError, status: StatusCode) -> Response {
|
||||
@@ -395,3 +398,41 @@ impl EndpointHandler for VmAddDisk {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// /api/v1/vm.add-pmem handler
|
||||
pub struct VmAddPmem {}
|
||||
|
||||
impl EndpointHandler for VmAddPmem {
|
||||
fn handle_request(
|
||||
&self,
|
||||
req: &Request,
|
||||
api_notifier: EventFd,
|
||||
api_sender: Sender<ApiRequest>,
|
||||
) -> Response {
|
||||
match req.method() {
|
||||
Method::Put => {
|
||||
match &req.body {
|
||||
Some(body) => {
|
||||
// Deserialize into a PmemConfig
|
||||
let vm_add_pmem_data: PmemConfig = match serde_json::from_slice(body.raw())
|
||||
.map_err(HttpError::SerdeJsonDeserialize)
|
||||
{
|
||||
Ok(config) => config,
|
||||
Err(e) => return error_response(e, StatusCode::BadRequest),
|
||||
};
|
||||
|
||||
match vm_add_pmem(api_notifier, api_sender, Arc::new(vm_add_pmem_data))
|
||||
.map_err(HttpError::VmAddPmem)
|
||||
{
|
||||
Ok(_) => Response::new(Version::Http11, StatusCode::NoContent),
|
||||
Err(e) => error_response(e, StatusCode::InternalServerError),
|
||||
}
|
||||
}
|
||||
|
||||
None => Response::new(Version::Http11, StatusCode::BadRequest),
|
||||
}
|
||||
}
|
||||
_ => Response::new(Version::Http11, StatusCode::BadRequest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user