mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: api: Move HttpError enum to http module
Minor rearrangement of code to make it easier to implement refactoring. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
@@ -7,17 +7,85 @@ use crate::api::http_endpoint::{
|
|||||||
VmActionHandler, VmAddDevice, VmAddDisk, VmAddFs, VmAddNet, VmAddPmem, VmAddVsock, VmCreate,
|
VmActionHandler, VmAddDevice, VmAddDisk, VmAddFs, VmAddNet, VmAddPmem, VmAddVsock, VmCreate,
|
||||||
VmInfo, VmRemoveDevice, VmResize, VmRestore, VmSnapshot, VmmPing, VmmShutdown,
|
VmInfo, VmRemoveDevice, VmResize, VmRestore, VmSnapshot, VmmPing, VmmShutdown,
|
||||||
};
|
};
|
||||||
use crate::api::{ApiRequest, VmAction};
|
use crate::api::{ApiError, ApiRequest, VmAction};
|
||||||
use crate::seccomp_filters::{get_seccomp_filter, Thread};
|
use crate::seccomp_filters::{get_seccomp_filter, Thread};
|
||||||
use crate::{Error, Result};
|
use crate::{Error, Result};
|
||||||
use micro_http::{HttpServer, MediaType, Request, Response, StatusCode, Version};
|
use micro_http::{HttpServer, MediaType, Request, Response, StatusCode, Version};
|
||||||
use seccomp::{SeccompFilter, SeccompLevel};
|
use seccomp::{SeccompFilter, SeccompLevel};
|
||||||
|
use serde_json::Error as SerdeError;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use vmm_sys_util::eventfd::EventFd;
|
use vmm_sys_util::eventfd::EventFd;
|
||||||
|
|
||||||
|
/// Errors associated with VMM management
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum HttpError {
|
||||||
|
/// API request receive error
|
||||||
|
SerdeJsonDeserialize(SerdeError),
|
||||||
|
|
||||||
|
/// Could not create a VM
|
||||||
|
VmCreate(ApiError),
|
||||||
|
|
||||||
|
/// Could not boot a VM
|
||||||
|
VmBoot(ApiError),
|
||||||
|
|
||||||
|
/// Could not get the VM information
|
||||||
|
VmInfo(ApiError),
|
||||||
|
|
||||||
|
/// Could not pause the VM
|
||||||
|
VmPause(ApiError),
|
||||||
|
|
||||||
|
/// Could not pause the VM
|
||||||
|
VmResume(ApiError),
|
||||||
|
|
||||||
|
/// Could not shut a VM down
|
||||||
|
VmShutdown(ApiError),
|
||||||
|
|
||||||
|
/// Could not reboot a VM
|
||||||
|
VmReboot(ApiError),
|
||||||
|
|
||||||
|
/// Could not snapshot a VM
|
||||||
|
VmSnapshot(ApiError),
|
||||||
|
|
||||||
|
/// Could not restore a VM
|
||||||
|
VmRestore(ApiError),
|
||||||
|
|
||||||
|
/// Could not act on a VM
|
||||||
|
VmAction(ApiError),
|
||||||
|
|
||||||
|
/// Could not resize a VM
|
||||||
|
VmResize(ApiError),
|
||||||
|
|
||||||
|
/// Could not add a device to a VM
|
||||||
|
VmAddDevice(ApiError),
|
||||||
|
|
||||||
|
/// Could not remove a device from a VM
|
||||||
|
VmRemoveDevice(ApiError),
|
||||||
|
|
||||||
|
/// Could not shut the VMM down
|
||||||
|
VmmShutdown(ApiError),
|
||||||
|
|
||||||
|
/// Could not handle VMM ping
|
||||||
|
VmmPing(ApiError),
|
||||||
|
|
||||||
|
/// Could not add a disk to a VM
|
||||||
|
VmAddDisk(ApiError),
|
||||||
|
|
||||||
|
/// Could not add a fs to a VM
|
||||||
|
VmAddFs(ApiError),
|
||||||
|
|
||||||
|
/// Could not add a pmem device to a VM
|
||||||
|
VmAddPmem(ApiError),
|
||||||
|
|
||||||
|
/// Could not add a network device to a VM
|
||||||
|
VmAddNet(ApiError),
|
||||||
|
|
||||||
|
/// Could not add a vsock device to a VM
|
||||||
|
VmAddVsock(ApiError),
|
||||||
|
}
|
||||||
|
|
||||||
const HTTP_ROOT: &str = "/api/v1";
|
const HTTP_ROOT: &str = "/api/v1";
|
||||||
|
|
||||||
/// An HTTP endpoint handler interface
|
/// An HTTP endpoint handler interface
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
//
|
//
|
||||||
|
|
||||||
use crate::api::http::EndpointHandler;
|
use crate::api::http::{EndpointHandler, HttpError};
|
||||||
use crate::api::{
|
use crate::api::{
|
||||||
vm_add_device, vm_add_disk, vm_add_fs, vm_add_net, vm_add_pmem, vm_add_vsock, vm_boot,
|
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_create, vm_delete, vm_info, vm_pause, vm_reboot, vm_remove_device, vm_resize, vm_restore,
|
||||||
@@ -12,78 +12,10 @@ use crate::api::{
|
|||||||
VmRemoveDeviceData, VmResizeData, VmSnapshotConfig, VsockConfig,
|
VmRemoveDeviceData, VmResizeData, VmSnapshotConfig, VsockConfig,
|
||||||
};
|
};
|
||||||
use micro_http::{Body, Method, Request, Response, StatusCode, Version};
|
use micro_http::{Body, Method, Request, Response, StatusCode, Version};
|
||||||
use serde_json::Error as SerdeError;
|
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use vmm_sys_util::eventfd::EventFd;
|
use vmm_sys_util::eventfd::EventFd;
|
||||||
|
|
||||||
/// Errors associated with VMM management
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum HttpError {
|
|
||||||
/// API request receive error
|
|
||||||
SerdeJsonDeserialize(SerdeError),
|
|
||||||
|
|
||||||
/// Could not create a VM
|
|
||||||
VmCreate(ApiError),
|
|
||||||
|
|
||||||
/// Could not boot a VM
|
|
||||||
VmBoot(ApiError),
|
|
||||||
|
|
||||||
/// Could not get the VM information
|
|
||||||
VmInfo(ApiError),
|
|
||||||
|
|
||||||
/// Could not pause the VM
|
|
||||||
VmPause(ApiError),
|
|
||||||
|
|
||||||
/// Could not pause the VM
|
|
||||||
VmResume(ApiError),
|
|
||||||
|
|
||||||
/// Could not shut a VM down
|
|
||||||
VmShutdown(ApiError),
|
|
||||||
|
|
||||||
/// Could not reboot a VM
|
|
||||||
VmReboot(ApiError),
|
|
||||||
|
|
||||||
/// Could not snapshot a VM
|
|
||||||
VmSnapshot(ApiError),
|
|
||||||
|
|
||||||
/// Could not restore a VM
|
|
||||||
VmRestore(ApiError),
|
|
||||||
|
|
||||||
/// Could not act on a VM
|
|
||||||
VmAction(ApiError),
|
|
||||||
|
|
||||||
/// Could not resize a VM
|
|
||||||
VmResize(ApiError),
|
|
||||||
|
|
||||||
/// Could not add a device to a VM
|
|
||||||
VmAddDevice(ApiError),
|
|
||||||
|
|
||||||
/// Could not remove a device from a VM
|
|
||||||
VmRemoveDevice(ApiError),
|
|
||||||
|
|
||||||
/// Could not shut the VMM down
|
|
||||||
VmmShutdown(ApiError),
|
|
||||||
|
|
||||||
/// Could not handle VMM ping
|
|
||||||
VmmPing(ApiError),
|
|
||||||
|
|
||||||
/// Could not add a disk to a VM
|
|
||||||
VmAddDisk(ApiError),
|
|
||||||
|
|
||||||
/// Could not add a fs to a VM
|
|
||||||
VmAddFs(ApiError),
|
|
||||||
|
|
||||||
/// Could not add a pmem device to a VM
|
|
||||||
VmAddPmem(ApiError),
|
|
||||||
|
|
||||||
/// Could not add a network device to a VM
|
|
||||||
VmAddNet(ApiError),
|
|
||||||
|
|
||||||
/// Could not add a vsock device to a VM
|
|
||||||
VmAddVsock(ApiError),
|
|
||||||
}
|
|
||||||
|
|
||||||
fn error_response(error: HttpError, status: StatusCode) -> Response {
|
fn error_response(error: HttpError, status: StatusCode) -> Response {
|
||||||
let mut response = Response::new(Version::Http11, status);
|
let mut response = Response::new(Version::Http11, status);
|
||||||
response.set_body(Body::new(format!("{:?}", error)));
|
response.set_body(Body::new(format!("{:?}", error)));
|
||||||
|
|||||||
Reference in New Issue
Block a user