use super::Image;
use super::ImageStore;
use crate::containerization::vm::Kernel;
use crate::containerization::vm::SystemPlatform;
use crate::containerization_oci::content::LocalContentStore;
use crate::error::Error;
use crate::platform;
use crate::platform::ffi;
use std::collections::BTreeMap;
pub struct KernelImage {
handle: ffi::CzKernelImage,
}
unsafe impl Send for KernelImage {}
unsafe impl Sync for KernelImage {}
impl KernelImage {
pub const MEDIA_TYPE: &str = "application/vnd.apple.containerization.kernel";
pub fn new(image: &Image) -> Self {
Self {
handle: image.handle.kernel_image(),
}
}
pub fn name(&self) -> String {
self.handle.name()
}
pub fn kernel(&self, platform: SystemPlatform) -> Result<Kernel, Error> {
platform::outcome(
self.handle.kernel(platform),
format!("find the kernel in {}", self.name()),
)
.map(|outcome| outcome.kernel())
}
pub fn create(
reference: &str,
binaries: &[Kernel],
labels: &BTreeMap<String, String>,
image_store: &ImageStore,
content_store: &LocalContentStore,
) -> Result<Self, Error> {
platform::outcome(
image_store.handle.create_kernel_image(
reference,
binaries.to_vec(),
labels.keys().cloned().collect(),
labels.values().cloned().collect(),
content_store.handle.duplicate(),
),
format!("create kernel image {reference}"),
)
.map(|outcome| Self {
handle: outcome.kernel_image(),
})
}
}