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:
Rob Bradford
2019-11-26 16:46:10 +00:00
parent e7d4eae527
commit 86339b4cb4
6 changed files with 117 additions and 3 deletions

View File

@@ -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(())
}