pub(crate) mod archive;
pub(crate) mod box_impl;
mod clone_export;
pub(crate) mod config;
pub mod copy;
mod crash_report;
mod exec;
mod init;
pub(crate) mod local_snapshot;
mod manager;
mod snapshot;
pub(crate) mod snapshot_mgr;
mod state;
pub use copy::CopyOptions;
pub(crate) use crash_report::CrashReport;
pub use exec::{BoxCommand, ExecResult, ExecStderr, ExecStdin, ExecStdout, Execution, ExecutionId};
pub(crate) use manager::BoxManager;
pub use snapshot::SnapshotHandle;
pub use state::{BoxState, BoxStatus, HealthState, HealthStatus};
pub(crate) use box_impl::SharedBoxImpl;
pub(crate) use init::BoxBuilder;
pub(crate) use local_snapshot::LocalSnapshotBackend;
use std::path::Path;
use std::sync::Arc;
use crate::metrics::BoxMetrics;
use crate::runtime::backend::{BoxBackend, SnapshotBackend};
use crate::runtime::options::{BoxArchive, CloneOptions, ExportOptions};
use crate::{BoxID, BoxInfo};
use boxlite_shared::errors::BoxliteResult;
pub use config::BoxConfig;
pub struct LiteBox {
id: BoxID,
name: Option<String>,
box_backend: Arc<dyn BoxBackend>,
snapshot_backend: Arc<dyn SnapshotBackend>,
}
impl LiteBox {
pub(crate) fn new(
box_backend: Arc<dyn BoxBackend>,
snapshot_backend: Arc<dyn SnapshotBackend>,
) -> Self {
let id = box_backend.id().clone();
let name = box_backend.name().map(|s| s.to_string());
Self {
id,
name,
box_backend,
snapshot_backend,
}
}
pub fn id(&self) -> &BoxID {
&self.id
}
pub fn name(&self) -> Option<&str> {
self.name.as_deref()
}
pub fn info(&self) -> BoxInfo {
self.box_backend.info()
}
pub async fn start(&self) -> BoxliteResult<()> {
self.box_backend.start().await
}
pub async fn exec(&self, command: BoxCommand) -> BoxliteResult<Execution> {
self.box_backend.exec(command).await
}
pub async fn attach(&self, execution_id: &str) -> BoxliteResult<Execution> {
self.box_backend.attach(execution_id).await
}
pub async fn metrics(&self) -> BoxliteResult<BoxMetrics> {
self.box_backend.metrics().await
}
pub async fn stop(&self) -> BoxliteResult<()> {
self.box_backend.stop().await
}
pub async fn copy_into(
&self,
host_src: impl AsRef<Path>,
container_dst: impl AsRef<str>,
opts: copy::CopyOptions,
) -> BoxliteResult<()> {
self.box_backend
.copy_into(host_src.as_ref(), container_dst.as_ref(), opts)
.await
}
pub async fn copy_out(
&self,
container_src: impl AsRef<str>,
host_dst: impl AsRef<Path>,
opts: copy::CopyOptions,
) -> BoxliteResult<()> {
self.box_backend
.copy_out(container_src.as_ref(), host_dst.as_ref(), opts)
.await
}
pub fn snapshots(&self) -> SnapshotHandle {
SnapshotHandle::new(Arc::clone(&self.snapshot_backend))
}
pub async fn clone_box(
&self,
options: CloneOptions,
name: Option<String>,
) -> BoxliteResult<LiteBox> {
self.box_backend.clone_box(options, name).await
}
pub async fn clone_boxes(
&self,
options: CloneOptions,
count: usize,
names: Vec<String>,
) -> BoxliteResult<Vec<LiteBox>> {
self.box_backend.clone_boxes(options, count, names).await
}
pub async fn export(&self, options: ExportOptions, dest: &Path) -> BoxliteResult<BoxArchive> {
self.box_backend.export_box(options, dest).await
}
}
const _: () = {
const fn assert_send_sync<T: Send + Sync>() {}
let _ = assert_send_sync::<LiteBox>;
};