From e000ab29197733571266338fa269d54c34bd5bdb Mon Sep 17 00:00:00 2001 From: Alex Zenla Date: Tue, 6 Feb 2024 09:07:18 +0000 Subject: [PATCH] hypha: move components into separate crates --- Cargo.toml | 10 ++++-- container/Cargo.toml | 33 +++++++++++++++++++ .../bin/container.rs => container/bin/init.rs | 2 +- .../src/container => container/src}/init.rs | 2 +- .../container/mod.rs => container/src/lib.rs | 0 {hypha => controller}/Cargo.toml | 21 +++--------- .../bin/control.rs | 2 +- {hypha => controller}/src/autoloop.rs | 0 {hypha => controller}/src/ctl/cfgblk.rs | 0 {hypha => controller}/src/ctl/mod.rs | 0 {hypha => controller}/src/image/cache.rs | 0 {hypha => controller}/src/image/fetch.rs | 0 {hypha => controller}/src/image/mod.rs | 0 {hypha => controller}/src/image/name.rs | 0 {hypha => controller}/src/lib.rs | 2 -- {hypha => controller}/src/shared/mod.rs | 0 libs/xen/xenclient/Cargo.toml | 3 -- network/Cargo.toml | 26 +++++++++++++++ {hypha => network}/bin/network.rs | 2 +- .../src/network/mod.rs => network/src/lib.rs | 0 shared/Cargo.toml | 11 +++++++ shared/src/lib.rs | 14 ++++++++ 22 files changed, 101 insertions(+), 27 deletions(-) create mode 100644 container/Cargo.toml rename hypha/bin/container.rs => container/bin/init.rs (94%) rename {hypha/src/container => container/src}/init.rs (99%) rename hypha/src/container/mod.rs => container/src/lib.rs (100%) rename {hypha => controller}/Cargo.toml (75%) rename hypha/bin/controller.rs => controller/bin/control.rs (99%) rename {hypha => controller}/src/autoloop.rs (100%) rename {hypha => controller}/src/ctl/cfgblk.rs (100%) rename {hypha => controller}/src/ctl/mod.rs (100%) rename {hypha => controller}/src/image/cache.rs (100%) rename {hypha => controller}/src/image/fetch.rs (100%) rename {hypha => controller}/src/image/mod.rs (100%) rename {hypha => controller}/src/image/name.rs (100%) rename {hypha => controller}/src/lib.rs (63%) rename {hypha => controller}/src/shared/mod.rs (100%) create mode 100644 network/Cargo.toml rename {hypha => network}/bin/network.rs (92%) rename hypha/src/network/mod.rs => network/src/lib.rs (100%) create mode 100644 shared/Cargo.toml create mode 100644 shared/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 9b83a3e..6b8941f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,10 @@ members = [ "libs/xen/xenclient", "libs/advmac", "libs/loopdev", - "hypha", + "shared", + "container", + "network", + "controller", ] resolver = "2" @@ -30,7 +33,6 @@ errno = "0.3.0" oci-spec = "0.6.4" backhand = "0.14.2" sha256 = "1.5.0" -serde = "1.0.196" serde_json = "1.0.113" walkdir = "2" directories = "5.0.1" @@ -64,3 +66,7 @@ features = ["derive"] [workspace.dependencies.tokio] version = "1.35.1" features = ["macros", "rt", "rt-multi-thread"] + +[workspace.dependencies.serde] +version = "1.0.196" +features = ["derive"] diff --git a/container/Cargo.toml b/container/Cargo.toml new file mode 100644 index 0000000..5af80c0 --- /dev/null +++ b/container/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "hyphactr" +version.workspace = true +edition = "2021" +resolver = "2" + +[dependencies] +anyhow = { workspace = true } +log = { workspace = true } +env_logger = { workspace = true } +walkdir = { workspace = true } +serde = { workspace = true } +serde_json = { workspace = true } +sys-mount = { workspace = true } +oci-spec = { workspace = true } +rtnetlink = { workspace = true } +tokio = { workspace = true } +futures = { workspace = true } +ipnetwork = { workspace = true } + +[dependencies.nix] +workspace = true +features = ["process"] + +[dependencies.hypha] +path = "../shared" + +[lib] +path = "src/lib.rs" + +[[bin]] +name = "hyphactr" +path = "bin/init.rs" diff --git a/hypha/bin/container.rs b/container/bin/init.rs similarity index 94% rename from hypha/bin/container.rs rename to container/bin/init.rs index a56de53..e8b9a15 100644 --- a/hypha/bin/container.rs +++ b/container/bin/init.rs @@ -1,6 +1,6 @@ use anyhow::{anyhow, Result}; use env_logger::Env; -use hypha::container::init::ContainerInit; +use hyphactr::init::ContainerInit; use std::env; #[tokio::main] diff --git a/hypha/src/container/init.rs b/container/src/init.rs similarity index 99% rename from hypha/src/container/init.rs rename to container/src/init.rs index 0568533..882006f 100644 --- a/hypha/src/container/init.rs +++ b/container/src/init.rs @@ -1,6 +1,6 @@ -use crate::shared::{LaunchInfo, LaunchNetwork}; use anyhow::{anyhow, Result}; use futures::stream::TryStreamExt; +use hypha::{LaunchInfo, LaunchNetwork}; use ipnetwork::IpNetwork; use log::{trace, warn}; use nix::libc::{c_int, dup2, wait}; diff --git a/hypha/src/container/mod.rs b/container/src/lib.rs similarity index 100% rename from hypha/src/container/mod.rs rename to container/src/lib.rs diff --git a/hypha/Cargo.toml b/controller/Cargo.toml similarity index 75% rename from hypha/Cargo.toml rename to controller/Cargo.toml index 4f822ea..6a30830 100644 --- a/hypha/Cargo.toml +++ b/controller/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "hypha" +name = "hyphactrl" version.workspace = true edition = "2021" resolver = "2" @@ -22,16 +22,13 @@ path-clean = { workspace = true } termion = { workspace = true } cli-tables = { workspace = true } clap = { workspace = true } -sys-mount = { workspace = true } oci-spec = { workspace = true } backhand = { workspace = true } uuid = { workspace = true } -rtnetlink = { workspace = true } -netlink-packet-route = { workspace = true } -tokio = { workspace = true } -futures = { workspace = true } ipnetwork = { workspace = true } -smoltcp = { workspace = true } + +[dependencies.hypha] +path = "../shared" [dependencies.nix] workspace = true @@ -54,12 +51,4 @@ path = "src/lib.rs" [[bin]] name = "hyphactl" -path = "bin/controller.rs" - -[[bin]] -name = "hyphactr" -path = "bin/container.rs" - -[[bin]] -name = "hyphanet" -path = "bin/network.rs" +path = "bin/control.rs" diff --git a/hypha/bin/controller.rs b/controller/bin/control.rs similarity index 99% rename from hypha/bin/controller.rs rename to controller/bin/control.rs index 51b04a9..1716ce9 100644 --- a/hypha/bin/controller.rs +++ b/controller/bin/control.rs @@ -1,7 +1,7 @@ use anyhow::{anyhow, Result}; use clap::{Parser, Subcommand}; use env_logger::Env; -use hypha::ctl::Controller; +use hyphactrl::ctl::Controller; use std::path::PathBuf; #[derive(Parser, Debug)] diff --git a/hypha/src/autoloop.rs b/controller/src/autoloop.rs similarity index 100% rename from hypha/src/autoloop.rs rename to controller/src/autoloop.rs diff --git a/hypha/src/ctl/cfgblk.rs b/controller/src/ctl/cfgblk.rs similarity index 100% rename from hypha/src/ctl/cfgblk.rs rename to controller/src/ctl/cfgblk.rs diff --git a/hypha/src/ctl/mod.rs b/controller/src/ctl/mod.rs similarity index 100% rename from hypha/src/ctl/mod.rs rename to controller/src/ctl/mod.rs diff --git a/hypha/src/image/cache.rs b/controller/src/image/cache.rs similarity index 100% rename from hypha/src/image/cache.rs rename to controller/src/image/cache.rs diff --git a/hypha/src/image/fetch.rs b/controller/src/image/fetch.rs similarity index 100% rename from hypha/src/image/fetch.rs rename to controller/src/image/fetch.rs diff --git a/hypha/src/image/mod.rs b/controller/src/image/mod.rs similarity index 100% rename from hypha/src/image/mod.rs rename to controller/src/image/mod.rs diff --git a/hypha/src/image/name.rs b/controller/src/image/name.rs similarity index 100% rename from hypha/src/image/name.rs rename to controller/src/image/name.rs diff --git a/hypha/src/lib.rs b/controller/src/lib.rs similarity index 63% rename from hypha/src/lib.rs rename to controller/src/lib.rs index a2878fb..9575c3e 100644 --- a/hypha/src/lib.rs +++ b/controller/src/lib.rs @@ -1,6 +1,4 @@ pub mod autoloop; -pub mod container; pub mod ctl; pub mod image; -pub mod network; pub mod shared; diff --git a/hypha/src/shared/mod.rs b/controller/src/shared/mod.rs similarity index 100% rename from hypha/src/shared/mod.rs rename to controller/src/shared/mod.rs diff --git a/libs/xen/xenclient/Cargo.toml b/libs/xen/xenclient/Cargo.toml index dc1c493..d1454c9 100644 --- a/libs/xen/xenclient/Cargo.toml +++ b/libs/xen/xenclient/Cargo.toml @@ -21,9 +21,6 @@ path = "../xencall" [dependencies.xenstore] path = "../xenstore" -[dependencies.xenevtchn] -path = "../xenevtchn" - [dev-dependencies] env_logger = { workspace = true } diff --git a/network/Cargo.toml b/network/Cargo.toml new file mode 100644 index 0000000..c63e6f4 --- /dev/null +++ b/network/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "hyphanet" +version.workspace = true +edition = "2021" +resolver = "2" + +[dependencies] +anyhow = { workspace = true } +clap = { workspace = true } +log = { workspace = true } +env_logger = { workspace = true } +rtnetlink = { workspace = true } +netlink-packet-route = { workspace = true } +tokio = { workspace = true } +futures = { workspace = true } +smoltcp = { workspace = true } + +[dependencies.advmac] +path = "../libs/advmac" + +[lib] +path = "src/lib.rs" + +[[bin]] +name = "hyphanet" +path = "bin/network.rs" diff --git a/hypha/bin/network.rs b/network/bin/network.rs similarity index 92% rename from hypha/bin/network.rs rename to network/bin/network.rs index d263746..c44ae6f 100644 --- a/hypha/bin/network.rs +++ b/network/bin/network.rs @@ -1,7 +1,7 @@ use anyhow::Result; use clap::Parser; use env_logger::Env; -use hypha::network::NetworkService; +use hyphanet::NetworkService; #[derive(Parser, Debug)] struct NetworkArgs { diff --git a/hypha/src/network/mod.rs b/network/src/lib.rs similarity index 100% rename from hypha/src/network/mod.rs rename to network/src/lib.rs diff --git a/shared/Cargo.toml b/shared/Cargo.toml new file mode 100644 index 0000000..b69e95a --- /dev/null +++ b/shared/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "hypha" +version.workspace = true +edition = "2021" +resolver = "2" + +[dependencies] +serde = { workspace = true } + +[lib] +path = "src/lib.rs" diff --git a/shared/src/lib.rs b/shared/src/lib.rs new file mode 100644 index 0000000..1281840 --- /dev/null +++ b/shared/src/lib.rs @@ -0,0 +1,14 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Debug)] +pub struct LaunchNetwork { + pub link: String, + pub ipv4: String, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct LaunchInfo { + pub network: Option, + pub env: Option>, + pub run: Option>, +}