pub struct VmManager { /* private fields */ }Expand description
VM manager - orchestrates VM lifecycle.
Implementations§
Source§impl VmManager
impl VmManager
Sourcepub fn new(config: BoxConfig, event_emitter: EventEmitter) -> Self
pub fn new(config: BoxConfig, event_emitter: EventEmitter) -> Self
Create a new VM manager.
Sourcepub fn with_box_id(
config: BoxConfig,
event_emitter: EventEmitter,
box_id: String,
) -> Self
pub fn with_box_id( config: BoxConfig, event_emitter: EventEmitter, box_id: String, ) -> Self
Create a new VM manager with a specific box ID.
Sourcepub fn with_provider(
config: BoxConfig,
event_emitter: EventEmitter,
provider: Box<dyn VmmProvider>,
) -> Self
pub fn with_provider( config: BoxConfig, event_emitter: EventEmitter, provider: Box<dyn VmmProvider>, ) -> Self
Create a new VM manager with a custom VMM provider.
Sourcepub fn exec_client(&self) -> Option<&ExecClient>
pub fn exec_client(&self) -> Option<&ExecClient>
Get the exec client, if connected.
Sourcepub async fn attach_running_process(
&mut self,
pid: u32,
exec_socket_path: PathBuf,
pty_socket_path: Option<PathBuf>,
) -> Result<()>
pub async fn attach_running_process( &mut self, pid: u32, exec_socket_path: PathBuf, pty_socket_path: Option<PathBuf>, ) -> Result<()>
Attach this manager to an already-running shim process.
This is useful for crash recovery or control-plane restart flows where the workload VM is still alive and only the host-side manager state needs to be reconstructed.
Sourcepub fn exec_socket_path(&self) -> Option<&Path>
pub fn exec_socket_path(&self) -> Option<&Path>
Get the exec socket path, if the VM has been booted.
Sourcepub fn pty_socket_path(&self) -> Option<&Path>
pub fn pty_socket_path(&self) -> Option<&Path>
Get the PTY socket path, if the VM has been booted.
Sourcepub fn port_forward_socket_path(&self) -> Option<&Path>
pub fn port_forward_socket_path(&self) -> Option<&Path>
Get the CRI port-forward socket path, if the VM has been booted.
Sourcepub fn set_provider(&mut self, provider: Box<dyn VmmProvider>)
pub fn set_provider(&mut self, provider: Box<dyn VmmProvider>)
Inject a custom VMM provider (e.g., a VmController with a known shim path).
If set before boot(), the injected provider is used instead of the
default VmController::find_shim() fallback.
Sourcepub fn set_rootfs_provider(&mut self, provider: Box<dyn RootfsProvider>)
pub fn set_rootfs_provider(&mut self, provider: Box<dyn RootfsProvider>)
Override the rootfs provider (overlay or copy).
By default, default_provider() auto-detects the best available provider.
Call this before boot() to force a specific provider.
Sourcepub fn rootfs_provider_name(&self) -> &str
pub fn rootfs_provider_name(&self) -> &str
Get the name of the active rootfs provider.
Sourcepub fn set_pull_progress_fn(
&mut self,
f: Arc<dyn Fn(usize, usize, &str, i64) + Send + Sync>,
)
pub fn set_pull_progress_fn( &mut self, f: Arc<dyn Fn(usize, usize, &str, i64) + Send + Sync>, )
Set a progress callback for image pulls: (current, total, digest, size_bytes).
Called once per layer when run pulls an image that is not yet cached.
Sourcepub fn set_metrics(&mut self, metrics: RuntimeMetrics)
pub fn set_metrics(&mut self, metrics: RuntimeMetrics)
Attach Prometheus metrics to this VM manager.
Sourcepub fn set_log_config(&mut self, log_config: LogConfig)
pub fn set_log_config(&mut self, log_config: LogConfig)
Set the logging driver config. Threaded into the InstanceSpec so the shim runs the log processor for the box’s lifetime.
Sourcepub fn metrics_prom(&self) -> Option<&RuntimeMetrics>
pub fn metrics_prom(&self) -> Option<&RuntimeMetrics>
Get the attached Prometheus metrics (if any).
Sourcepub fn anonymous_volumes(&self) -> &[String]
pub fn anonymous_volumes(&self) -> &[String]
Get the names of anonymous volumes created during boot.
These are auto-created from OCI VOLUME directives and should be tracked for cleanup when the box is removed.
Sourcepub fn image_config(&self) -> Option<&OciImageConfig>
pub fn image_config(&self) -> Option<&OciImageConfig>
Get the OCI image config resolved during boot.
Sourcepub fn exit_code(&self) -> Option<i32>
pub fn exit_code(&self) -> Option<i32>
Get the exit code of the container, if it has exited.
Returns Some(code) after destroy() has been called and the shim
process exited naturally (not killed). Returns None if the VM has not
yet stopped or the exit code could not be determined.
Sourcepub async fn try_wait_exit(&mut self) -> Result<Option<i32>>
pub async fn try_wait_exit(&mut self) -> Result<Option<i32>>
Poll the owned VM process for natural exit without sending a signal.
This is used by foreground CLI flows where the container command may finish on its own and the CLI should clean up instead of waiting for a Ctrl-C.
Sourcepub async fn run_deferred_main(
&mut self,
spec_json: &[u8],
timeout: Duration,
) -> Result<ExecOutput>
pub async fn run_deferred_main( &mut self, spec_json: &[u8], timeout: Duration, ) -> Result<ExecOutput>
Run a command as the container MAIN in an IDLE-booted (deferred-main) VM.
Sends the spawn-main control frame carrying spec_json (the command),
waits for the main to exit (which halts the VM), and returns its real exit
code + the box’s json-file console logs split by stream. This is the full-
box-semantics counterpart to Self::exec_command (whose output is piped
over the exec stream, not the json-file logs).
Sourcepub async fn exec_request(&self, request: &ExecRequest) -> Result<ExecOutput>
pub async fn exec_request(&self, request: &ExecRequest) -> Result<ExecOutput>
Execute a command in the guest VM.
Requires the VM to be in Ready, Busy, or Compacting state.
Sourcepub async fn exec_command(
&self,
cmd: Vec<String>,
timeout_ns: u64,
) -> Result<ExecOutput>
pub async fn exec_command( &self, cmd: Vec<String>, timeout_ns: u64, ) -> Result<ExecOutput>
Execute a command in the guest VM.
Requires the VM to be in Ready, Busy, or Compacting state.
Sourcepub async fn destroy(&mut self) -> Result<()>
pub async fn destroy(&mut self) -> Result<()>
Destroy the VM with the default shutdown timeout and SIGTERM.
Sourcepub async fn destroy_with_timeout(&mut self, timeout_ms: u64) -> Result<()>
pub async fn destroy_with_timeout(&mut self, timeout_ms: u64) -> Result<()>
Destroy the VM with a custom shutdown timeout and SIGTERM.
Sourcepub async fn destroy_with_options(
&mut self,
signal: i32,
timeout_ms: u64,
) -> Result<()>
pub async fn destroy_with_options( &mut self, signal: i32, timeout_ms: u64, ) -> Result<()>
Destroy the VM with a specific stop signal and timeout.
Sends signal to the shim process and waits up to timeout_ms for it
to exit gracefully before sending SIGKILL.
Sourcepub async fn set_compacting(&self) -> Result<()>
pub async fn set_compacting(&self) -> Result<()>
Transition to compacting state.
Sourcepub async fn pause(&self) -> Result<()>
pub async fn pause(&self) -> Result<()>
Pause the VM by sending SIGSTOP to the shim process.
The VM must be in Ready, Busy, or Compacting state.
Sourcepub async fn resume(&self) -> Result<()>
pub async fn resume(&self) -> Result<()>
Resume the VM by sending SIGCONT to the shim process.
Can be called on a paused VM to resume execution.
Sourcepub async fn health_check(&self) -> Result<bool>
pub async fn health_check(&self) -> Result<bool>
Check if VM is healthy.
Sourcepub fn tee(&self) -> Option<&dyn TeeExtension>
pub fn tee(&self) -> Option<&dyn TeeExtension>
Get the TEE extension, if TEE is configured and VM is booted.
Sourcepub fn require_tee(&self) -> Result<&dyn TeeExtension>
pub fn require_tee(&self) -> Result<&dyn TeeExtension>
Get the TEE extension or return an error.
Sourcepub async fn update_resources(
&self,
update: &ResourceUpdate,
) -> Result<ResizeResult>
pub async fn update_resources( &self, update: &ResourceUpdate, ) -> Result<ResizeResult>
Apply a live resource update to the running VM.
Tier 1 changes (vCPU count, memory size) are rejected with a clear error because libkrun does not expose a hot-resize API.
Tier 2 changes (cgroup-based limits) are applied by executing shell commands inside the guest that write to cgroup v2 control files.
Auto Trait Implementations§
impl !RefUnwindSafe for VmManager
impl !UnwindSafe for VmManager
impl Freeze for VmManager
impl Send for VmManager
impl Sync for VmManager
impl Unpin for VmManager
impl UnsafeUnpin for VmManager
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more