mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-02 21:00:55 +00:00
move ownership of image compilation to controller
This commit is contained in:
parent
198ca3ff80
commit
9c438e8e57
@ -1,8 +1,6 @@
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use hypha::ctl::Controller;
|
use hypha::ctl::Controller;
|
||||||
use hypha::error::Result;
|
use hypha::error::Result;
|
||||||
use hypha::image::ImageCompiler;
|
|
||||||
use ocipkg::ImageName;
|
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(version, about)]
|
#[command(version, about)]
|
||||||
@ -27,12 +25,9 @@ fn main() -> Result<()> {
|
|||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
let args = ControllerArgs::parse();
|
let args = ControllerArgs::parse();
|
||||||
let mut controller = Controller::new(args.kernel, args.initrd, args.cpus, args.mem)?;
|
let mut controller =
|
||||||
let image = ImageName::parse(args.image.as_str())?;
|
Controller::new(args.kernel, args.initrd, args.image, args.cpus, args.mem)?;
|
||||||
let compiler = ImageCompiler::new()?;
|
controller.compile()?;
|
||||||
let squashfs = compiler.compile(&image)?;
|
|
||||||
println!("packed image into squashfs: {}", &squashfs);
|
|
||||||
|
|
||||||
let domid = controller.launch()?;
|
let domid = controller.launch()?;
|
||||||
println!("launched domain: {}", domid);
|
println!("launched domain: {}", domid);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
use crate::error::Result;
|
use crate::error::Result;
|
||||||
|
use crate::image::ImageCompiler;
|
||||||
|
use ocipkg::ImageName;
|
||||||
use xenclient::{DomainConfig, XenClient};
|
use xenclient::{DomainConfig, XenClient};
|
||||||
|
|
||||||
pub struct Controller {
|
pub struct Controller {
|
||||||
@ -7,12 +9,14 @@ pub struct Controller {
|
|||||||
initrd_path: String,
|
initrd_path: String,
|
||||||
vcpus: u32,
|
vcpus: u32,
|
||||||
mem: u64,
|
mem: u64,
|
||||||
|
image: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Controller {
|
impl Controller {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
kernel_path: String,
|
kernel_path: String,
|
||||||
initrd_path: String,
|
initrd_path: String,
|
||||||
|
image: String,
|
||||||
vcpus: u32,
|
vcpus: u32,
|
||||||
mem: u64,
|
mem: u64,
|
||||||
) -> Result<Controller> {
|
) -> Result<Controller> {
|
||||||
@ -21,11 +25,19 @@ impl Controller {
|
|||||||
client,
|
client,
|
||||||
kernel_path,
|
kernel_path,
|
||||||
initrd_path,
|
initrd_path,
|
||||||
|
image,
|
||||||
vcpus,
|
vcpus,
|
||||||
mem,
|
mem,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn compile(&mut self) -> Result<()> {
|
||||||
|
let image = ImageName::parse(&self.image)?;
|
||||||
|
let compiler = ImageCompiler::new()?;
|
||||||
|
let _squashfs = compiler.compile(&image)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn launch(&mut self) -> Result<u32> {
|
pub fn launch(&mut self) -> Result<u32> {
|
||||||
let config = DomainConfig {
|
let config = DomainConfig {
|
||||||
max_vcpus: self.vcpus,
|
max_vcpus: self.vcpus,
|
||||||
|
Loading…
Reference in New Issue
Block a user