1#[cfg(target_os = "macos")]
8pub mod apple_vz;
9
10#[cfg(target_os = "linux")]
11pub mod cloud_hv;
12
13#[cfg(target_os = "windows")]
14pub mod boot;
15
16#[cfg(target_os = "windows")]
17pub mod whp;
18
19#[cfg(any(target_os = "macos", target_os = "linux"))]
20mod ready;
21
22use crate::config::{VmConfig, VmHandle, VmState};
23#[cfg(any(target_os = "macos", target_os = "linux"))]
24pub(crate) use ready::{check_ready_marker, ReadyMarkerCache};
25
26pub trait VmDriver: Send + Sync {
32 fn boot(&self, config: &VmConfig) -> Result<VmHandle, VmError>;
38
39 fn stop(&self, handle: &VmHandle) -> Result<(), VmError>;
43
44 fn kill(&self, handle: &VmHandle) -> Result<(), VmError>;
48
49 fn state(&self, handle: &VmHandle) -> Result<VmState, VmError>;
51
52 fn pause(&self, handle: &VmHandle) -> Result<(), VmError> {
56 Err(VmError::Hypervisor(format!(
57 "pause is not supported by this driver for VM '{}'",
58 handle.name
59 )))
60 }
61
62 fn resume(&self, handle: &VmHandle) -> Result<(), VmError> {
66 Err(VmError::Hypervisor(format!(
67 "resume is not supported by this driver for VM '{}'",
68 handle.name
69 )))
70 }
71}
72
73#[derive(Debug, thiserror::Error)]
75pub enum VmError {
76 #[error("boot failed for '{name}': {detail}")]
78 BootFailed { name: String, detail: String },
79
80 #[error("VM '{name}' not found")]
82 NotFound { name: String },
83
84 #[error("failed to stop '{name}': {detail}")]
86 StopFailed { name: String, detail: String },
87
88 #[error("failed to query state for '{name}': {detail}")]
90 StateFailed { name: String, detail: String },
91
92 #[error("hypervisor error: {0}")]
94 Hypervisor(String),
95
96 #[error("I/O error: {0}")]
98 Io(#[from] std::io::Error),
99
100 #[error("invalid config: {0}")]
102 InvalidConfig(String),
103}
104
105impl From<crate::oci::registry::OciError> for VmError {
106 fn from(e: crate::oci::registry::OciError) -> Self {
107 VmError::Hypervisor(format!("OCI error: {}", e))
108 }
109}
110
111impl From<crate::setup::SetupError> for VmError {
112 fn from(e: crate::setup::SetupError) -> Self {
113 VmError::Hypervisor(format!("setup error: {}", e))
114 }
115}