mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-03 13:11:31 +00:00
hypha-agent: command line arguments
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
use std::{env, process};
|
||||
use xenclient::create::DomainConfig;
|
||||
use xenclient::{XenClient, XenClientError};
|
||||
use xenclient::{DomainConfig, XenClient, XenClientError};
|
||||
|
||||
fn main() -> Result<(), XenClientError> {
|
||||
env_logger::init();
|
||||
@ -16,11 +15,11 @@ fn main() -> Result<(), XenClientError> {
|
||||
let config = DomainConfig {
|
||||
max_vcpus: 1,
|
||||
mem_mb: 512,
|
||||
kernel_path: kernel_image_path.to_string(),
|
||||
initrd_path: initrd_path.to_string(),
|
||||
cmdline: "debug elevator=noop".to_string(),
|
||||
kernel_path: kernel_image_path.as_str(),
|
||||
initrd_path: initrd_path.as_str(),
|
||||
cmdline: "debug elevator=noop",
|
||||
};
|
||||
let domid = client.create(config)?;
|
||||
let domid = client.create(&config)?;
|
||||
println!("created domain {}", domid);
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1,92 +0,0 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub struct DomainConfig {
|
||||
pub max_vcpus: u32,
|
||||
pub mem_mb: u64,
|
||||
pub kernel_path: String,
|
||||
pub initrd_path: String,
|
||||
pub cmdline: String,
|
||||
}
|
||||
|
||||
pub struct PvDomainStore {
|
||||
kernel: String,
|
||||
ramdisk: Option<String>,
|
||||
cmdline: Option<String>,
|
||||
}
|
||||
|
||||
pub struct DomainStore {
|
||||
vm_entries: HashMap<String, String>,
|
||||
domain_entries: HashMap<String, String>,
|
||||
}
|
||||
|
||||
impl DomainStore {
|
||||
pub fn new() -> DomainStore {
|
||||
DomainStore {
|
||||
vm_entries: HashMap::new(),
|
||||
domain_entries: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn put_vm(&mut self, key: &str, value: String) {
|
||||
self.vm_entries.insert(key.to_string(), value);
|
||||
}
|
||||
|
||||
pub fn put_vm_str(&mut self, key: &str, value: &str) {
|
||||
self.put_vm(key, value.to_string());
|
||||
}
|
||||
|
||||
pub fn put_domain(&mut self, key: &str, value: String) {
|
||||
self.vm_entries.insert(key.to_string(), value);
|
||||
}
|
||||
|
||||
pub fn put_domain_str(&mut self, key: &str, value: &str) {
|
||||
self.put_domain(key, value.to_string());
|
||||
}
|
||||
|
||||
pub fn configure_memory(&mut self, maxkb: u32, targetkb: u32, videokb: u32) {
|
||||
self.put_domain("memory/static-max", maxkb.to_string());
|
||||
self.put_domain("memory/target", targetkb.to_string());
|
||||
self.put_domain("memory/videoram", videokb.to_string());
|
||||
}
|
||||
|
||||
pub fn configure_cpus(&mut self, _maxvcpus: u32) {}
|
||||
|
||||
pub fn configure_pv(&mut self, pv: PvDomainStore) {
|
||||
self.put_vm_str("image/ostype", "linux");
|
||||
self.put_vm("image/kernel", pv.kernel);
|
||||
|
||||
match pv.ramdisk {
|
||||
None => {}
|
||||
Some(ramdisk) => self.put_vm("image/ramdisk", ramdisk),
|
||||
}
|
||||
|
||||
match pv.cmdline {
|
||||
None => {}
|
||||
Some(cmdline) => self.put_vm("image/cmdline", cmdline),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clone_vm_entries(&self) -> HashMap<String, String> {
|
||||
self.vm_entries.clone()
|
||||
}
|
||||
|
||||
pub fn clone_domain_entries(&self) -> HashMap<String, String> {
|
||||
self.domain_entries.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for DomainStore {
|
||||
fn default() -> Self {
|
||||
DomainStore::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl PvDomainStore {
|
||||
pub fn new(kernel: String, ramdisk: Option<String>, cmdline: Option<String>) -> PvDomainStore {
|
||||
PvDomainStore {
|
||||
kernel,
|
||||
ramdisk,
|
||||
cmdline,
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +1,10 @@
|
||||
pub mod boot;
|
||||
pub mod create;
|
||||
pub mod elfloader;
|
||||
pub mod mem;
|
||||
pub mod sys;
|
||||
mod x86;
|
||||
|
||||
use crate::boot::BootSetup;
|
||||
use crate::create::DomainConfig;
|
||||
use crate::elfloader::ElfImageLoader;
|
||||
use crate::x86::X86BootSetup;
|
||||
use std::error::Error;
|
||||
@ -80,6 +78,14 @@ impl From<EventChannelError> for XenClientError {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DomainConfig<'a> {
|
||||
pub max_vcpus: u32,
|
||||
pub mem_mb: u64,
|
||||
pub kernel_path: &'a str,
|
||||
pub initrd_path: &'a str,
|
||||
pub cmdline: &'a str,
|
||||
}
|
||||
|
||||
impl XenClient {
|
||||
pub fn open() -> Result<XenClient, XenClientError> {
|
||||
let store = XsdClient::open()?;
|
||||
@ -87,7 +93,7 @@ impl XenClient {
|
||||
Ok(XenClient { store, call })
|
||||
}
|
||||
|
||||
pub fn create(&mut self, config: DomainConfig) -> Result<u32, XenClientError> {
|
||||
pub fn create(&mut self, config: &DomainConfig) -> Result<u32, XenClientError> {
|
||||
let domain = CreateDomain {
|
||||
max_vcpus: config.max_vcpus,
|
||||
..Default::default()
|
||||
@ -99,9 +105,7 @@ impl XenClient {
|
||||
let libxl_path = format!("/libxl/{}", domid);
|
||||
|
||||
let ro_perm = XsPermissions { id: 0, perms: 0 };
|
||||
|
||||
let rw_perm = XsPermissions { id: 0, perms: 0 };
|
||||
|
||||
let no_perm = XsPermissions { id: 0, perms: 0 };
|
||||
|
||||
{
|
||||
@ -156,7 +160,7 @@ impl XenClient {
|
||||
|
||||
self.call.set_max_vcpus(domid, config.max_vcpus)?;
|
||||
self.call.set_max_mem(domid, config.mem_mb * 1024)?;
|
||||
let image_loader = ElfImageLoader::load_file_kernel(config.kernel_path.as_str())?;
|
||||
let image_loader = ElfImageLoader::load_file_kernel(config.kernel_path)?;
|
||||
|
||||
let console_evtchn: u32;
|
||||
let xenstore_evtchn: u32;
|
||||
@ -166,7 +170,7 @@ impl XenClient {
|
||||
{
|
||||
let mut boot = BootSetup::new(&self.call, domid);
|
||||
let mut arch = X86BootSetup::new();
|
||||
let initrd = read(config.initrd_path.as_str())?;
|
||||
let initrd = read(config.initrd_path)?;
|
||||
let mut state = boot.initialize(
|
||||
&mut arch,
|
||||
&image_loader,
|
||||
@ -174,7 +178,7 @@ impl XenClient {
|
||||
config.max_vcpus,
|
||||
config.mem_mb,
|
||||
)?;
|
||||
boot.boot(&mut arch, &mut state, config.cmdline.as_str())?;
|
||||
boot.boot(&mut arch, &mut state, config.cmdline)?;
|
||||
console_evtchn = state.console_evtchn;
|
||||
xenstore_evtchn = state.store_evtchn;
|
||||
console_mfn = boot.phys.p2m[state.console_segment.pfn as usize];
|
||||
@ -186,15 +190,15 @@ impl XenClient {
|
||||
tx.write_string(format!("{}/image/os_type", vm_path).as_str(), "linux")?;
|
||||
tx.write_string(
|
||||
format!("{}/image/kernel", vm_path).as_str(),
|
||||
&config.kernel_path,
|
||||
config.kernel_path,
|
||||
)?;
|
||||
tx.write_string(
|
||||
format!("{}/image/ramdisk", vm_path).as_str(),
|
||||
&config.initrd_path,
|
||||
config.initrd_path,
|
||||
)?;
|
||||
tx.write_string(
|
||||
format!("{}/image/cmdline", vm_path).as_str(),
|
||||
&config.cmdline,
|
||||
config.cmdline,
|
||||
)?;
|
||||
|
||||
tx.write_string(
|
||||
|
Reference in New Issue
Block a user