vmm: Implement the /api/v1/vm.delete endpoint

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Samuel Ortiz
2019-10-01 17:24:39 +02:00
parent f9daf2e247
commit 7328ecdb3b
4 changed files with 46 additions and 15 deletions
+24
View File
@@ -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() {