1use std::fmt;
4use std::path::Path;
5
6use anyhow::Result;
7use async_trait::async_trait;
8
9use crate::types::{OutputSink, SnapshotId, SnapshotLabel, VmConfig};
10
11#[async_trait]
13pub trait VmBackend: Send + Sync + fmt::Debug {
14 async fn create(&self, image: &str, config: &VmConfig) -> Result<Box<dyn Vm>>;
16
17 async fn restore(&self, snapshot: &SnapshotId, config: &VmConfig) -> Result<Box<dyn Vm>>;
19
20 async fn snapshot_exists(&self, snapshot: &SnapshotId) -> Result<bool>;
22
23 async fn remove_snapshot(&self, snapshot: &SnapshotId) -> Result<()>;
25}
26
27#[async_trait]
29pub trait Vm: Send {
30 async fn inject(&self, host_path: &Path, guest_path: &str) -> Result<()>;
32
33 async fn exec(
35 &self,
36 cmd: &str,
37 env: &[(String, String)],
38 working_dir: &str,
39 sink: &dyn OutputSink,
40 ) -> Result<i32>;
41
42 async fn snapshot(&mut self, label: &SnapshotLabel) -> Result<SnapshotId>;
44
45 async fn destroy(&mut self) -> Result<()>;
47}