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
@@ -105,12 +105,20 @@ pub struct VmInfo {
|
||||
pub state: VmState,
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize, Serialize)]
|
||||
pub struct VmmPingResponse {
|
||||
pub version: String,
|
||||
}
|
||||
|
||||
pub enum ApiResponsePayload {
|
||||
/// No data is sent on the channel.
|
||||
Empty,
|
||||
|
||||
/// Virtual machine information
|
||||
VmInfo(VmInfo),
|
||||
|
||||
/// Vmm ping response
|
||||
VmmPing(VmmPingResponse),
|
||||
}
|
||||
|
||||
/// This is the response sent by the VMM API server through the mpsc channel.
|
||||
@@ -138,6 +146,9 @@ pub enum ApiRequest {
|
||||
/// Request the VM information.
|
||||
VmInfo(Sender<ApiResponse>),
|
||||
|
||||
/// Request the VMM API server status
|
||||
VmmPing(Sender<ApiResponse>),
|
||||
|
||||
/// Pause a VM.
|
||||
VmPause(Sender<ApiResponse>),
|
||||
|
||||
@@ -263,6 +274,22 @@ pub fn vm_info(api_evt: EventFd, api_sender: Sender<ApiRequest>) -> ApiResult<Vm
|
||||
}
|
||||
}
|
||||
|
||||
pub fn vmm_ping(api_evt: EventFd, api_sender: Sender<ApiRequest>) -> ApiResult<VmmPingResponse> {
|
||||
let (response_sender, response_receiver) = channel();
|
||||
|
||||
api_sender
|
||||
.send(ApiRequest::VmmPing(response_sender))
|
||||
.map_err(ApiError::RequestSend)?;
|
||||
api_evt.write(1).map_err(ApiError::EventFdWrite)?;
|
||||
|
||||
let vmm_pong = response_receiver.recv().map_err(ApiError::ResponseRecv)??;
|
||||
|
||||
match vmm_pong {
|
||||
ApiResponsePayload::VmmPing(pong) => Ok(pong),
|
||||
_ => Err(ApiError::ResponsePayloadType),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn vmm_shutdown(api_evt: EventFd, api_sender: Sender<ApiRequest>) -> ApiResult<()> {
|
||||
let (response_sender, response_receiver) = channel();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user