Skip to content

Commit

Permalink
Merge branch 'main' into observe_todo
Browse files Browse the repository at this point in the history
  • Loading branch information
dmah42 authored Aug 21, 2024
2 parents 12a5b4e + fcb6ad6 commit 74ad161
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 91 deletions.
26 changes: 13 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -204,35 +204,35 @@ $(1)-lint: $(GEN_RS) $(GEN_TS)

.PHONY: $(1)-test
$(1)-test: $(GEN_RS) $(GEN_TS) auraed
$(cargo) test --locked -p $(1)
$(cargo) test -p $(1) --locked

.PHONY: $(1)-test-all
$(1)-test-all: $(GEN_RS) $(GEN_TS) auraed
$(root_cargo) test --locked -p $(1) -- --include-ignored
$(root_cargo) test -p $(1) --locked -- --include-ignored

.PHONY: $(1)-test-integration
$(1)-test-integration: $(GEN_RS) $(GEN_TS) auraed
$(root_cargo) test --locked -p $(1) --test '*' -- --include-ignored
$(root_cargo) test -p $(1) --locked --test '*' -- --include-ignored

.PHONY: $(1)-test-watch
$(1)-test-watch: $(GEN_RS) $(GEN_TS) auraed # Use cargo-watch to continuously run a test (e.g. make $(1)-test-watch name=path::to::test)
$(root_cargo) watch -- $(cargo) test --locked -p $(1) $(name) -- --include-ignored --nocapture
$(root_cargo) watch -- $(cargo) test -p $(1) --locked $(name) -- --include-ignored --nocapture

.PHONY: $(1)-build
$(1)-build: $(GEN_RS) $(GEN_TS)
$(cargo) build --locked -p $(1)
$(cargo) build -p $(1) --locked

.PHONY: $(1)-build-release
$(1)-build-release: $(GEN_RS) $(GEN_TS)
$(cargo) build --locked -p $(1) --release
$(cargo) build -p $(1) --locked --release

.PHONY: $(1)-debug
$(1)-debug: $(GEN_RS) $(GEN_TS) $(1)-lint
$(cargo) install --locked --path ./$(1) --debug --force
$(cargo) install --path ./$(1) --debug --force --locked

.PHONY: $(1)-release
$(1)-release: $(GEN_RS) $(GEN_TS) $(1)-lint $(1)-test ## Lint, test, and install $(1)
$(cargo) install --locked --path ./$(1) --force
$(cargo) install --path ./$(1) --force --locked
endef

$(foreach p,$(PROGS),$(eval $(call AURAE_template,$(p),$(if $(findstring auraed,$(p)),))))
Expand All @@ -257,19 +257,19 @@ endif

.PHONY: not-auraed-build
not-auraed-build: $(GEN_RS) $(GEN_TS)
$(cargo) build --locked --workspace --exclude auraed
$(cargo) build --workspace --locked --exclude auraed

.PHONY: not-auraed-lint
not-auraed-lint: $(GEN_RS) $(GEN_TS)
$(cargo) clippy --all-features --workspace --exclude auraed -- -D clippy::all -D warnings

.PHONY: not-auraed-test
not-auraed-test: $(GEN_RS) $(GEN_TS)
$(cargo) test --locked --workspace --exclude auraed
$(cargo) test --workspace --locked --exclude auraed

.PHONY: not-auraed-test-all
not-auraed-test-all: $(GEN_RS) $(GEN_TS)
$(cargo) test --locked --workspace --exclude auraed -- --include-ignored
$(cargo) test --workspace --locked --exclude auraed -- --include-ignored

#------------------------------------------------------------------------------#

Expand All @@ -281,11 +281,11 @@ libs-lint: $(GEN_RS) $(GEN_TS)

.PHONY: libs-test
libs-test: $(GEN_RS) $(GEN_TS)
$(cargo) test --locked --workspace --exclude auraed --exclude auraescript --exclude aer
$(cargo) test --workspace --locked --exclude auraed --exclude auraescript --exclude aer

.PHONY: libs-test-all
libs-test-all: $(GEN_RS) $(GEN_TS)
$(cargo) test --locked --workspace --exclude auraed --exclude auraescript --exclude aer -- --include-ignored
$(cargo) test --workspace --locked --exclude auraed --exclude auraescript --exclude aer -- --include-ignored

.PHONY: ebpf
ebpf:
Expand Down
6 changes: 3 additions & 3 deletions api/v0/vms/vms.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ option go_package = "github.com/aurae-runtime/ae/client/pkg/api/v0/vms;vmsv0";

service VmService {
// Reserve requested system resources for a new VM.
rpc Create(VmServiceCreateRequest) returns (VmServiceCreateResponse) {}
rpc Allocate(VmServiceAllocateRequest) returns (VmServiceAllocateResponse) {}

// Free up previously requested resources for an existing VM
rpc Free(VmServiceFreeRequest) returns (VmServiceFreeResponse) {}
Expand Down Expand Up @@ -79,10 +79,10 @@ message VirtualMachineSummary {
string auraed_address = 7;
}

message VmServiceCreateRequest{
message VmServiceAllocateRequest{
VirtualMachine machine = 1;
}
message VmServiceCreateResponse{
message VmServiceAllocateResponse{
string vm_id = 1;
}

Expand Down
50 changes: 27 additions & 23 deletions auraed/src/init/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ pub(crate) enum NetworkError {
Other(#[from] rtnetlink::Error),
}

pub(crate) struct Config {
pub device: String,
pub address: String,
pub gateway: String,
pub subnet: String,
}

pub(crate) struct Network(Handle);

impl Network {
Expand All @@ -62,9 +69,12 @@ impl Network {
Ok(Self(handle))
}

pub(crate) async fn init(&self) -> Result<(), NetworkError> {
pub(crate) async fn init(
&self,
config: &Config,
) -> Result<(), NetworkError> {
configure_loopback(&self.0).await?;
configure_nic(&self.0).await?;
configure_nic(&self.0, config).await?;
Ok(())
}

Expand Down Expand Up @@ -125,38 +135,32 @@ async fn configure_loopback(handle: &Handle) -> Result<(), NetworkError> {
Ok(())
}

// TODO: design network config struct
async fn configure_nic(handle: &Handle) -> Result<(), NetworkError> {
const DEFAULT_NET_DEV: &str = "eth0";
const DEFAULT_NET_DEV_IPV6: &str = "fe80::2";
const DEFAULT_NET_DEV_IPV6_GATEWAY: &str = "fe80::1";
const DEFAULT_NET_DEV_IPV6_SUBNET: &str = "/64";

trace!("configure {DEFAULT_NET_DEV}");

let ipv6_addr =
format!("{DEFAULT_NET_DEV_IPV6}{DEFAULT_NET_DEV_IPV6_SUBNET}")
.parse::<Ipv6Network>()
.expect("valid ipv6 address");
async fn configure_nic(
handle: &Handle,
config: &Config,
) -> Result<(), NetworkError> {
trace!("configure {0}", config.device);

let gateway = DEFAULT_NET_DEV_IPV6_GATEWAY
.to_string()
let ipv6_addr = format!("{0}{1}", config.address, config.subnet)
.parse::<Ipv6Network>()
.expect("gateway");
.expect("valid ipv6 address");

add_address(handle, DEFAULT_NET_DEV.to_owned(), ipv6_addr).await?;
let gateway =
config.gateway.to_string().parse::<Ipv6Network>().expect("gateway");

set_link_up(handle, DEFAULT_NET_DEV.to_owned()).await?;
add_address(handle, config.device.clone(), ipv6_addr).await?;

set_link_up(handle, config.device.clone()).await?;

add_route_v6(
handle,
DEFAULT_NET_DEV.to_owned(),
config.device.clone(),
"::/0".parse::<Ipv6Network>().expect("valid ipv6 address"),
gateway,
)
.await?;

info!("Successfully configured {DEFAULT_NET_DEV}");
info!("Successfully configured {0}", config.device);
Ok(())
}

Expand Down Expand Up @@ -371,4 +375,4 @@ async fn dump_addresses(
} else {
Err(NetworkError::DeviceNotFound { iface: iface.to_string() })
}
}
}
15 changes: 14 additions & 1 deletion auraed/src/init/system_runtimes/pid1_system_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,22 @@ impl SystemRuntime for Pid1SystemRuntime {
.mount()?;

trace!("Configure network");

const DEFAULT_NET_DEV: &str = "eth0";
const DEFAULT_NET_DEV_IPV6: &str = "fe80::2";
const DEFAULT_NET_DEV_IPV6_GATEWAY: &str = "fe80::1";
const DEFAULT_NET_DEV_IPV6_SUBNET: &str = "/64";

// show_dir("/sys/class/net/", false); // Show available network interfaces
let network = network::Network::connect()?;
network.init().await?;
network
.init(&network::Config {
device: DEFAULT_NET_DEV.to_owned(),
address: DEFAULT_NET_DEV_IPV6.to_owned(),
gateway: DEFAULT_NET_DEV_IPV6_GATEWAY.to_owned(),
subnet: DEFAULT_NET_DEV_IPV6_SUBNET.to_owned(),
})
.await?;
network.show_network_info().await;

// TODO: do we need to create an interface and address for socket_address?
Expand Down
55 changes: 55 additions & 0 deletions auraed/src/vms/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* -------------------------------------------------------------------------- *\
* | █████╗ ██╗ ██╗██████╗ █████╗ ███████╗ | *
* | ██╔══██╗██║ ██║██╔══██╗██╔══██╗██╔════╝ | *
* | ███████║██║ ██║██████╔╝███████║█████╗ | *
* | ██╔══██║██║ ██║██╔══██╗██╔══██║██╔══╝ | *
* | ██║ ██║╚██████╔╝██║ ██║██║ ██║███████╗ | *
* | ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ | *
* +--------------------------------------------+ *
* *
* Distributed Systems Runtime *
* -------------------------------------------------------------------------- *
* Copyright 2022 - 2024, the aurae contributors *
* SPDX-License-Identifier: Apache-2.0 *
\* -------------------------------------------------------------------------- */

use thiserror::Error;
use tonic::Status;
use tracing::error;

use super::virtual_machine::VmID;

pub(crate) type Result<T> = std::result::Result<T, VmServiceError>;

#[derive(Debug, Error)]
pub(crate) enum VmServiceError {
#[error("vm '{id}' could not be allocated: {source}")]
FailedToAllocateError { id: VmID, source: anyhow::Error },
#[error("vm '{id}' could not be freed: {source}")]
FailedToFreeError { id: VmID, source: anyhow::Error },
#[error("vm '{id}' could not be started: {source}")]
FailedToStartError { id: VmID, source: anyhow::Error },
#[error("vm '{id}' could not be stopped: {source}")]
FailedToStopError { id: VmID, source: anyhow::Error },
#[error("vm config has no machine specified")]
MissingMachineConfig,
#[error("vm '{id}' config has no root drive specified")]
MissingRootDrive { id: VmID },
}

impl From<VmServiceError> for Status {
fn from(err: VmServiceError) -> Self {
let msg = err.to_string();
error!("{msg}");
match err {
VmServiceError::FailedToAllocateError { .. }
| VmServiceError::FailedToFreeError { .. }
| VmServiceError::FailedToStartError { .. }
| VmServiceError::FailedToStopError { .. } => Status::internal(msg),
VmServiceError::MissingMachineConfig { .. }
| VmServiceError::MissingRootDrive { .. } => {
Status::failed_precondition(msg)
}
}
}
}
4 changes: 1 addition & 3 deletions auraed/src/vms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
* SPDX-License-Identifier: Apache-2.0 *
\* -------------------------------------------------------------------------- */

mod error;
mod manager;
mod virtual_machine;
mod virtual_machines;
mod vm_service;

pub(crate) use vm_service::VmService;

// TODO: Custom Errors
// pub mod errors;
Loading

0 comments on commit 74ad161

Please sign in to comment.