mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-02 12:50:54 +00:00
create hypha
This commit is contained in:
parent
135182d847
commit
8689398032
@ -3,6 +3,7 @@ members = [
|
|||||||
"xenstore",
|
"xenstore",
|
||||||
"xenevtchn",
|
"xenevtchn",
|
||||||
"xencall",
|
"xencall",
|
||||||
"xenclient"
|
"xenclient",
|
||||||
|
"hypha",
|
||||||
]
|
]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
22
hypha/Cargo.toml
Normal file
22
hypha/Cargo.toml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
[package]
|
||||||
|
name = "hypha"
|
||||||
|
version = "0.0.1"
|
||||||
|
edition = "2021"
|
||||||
|
resolver = "2"
|
||||||
|
|
||||||
|
[dependencies.xenclient]
|
||||||
|
path = "../xenclient"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
log = "0.4.20"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
path = "src/lib.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "hypha-agent"
|
||||||
|
path = "bin/agent.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "hypha-container"
|
||||||
|
path = "bin/container.rs"
|
9
hypha/bin/agent.rs
Normal file
9
hypha/bin/agent.rs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
use hypha::agent::Agent;
|
||||||
|
use hypha::error::Result;
|
||||||
|
|
||||||
|
fn main() -> Result<()> {
|
||||||
|
let mut agent = Agent::new()?;
|
||||||
|
let domid = agent.launch()?;
|
||||||
|
println!("launched domain: {}", domid);
|
||||||
|
Ok(())
|
||||||
|
}
|
5
hypha/bin/container.rs
Normal file
5
hypha/bin/container.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
use hypha::error::Result;
|
||||||
|
|
||||||
|
fn main() -> Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
50
hypha/src/agent/mod.rs
Normal file
50
hypha/src/agent/mod.rs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
use crate::error::{HyphaError, Result};
|
||||||
|
use std::fs::{read_dir, DirEntry};
|
||||||
|
use xenclient::create::DomainConfig;
|
||||||
|
use xenclient::XenClient;
|
||||||
|
|
||||||
|
pub struct Agent {
|
||||||
|
client: XenClient,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Agent {
|
||||||
|
pub fn new() -> Result<Agent> {
|
||||||
|
let client = XenClient::open()?;
|
||||||
|
Ok(Agent { client })
|
||||||
|
}
|
||||||
|
|
||||||
|
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(),
|
||||||
|
};
|
||||||
|
Ok(self.client.create(config)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn find_boot_path(&self, prefix: &str) -> Result<String> {
|
||||||
|
let vmlinuz = read_dir("/boot")?
|
||||||
|
.filter(|x| x.is_ok())
|
||||||
|
.map(|x| x.unwrap())
|
||||||
|
.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())
|
||||||
|
}
|
||||||
|
}
|
1
hypha/src/container/mod.rs
Normal file
1
hypha/src/container/mod.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
42
hypha/src/error.rs
Normal file
42
hypha/src/error.rs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
use std::error::Error;
|
||||||
|
use std::fmt::{Display, Formatter};
|
||||||
|
use xenclient::XenClientError;
|
||||||
|
|
||||||
|
pub type Result<T> = std::result::Result<T, HyphaError>;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct HyphaError {
|
||||||
|
message: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HyphaError {
|
||||||
|
pub fn new(msg: &str) -> HyphaError {
|
||||||
|
HyphaError {
|
||||||
|
message: msg.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for HyphaError {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "{}", self.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Error for HyphaError {
|
||||||
|
fn description(&self) -> &str {
|
||||||
|
&self.message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<std::io::Error> for HyphaError {
|
||||||
|
fn from(value: std::io::Error) -> Self {
|
||||||
|
HyphaError::new(value.to_string().as_str())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<XenClientError> for HyphaError {
|
||||||
|
fn from(value: XenClientError) -> Self {
|
||||||
|
HyphaError::new(value.to_string().as_str())
|
||||||
|
}
|
||||||
|
}
|
3
hypha/src/lib.rs
Normal file
3
hypha/src/lib.rs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
pub mod agent;
|
||||||
|
pub mod container;
|
||||||
|
pub mod error;
|
Loading…
Reference in New Issue
Block a user