mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Add HTTP API to resize the VM
Currently only increasing the number of vCPUs is supported but in the future it will be extended. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
@@ -96,6 +96,9 @@ pub enum ApiError {
|
||||
|
||||
/// The VMM could not shutdown.
|
||||
VmmShutdown(VmError),
|
||||
|
||||
/// The VM could not be resized
|
||||
VmResize(VmError),
|
||||
}
|
||||
pub type ApiResult<T> = std::result::Result<T, ApiError>;
|
||||
|
||||
@@ -110,6 +113,11 @@ pub struct VmmPingResponse {
|
||||
pub version: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize, Serialize)]
|
||||
pub struct VmResizeData {
|
||||
pub desired_vcpus: u8,
|
||||
}
|
||||
|
||||
pub enum ApiResponsePayload {
|
||||
/// No data is sent on the channel.
|
||||
Empty,
|
||||
@@ -169,6 +177,9 @@ pub enum ApiRequest {
|
||||
/// This will shutdown and delete the current VM, if any, and then exit the
|
||||
/// VMM process.
|
||||
VmmShutdown(Sender<ApiResponse>),
|
||||
|
||||
//// Resuze the VMM
|
||||
VmResize(Arc<VmResizeData>, Sender<ApiResponse>),
|
||||
}
|
||||
|
||||
pub fn vm_create(
|
||||
@@ -303,3 +314,21 @@ pub fn vmm_shutdown(api_evt: EventFd, api_sender: Sender<ApiRequest>) -> ApiResu
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn vm_resize(
|
||||
api_evt: EventFd,
|
||||
api_sender: Sender<ApiRequest>,
|
||||
data: Arc<VmResizeData>,
|
||||
) -> ApiResult<()> {
|
||||
let (response_sender, response_receiver) = channel();
|
||||
|
||||
// Send the VM creation request.
|
||||
api_sender
|
||||
.send(ApiRequest::VmResize(data, response_sender))
|
||||
.map_err(ApiError::RequestSend)?;
|
||||
api_evt.write(1).map_err(ApiError::EventFdWrite)?;
|
||||
|
||||
response_receiver.recv().map_err(ApiError::ResponseRecv)??;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user