mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-04 05:31:32 +00:00
hypha: implement image cache
This commit is contained in:
@ -1,44 +1,56 @@
|
||||
use crate::error::Result;
|
||||
use crate::image::ImageCompiler;
|
||||
use crate::image::cache::ImageCache;
|
||||
use crate::image::{ImageCompiler, ImageInfo};
|
||||
use ocipkg::ImageName;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use xenclient::{DomainConfig, XenClient};
|
||||
|
||||
pub struct Controller {
|
||||
image_cache: ImageCache,
|
||||
image: String,
|
||||
client: XenClient,
|
||||
kernel_path: String,
|
||||
initrd_path: String,
|
||||
vcpus: u32,
|
||||
mem: u64,
|
||||
image: String,
|
||||
}
|
||||
|
||||
impl Controller {
|
||||
pub fn new(
|
||||
cache_path: String,
|
||||
kernel_path: String,
|
||||
initrd_path: String,
|
||||
image: String,
|
||||
vcpus: u32,
|
||||
mem: u64,
|
||||
) -> Result<Controller> {
|
||||
fs::create_dir_all(&cache_path)?;
|
||||
|
||||
let client = XenClient::open()?;
|
||||
let mut image_cache_path = PathBuf::from(cache_path);
|
||||
image_cache_path.push("image");
|
||||
fs::create_dir_all(&image_cache_path)?;
|
||||
let image_cache = ImageCache::new(&image_cache_path)?;
|
||||
Ok(Controller {
|
||||
image_cache,
|
||||
image,
|
||||
client,
|
||||
kernel_path,
|
||||
initrd_path,
|
||||
image,
|
||||
vcpus,
|
||||
mem,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn compile(&mut self) -> Result<()> {
|
||||
fn compile(&mut self) -> Result<ImageInfo> {
|
||||
let image = ImageName::parse(&self.image)?;
|
||||
let compiler = ImageCompiler::new()?;
|
||||
let _squashfs = compiler.compile(&image)?;
|
||||
Ok(())
|
||||
let compiler = ImageCompiler::new(&self.image_cache)?;
|
||||
compiler.compile(&image)
|
||||
}
|
||||
|
||||
pub fn launch(&mut self) -> Result<u32> {
|
||||
let _image_info = self.compile()?;
|
||||
let config = DomainConfig {
|
||||
max_vcpus: self.vcpus,
|
||||
mem_mb: self.mem,
|
||||
|
Reference in New Issue
Block a user