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

@@ -5,8 +5,8 @@
use crate::api::http::EndpointHandler;
use crate::api::{
vm_boot, vm_create, vm_delete, vm_info, vm_pause, vm_reboot, vm_resume, vm_shutdown, vmm_ping,
vmm_shutdown, ApiError, ApiRequest, ApiResult, VmAction, VmConfig,
vm_boot, vm_create, vm_delete, vm_info, vm_pause, vm_reboot, vm_resize, vm_resume, vm_shutdown,
vmm_ping, vmm_shutdown, ApiError, ApiRequest, ApiResult, VmAction, VmConfig, VmResizeData,
};
use micro_http::{Body, Method, Request, Response, StatusCode, Version};
use serde_json::Error as SerdeError;
@@ -219,3 +219,42 @@ impl EndpointHandler for VmmShutdown {
}
}
}
// /api/v1/vm.resize handler
pub struct VmResize {}
impl EndpointHandler for VmResize {
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 VmConfig
let vm_resize_data: VmResizeData = match serde_json::from_slice(body.raw())
.map_err(HttpError::SerdeJsonDeserialize)
{
Ok(config) => config,
Err(e) => return error_response(e, StatusCode::BadRequest),
};
// Call vm_resize()
match vm_resize(api_notifier, api_sender, Arc::new(vm_resize_data))
.map_err(HttpError::VmCreate)
{
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),
}
}
}