Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
Signed-off-by: Mauran <[email protected]>
  • Loading branch information
thomas-mauran committed Apr 22, 2024
1 parent 572dfaf commit 9a0f75d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/vmm/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub enum Commands {
Cli(CliArguments),
#[command(about = "Run a GRPC server listening for incoming requests.")]
Grpc,
}
}

/// Run a VMM instance.
#[derive(Parser, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ pub enum VmmErrors {
VmmNew(core::Error),
VmmConfigure(core::Error),
VmmRun(core::Error),
}
}
43 changes: 27 additions & 16 deletions src/vmm/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use crate::args::{CliArgs, Commands};
use clap::Parser;
use tracing::info;
use vmm::{core::{vmm::VMM}, service::{vmmorchestrator, VmmService}, VmmErrors};
use tonic::transport::Server;
use tracing::info;
use vmm::{
core::vmm::VMM,
service::{vmmorchestrator, VmmService},
VmmErrors,
};
mod args;

#[tokio::main]
Expand All @@ -23,27 +27,34 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
match args.command {
Commands::Grpc => {
Server::builder()
.add_service(vmmorchestrator::vmm_service_server::VmmServiceServer::new(vmm_service))
.serve(addr)
.await?;

.add_service(vmmorchestrator::vmm_service_server::VmmServiceServer::new(
vmm_service,
))
.serve(addr)
.await?;
}
Commands::Cli(cli_args) => {

tracing_subscriber::fmt()
.with_max_level(cli_args.convert_log_to_tracing())
.init();
.with_max_level(cli_args.convert_log_to_tracing())
.init();
// Create a new VMM
let mut vmm =
VMM::new(cli_args.network_host_ip, cli_args.network_host_netmask).map_err(VmmErrors::VmmNew).unwrap();

vmm.configure(cli_args.cpus, cli_args.memory, &cli_args.kernel, &cli_args.initramfs)
.map_err(VmmErrors::VmmConfigure).unwrap();

let mut vmm = VMM::new(cli_args.network_host_ip, cli_args.network_host_netmask)
.map_err(VmmErrors::VmmNew)
.unwrap();

vmm.configure(
cli_args.cpus,
cli_args.memory,
&cli_args.kernel,
&cli_args.initramfs,
)
.map_err(VmmErrors::VmmConfigure)
.unwrap();

// Run the VMM
vmm.run().map_err(VmmErrors::VmmRun).unwrap();
}
}

Ok(())
}
34 changes: 22 additions & 12 deletions src/vmm/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
use tonic::{transport::Server, Request, Response, Status};
use crate::core::vmm::{self, VMM};
use std::{convert::From, net::Ipv4Addr, path::{Path, PathBuf}, process::{Command, Stdio}};
use self::vmmorchestrator::{
vmm_service_server::VmmService as VmmServiceTrait, RunVmmRequest, RunVmmResponse,
};
use crate::core::vmm::VMM;
use crate::VmmErrors;
use self::vmmorchestrator::{vmm_service_server::VmmService as VmmServiceTrait, RunVmmRequest, RunVmmResponse};
use std::{
convert::From,
net::Ipv4Addr,
path::{Path, PathBuf},
process::{Command, Stdio},
};
use tonic::{Request, Response, Status};
use tracing::{error, info};

pub mod vmmorchestrator {
Expand All @@ -28,15 +35,17 @@ pub struct VmmService;
impl VmmServiceTrait for VmmService {
async fn run(
&self,
request: Request<RunVmmRequest>,
_request: Request<RunVmmRequest>,
) -> Result<Response<RunVmmResponse>, Status> {
let response = vmmorchestrator::RunVmmResponse {};

const HOST_IP: Ipv4Addr = Ipv4Addr::new(172, 29, 0, 1);
const HOST_NETMASK: Ipv4Addr = Ipv4Addr::new(255, 255, 0, 0);

// Check if the kernel is on the system, else build it
if !Path::new("./tools/kernel/linux-cloud-hypervisor/arch/x86/boot/compressed/vmlinux.bin").exists() {
if !Path::new("./tools/kernel/linux-cloud-hypervisor/arch/x86/boot/compressed/vmlinux.bin")
.exists()
{
info!("Kernel not found, building kernel");
// Execute the script using sh and capture output and error streams
let output = Command::new("sh")
Expand All @@ -51,18 +60,19 @@ impl VmmServiceTrait for VmmService {
error!("Script errors: {}", String::from_utf8_lossy(&output.stderr));
};

let kernel_path = &Path::new("./tools/kernel/linux-cloud-hypervisor/arch/x86/boot/compressed/vmlinux.bin");
let mut initramfs_path: PathBuf = PathBuf::new();
let kernel_path = &Path::new(
"./tools/kernel/linux-cloud-hypervisor/arch/x86/boot/compressed/vmlinux.bin",
);
let mut initramfs_path: PathBuf = PathBuf::new();

// Todo - Check if the initramfs for the specified language is on the system, else build it
initramfs_path.push("./tools/rootfs/initramfs.img");

// // Create a new VMM
let mut vmm =
VMM::new(HOST_IP, HOST_NETMASK).map_err(VmmErrors::VmmNew)?;
let mut vmm = VMM::new(HOST_IP, HOST_NETMASK).map_err(VmmErrors::VmmNew)?;

// Configure the VMM parameters might need to be calculated rather than hardcoded
vmm.configure(1, 512, &kernel_path, &Some(initramfs_path))
vmm.configure(1, 512, kernel_path, &Some(initramfs_path))
.map_err(VmmErrors::VmmConfigure)?;
// Run the VMM
vmm.run().map_err(VmmErrors::VmmRun)?;
Expand Down

0 comments on commit 9a0f75d

Please sign in to comment.