mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-04 13:41:31 +00:00
hypha-agent: command line arguments
This commit is contained in:
@ -1,49 +1,34 @@
|
||||
use crate::error::{HyphaError, Result};
|
||||
use std::fs::{read_dir, DirEntry};
|
||||
use xenclient::create::DomainConfig;
|
||||
use xenclient::XenClient;
|
||||
use crate::error::Result;
|
||||
use xenclient::{DomainConfig, XenClient};
|
||||
|
||||
pub struct Agent {
|
||||
client: XenClient,
|
||||
kernel_path: String,
|
||||
initrd_path: String,
|
||||
vcpus: u32,
|
||||
mem: u64,
|
||||
}
|
||||
|
||||
impl Agent {
|
||||
pub fn new() -> Result<Agent> {
|
||||
pub fn new(kernel_path: String, initrd_path: String, vcpus: u32, mem: u64) -> Result<Agent> {
|
||||
let client = XenClient::open()?;
|
||||
Ok(Agent { client })
|
||||
Ok(Agent {
|
||||
client,
|
||||
kernel_path,
|
||||
initrd_path,
|
||||
vcpus,
|
||||
mem,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn launch(&mut self) -> Result<u32> {
|
||||
let kernel_path = self.find_boot_path("vmlinuz-")?;
|
||||
let initrd_path = self.find_boot_path("initrd.img-")?;
|
||||
|
||||
let config = DomainConfig {
|
||||
max_vcpus: 1,
|
||||
mem_mb: 512,
|
||||
kernel_path,
|
||||
initrd_path,
|
||||
cmdline: "debug elevator=noop".to_string(),
|
||||
max_vcpus: self.vcpus,
|
||||
mem_mb: self.mem,
|
||||
kernel_path: self.kernel_path.as_str(),
|
||||
initrd_path: self.initrd_path.as_str(),
|
||||
cmdline: "debug elevator=noop",
|
||||
};
|
||||
Ok(self.client.create(config)?)
|
||||
}
|
||||
|
||||
fn find_boot_path(&self, prefix: &str) -> Result<String> {
|
||||
let vmlinuz = read_dir("/boot")?
|
||||
.filter_map(|x| x.ok())
|
||||
.filter(|x| {
|
||||
x.file_name()
|
||||
.to_str()
|
||||
.ok_or(HyphaError::new("invalid direntry"))
|
||||
.map(|x| x.starts_with(prefix))
|
||||
.unwrap_or(false)
|
||||
})
|
||||
.collect::<Vec<DirEntry>>();
|
||||
Ok(vmlinuz
|
||||
.first()
|
||||
.ok_or(HyphaError::new("unable to find suitable image"))?
|
||||
.path()
|
||||
.to_str()
|
||||
.ok_or(HyphaError::new("invalid direntry"))?
|
||||
.to_string())
|
||||
Ok(self.client.create(&config)?)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user