Module builder

Source
Expand description

§MicroVM Builder Pattern

This module provides a builder pattern to make the configuration of microVM easier. For each component, all fields are optional and are validated once you run the Builder::try_build method. Once the build is successful, you can consider it will properly be configured and can be used to start a microVM.

§Example

use std::{
  fs::File,
  io::copy,
  path::{Path, PathBuf},
};
use firepilot_models::models::{BootSource, Drive, NetworkInterface};
use firepilot::builder::{Configuration, Builder};
use firepilot::builder::{drive::DriveBuilder, kernel::KernelBuilder};
use firepilot::builder::executor::FirecrackerExecutorBuilder;
let path = Path::new("examples/resources");
let kernel_path = path.join("kernel.bin");
let rootfs_path = path.join("rootfs.ext4");

// Configure the kernel in the micro VM
let kernel = KernelBuilder::new()
    .with_kernel_image_path(kernel_path.to_str().unwrap().to_string())
    .with_boot_args("reboot=k panic=1 pci=off".to_string())
    .try_build()
    .unwrap();
// Create a single drive that will be used as rootfs
let drive = DriveBuilder::new()
    .with_drive_id("rootfs".to_string())
    .with_path_on_host(rootfs_path)
    .as_read_only()
    .as_root_device()
    .try_build()
    .unwrap();
// Configure the executor that will be used to start the microVM
// only firecracker is available, but you could add a jailer executor
let executor = FirecrackerExecutorBuilder::new()
    .with_chroot("./examples/executor/".to_string())
    .with_exec_binary(PathBuf::from("/usr/bin/firecracker"))
    .try_build()
    .unwrap();
// Execute the builder pattern to create the configuration which can be used
// to create a [Machine]
let config = Configuration::new("simple_vm".to_string())
    .with_kernel(kernel)
    .with_executor(executor)
    .with_drive(drive);

Modules§

drive
executor
kernel
network_interface

Structs§

Configuration
Configuration object which represent a microVM configuration, when using the Builder the final object is this one.

Enums§

BuilderError

Traits§

Builder
Generic trait which all builder componenet must implement in order to be part of Configuration