mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Implement the /api/v1/vm.delete endpoint
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
@@ -307,6 +307,22 @@ impl Vmm {
|
||||
}
|
||||
}
|
||||
|
||||
fn vm_delete(&mut self) -> result::Result<(), VmError> {
|
||||
if self.vm_config.is_none() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
self.vm_config = None;
|
||||
|
||||
// First we shut the current VM down if necessary.
|
||||
if let Some(ref mut vm) = self.vm {
|
||||
vm.shutdown()?;
|
||||
self.vm = None;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn control_loop(&mut self, api_receiver: Arc<Receiver<ApiRequest>>) -> Result<ExitBehaviour> {
|
||||
const EPOLL_EVENTS_LEN: usize = 100;
|
||||
|
||||
@@ -377,6 +393,14 @@ impl Vmm {
|
||||
|
||||
sender.send(response).map_err(Error::ApiResponseSend)?;
|
||||
}
|
||||
ApiRequest::VmDelete(sender) => {
|
||||
let response = match self.vm_delete() {
|
||||
Ok(_) => Ok(ApiResponsePayload::Empty),
|
||||
Err(e) => Err(ApiError::VmDelete(e)),
|
||||
};
|
||||
|
||||
sender.send(response).map_err(Error::ApiResponseSend)?;
|
||||
}
|
||||
ApiRequest::VmBoot(sender) => {
|
||||
// If we don't have a config, we can not boot a VM.
|
||||
if self.vm_config.is_none() {
|
||||
|
||||
Reference in New Issue
Block a user