mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
http: api: implement vmm.ping
vmm.ping will help to check if http API server is up and running. This also removes the vmm.info endpoint. Signed-off-by: Jose Carlos Venegas Munoz <jose.carlos.venegas.munoz@intel.com>
This commit is contained in:
committed by
Sebastien Boeuf
parent
348a1bc30e
commit
a518651402
@@ -5,7 +5,7 @@
|
||||
|
||||
use crate::api::http::EndpointHandler;
|
||||
use crate::api::{
|
||||
vm_boot, vm_create, vm_delete, vm_info, vm_pause, vm_reboot, vm_resume, vm_shutdown,
|
||||
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,
|
||||
};
|
||||
use micro_http::{Body, Method, Request, Response, StatusCode, Version};
|
||||
@@ -46,6 +46,9 @@ pub enum HttpError {
|
||||
|
||||
/// Could not shut the VMM down
|
||||
VmmShutdown(ApiError),
|
||||
|
||||
/// Could not handle VMM ping
|
||||
VmmPing(ApiError),
|
||||
}
|
||||
|
||||
fn error_response(error: HttpError, status: StatusCode) -> Response {
|
||||
@@ -169,6 +172,32 @@ impl EndpointHandler for VmInfo {
|
||||
}
|
||||
}
|
||||
|
||||
// /api/v1/vmm.info handler
|
||||
pub struct VmmPing {}
|
||||
|
||||
impl EndpointHandler for VmmPing {
|
||||
fn handle_request(
|
||||
&self,
|
||||
req: &Request,
|
||||
api_notifier: EventFd,
|
||||
api_sender: Sender<ApiRequest>,
|
||||
) -> Response {
|
||||
match req.method() {
|
||||
Method::Get => match vmm_ping(api_notifier, api_sender).map_err(HttpError::VmmPing) {
|
||||
Ok(pong) => {
|
||||
let mut response = Response::new(Version::Http11, StatusCode::OK);
|
||||
let info_serialized = serde_json::to_string(&pong).unwrap();
|
||||
|
||||
response.set_body(Body::new(info_serialized));
|
||||
response
|
||||
}
|
||||
Err(e) => error_response(e, StatusCode::InternalServerError),
|
||||
},
|
||||
_ => Response::new(Version::Http11, StatusCode::BadRequest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// /api/v1/vmm.shutdown handler
|
||||
pub struct VmmShutdown {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user