#[cfg(target_os = "macos")]
pub mod apple_vz;
#[cfg(target_os = "linux")]
pub mod cloud_hv;
#[cfg(target_os = "windows")]
pub mod boot;
#[cfg(target_os = "windows")]
pub mod whp;
#[cfg(any(target_os = "macos", target_os = "linux"))]
mod ready;
use crate::config::{VmConfig, VmHandle, VmState};
#[cfg(any(target_os = "macos", target_os = "linux"))]
pub(crate) use ready::{check_ready_marker, ReadyMarkerCache};
pub trait VmDriver: Send + Sync {
fn boot(&self, config: &VmConfig) -> Result<VmHandle, VmError>;
fn stop(&self, handle: &VmHandle) -> Result<(), VmError>;
fn kill(&self, handle: &VmHandle) -> Result<(), VmError>;
fn state(&self, handle: &VmHandle) -> Result<VmState, VmError>;
fn pause(&self, handle: &VmHandle) -> Result<(), VmError> {
Err(VmError::Hypervisor(format!(
"pause is not supported by this driver for VM '{}'",
handle.name
)))
}
fn resume(&self, handle: &VmHandle) -> Result<(), VmError> {
Err(VmError::Hypervisor(format!(
"resume is not supported by this driver for VM '{}'",
handle.name
)))
}
}
#[derive(Debug, thiserror::Error)]
pub enum VmError {
#[error("boot failed for '{name}': {detail}")]
BootFailed { name: String, detail: String },
#[error("VM '{name}' not found")]
NotFound { name: String },
#[error("failed to stop '{name}': {detail}")]
StopFailed { name: String, detail: String },
#[error("failed to query state for '{name}': {detail}")]
StateFailed { name: String, detail: String },
#[error("hypervisor error: {0}")]
Hypervisor(String),
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("invalid config: {0}")]
InvalidConfig(String),
}
impl From<crate::oci::registry::OciError> for VmError {
fn from(e: crate::oci::registry::OciError) -> Self {
VmError::Hypervisor(format!("OCI error: {}", e))
}
}
impl From<crate::setup::SetupError> for VmError {
fn from(e: crate::setup::SetupError) -> Self {
VmError::Hypervisor(format!("setup error: {}", e))
}
}