2024-01-17 12:36:13 -08:00
|
|
|
use crate::error::Result;
|
|
|
|
use xenclient::{DomainConfig, XenClient};
|
2024-01-17 08:18:12 -08:00
|
|
|
|
2024-01-17 14:29:05 -08:00
|
|
|
pub struct Controller {
|
2024-01-17 08:18:12 -08:00
|
|
|
client: XenClient,
|
2024-01-17 12:36:13 -08:00
|
|
|
kernel_path: String,
|
|
|
|
initrd_path: String,
|
|
|
|
vcpus: u32,
|
|
|
|
mem: u64,
|
2024-01-17 08:18:12 -08:00
|
|
|
}
|
|
|
|
|
2024-01-17 14:29:05 -08:00
|
|
|
impl Controller {
|
|
|
|
pub fn new(
|
|
|
|
kernel_path: String,
|
|
|
|
initrd_path: String,
|
|
|
|
vcpus: u32,
|
|
|
|
mem: u64,
|
|
|
|
) -> Result<Controller> {
|
2024-01-17 08:18:12 -08:00
|
|
|
let client = XenClient::open()?;
|
2024-01-17 14:29:05 -08:00
|
|
|
Ok(Controller {
|
2024-01-17 12:36:13 -08:00
|
|
|
client,
|
|
|
|
kernel_path,
|
|
|
|
initrd_path,
|
|
|
|
vcpus,
|
|
|
|
mem,
|
|
|
|
})
|
2024-01-17 08:18:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn launch(&mut self) -> Result<u32> {
|
|
|
|
let config = DomainConfig {
|
2024-01-17 12:36:13 -08:00
|
|
|
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",
|
2024-01-17 08:18:12 -08:00
|
|
|
};
|
2024-01-17 12:36:13 -08:00
|
|
|
Ok(self.client.create(&config)?)
|
2024-01-17 08:18:12 -08:00
|
|
|
}
|
|
|
|
}
|