vmm: Implement HTTP API for obtaining counters

The counters are a hash of device name to hash of counter name to u64
value. Currently the API is only implemented with a stub that returns an
empty set of counters.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford
2020-06-24 11:20:13 +01:00
committed by Samuel Ortiz
parent fd4aba8eae
commit bca8a19244
5 changed files with 57 additions and 3 deletions

View File

@@ -94,6 +94,9 @@ pub enum HttpError {
/// Could not add a vsock device to a VM
VmAddVsock(ApiError),
/// Could not get counters from VM
VmCounters(ApiError),
}
impl From<serde_json::Error> for HttpError {
@@ -193,6 +196,7 @@ lazy_static! {
r.routes.insert(endpoint!("/vm.add-pmem"), Box::new(VmActionHandler::new(VmAction::AddPmem(Arc::default()))));
r.routes.insert(endpoint!("/vm.add-vsock"), Box::new(VmActionHandler::new(VmAction::AddVsock(Arc::default()))));
r.routes.insert(endpoint!("/vm.boot"), Box::new(VmActionHandler::new(VmAction::Boot)));
r.routes.insert(endpoint!("/vm.counters"), Box::new(VmActionHandler::new(VmAction::Counters)));
r.routes.insert(endpoint!("/vm.create"), Box::new(VmCreate {}));
r.routes.insert(endpoint!("/vm.delete"), Box::new(VmActionHandler::new(VmAction::Delete)));
r.routes.insert(endpoint!("/vm.info"), Box::new(VmInfo {}));

View File

@@ -6,8 +6,9 @@
use crate::api::http::{error_response, EndpointHandler, HttpError};
use crate::api::{
vm_add_device, vm_add_disk, vm_add_fs, vm_add_net, vm_add_pmem, vm_add_vsock, vm_boot,
vm_create, vm_delete, vm_info, vm_pause, vm_reboot, vm_remove_device, vm_resize, vm_restore,
vm_resume, vm_shutdown, vm_snapshot, vmm_ping, vmm_shutdown, ApiRequest, VmAction, VmConfig,
vm_counters, vm_create, vm_delete, vm_info, vm_pause, vm_reboot, vm_remove_device, vm_resize,
vm_restore, vm_resume, vm_shutdown, vm_snapshot, vmm_ping, vmm_shutdown, ApiRequest, VmAction,
VmConfig,
};
use micro_http::{Body, Method, Request, Response, StatusCode, Version};
use std::sync::mpsc::Sender;
@@ -159,6 +160,19 @@ impl EndpointHandler for VmActionHandler {
}
}
}
fn get_handler(
&self,
api_notifier: EventFd,
api_sender: Sender<ApiRequest>,
_body: &Option<Body>,
) -> std::result::Result<Option<Body>, HttpError> {
use VmAction::*;
match self.action {
Counters => vm_counters(api_notifier, api_sender).map_err(HttpError::VmCounters),
_ => Err(HttpError::BadRequest),
}
}
}
// /api/v1/vm.info handler

View File

@@ -214,6 +214,9 @@ pub enum ApiRequest {
/// Resume a VM.
VmResume(Sender<ApiResponse>),
/// Get counters for a VM.
VmCounters(Sender<ApiResponse>),
/// Shut the previously booted virtual machine down.
/// If the VM was not previously booted or created, the VMM API server
/// will send a VmShutdown error back.
@@ -300,6 +303,9 @@ pub enum VmAction {
/// Resume a VM
Resume,
/// Return VM counters
Counters,
/// Add VFIO device
AddDevice(Arc<DeviceConfig>),
@@ -346,6 +352,7 @@ fn vm_action(
Reboot => ApiRequest::VmReboot(response_sender),
Pause => ApiRequest::VmPause(response_sender),
Resume => ApiRequest::VmResume(response_sender),
Counters => ApiRequest::VmCounters(response_sender),
AddDevice(v) => ApiRequest::VmAddDevice(v, response_sender),
AddDisk(v) => ApiRequest::VmAddDisk(v, response_sender),
AddFs(v) => ApiRequest::VmAddFs(v, response_sender),
@@ -395,6 +402,10 @@ pub fn vm_resume(api_evt: EventFd, api_sender: Sender<ApiRequest>) -> ApiResult<
vm_action(api_evt, api_sender, VmAction::Resume)
}
pub fn vm_counters(api_evt: EventFd, api_sender: Sender<ApiRequest>) -> ApiResult<Option<Body>> {
vm_action(api_evt, api_sender, VmAction::Counters)
}
pub fn vm_snapshot(
api_evt: EventFd,
api_sender: Sender<ApiRequest>,