### Manage a Firecracker VM with Machine Source: https://context7.com/rik-org/firepilot/llms.txt Demonstrates configuring a kernel, root drive, and executor to create, start, and stop a microVM. ```rust use firepilot::machine::Machine; use firepilot::builder::{Configuration, Builder}; use firepilot::builder::kernel::KernelBuilder; use firepilot::builder::drive::DriveBuilder; use firepilot::builder::executor::FirecrackerExecutorBuilder; use std::path::PathBuf; use tokio::time::{sleep, Duration}; #[tokio::main] async fn main() -> Result<(), Box> { // Configure the kernel let kernel = KernelBuilder::new() .with_kernel_image_path("/path/to/kernel.bin".to_string()) .with_boot_args("reboot=k panic=1 pci=off".to_string()) .try_build() .unwrap(); // Configure the root drive let drive = DriveBuilder::new() .with_drive_id("rootfs".to_string()) .with_path_on_host(PathBuf::from("/path/to/rootfs.ext4")) .as_read_only() .as_root_device() .try_build() .unwrap(); // Configure the executor let executor = FirecrackerExecutorBuilder::new() .with_chroot("/srv/firepilot/".to_string()) .with_exec_binary(PathBuf::from("/usr/bin/firecracker")) .try_build() .unwrap(); // Create configuration and machine let config = Configuration::new("my_vm".to_string()) .with_kernel(kernel) .with_executor(executor) .with_drive(drive); let mut machine = Machine::new(); machine.create(config).await?; // Start the VM machine.start().await?; // Let it run for a while sleep(Duration::from_secs(10)).await; // Gracefully stop and kill machine.stop().await?; machine.kill().await?; Ok(()) } ``` -------------------------------- ### Configure Kernel Boot Source with KernelBuilder Source: https://context7.com/rik-org/firepilot/llms.txt Configures the kernel boot source, including the kernel image path, boot arguments, and an optional initrd. Use this to set up how the VM's kernel will start. ```rust use firepilot::builder::kernel::KernelBuilder; use firepilot::builder::Builder; // Minimal kernel configuration let kernel_minimal = KernelBuilder::new() .with_kernel_image_path("/path/to/vmlinux.bin".to_string()) .try_build() .unwrap(); ``` ```rust use firepilot::builder::kernel::KernelBuilder; use firepilot::builder::Builder; // Full kernel configuration with boot args and initrd let kernel_full = KernelBuilder::new() .with_kernel_image_path("/path/to/vmlinux.bin".to_string()) .with_boot_args("console=ttyS0 reboot=k panic=1 pci=off nomodules 8250.nr_uarts=0".to_string()) .with_initrd_path("/path/to/initrd.img".to_string()) .try_build() .unwrap(); ``` ```rust use firepilot::builder::kernel::KernelBuilder; use firepilot::builder::Builder; // Example boot args for different scenarios let debug_kernel = KernelBuilder::new() .with_kernel_image_path("/path/to/vmlinux.bin".to_string()) .with_boot_args("console=ttyS0 reboot=k panic=1 pci=off random.trust_cpu=on".to_string()) .try_build() .unwrap(); ``` -------------------------------- ### Create MicroVM with Network Interface Source: https://context7.com/rik-org/firepilot/llms.txt This Rust code demonstrates the complete setup for a microVM with network connectivity. It requires a pre-configured TAP device on the host. Ensure the kernel image and root filesystem paths are correct. ```rust use firepilot:: builder:: drive::DriveBuilder, executor::FirecrackerExecutorBuilder, kernel::KernelBuilder, network_interface::NetworkInterfaceBuilder, Builder, Configuration, }, machine::Machine, }; use std::path::PathBuf; use tokio::time::{sleep, Duration}; #[tokio::main] async fn main() -> Result<(), Box> { // Configure kernel with network-friendly boot args let kernel = KernelBuilder::new() .with_kernel_image_path("/path/to/kernel.bin".to_string()) .with_boot_args("reboot=k panic=1 pci=off random.trust_cpu=on".to_string()) .try_build() .unwrap(); // Configure root filesystem let drive = DriveBuilder::new() .with_drive_id("rootfs".to_string()) .with_path_on_host(PathBuf::from("/path/to/rootfs.ext4")) .as_read_only() .as_root_device() .try_build() .unwrap(); // Configure executor let executor = FirecrackerExecutorBuilder::new() .with_chroot("./vms/".to_string()) .with_exec_binary(PathBuf::from("/usr/bin/firecracker")) .try_build() .unwrap(); // Configure network interface (requires pre-created tap0 device) // Create tap device: sudo ip tuntap add dev tap0 mode tap // Configure tap: sudo ip addr add 172.16.0.1/24 dev tap0 && sudo ip link set tap0 up let iface = NetworkInterfaceBuilder::new() .with_iface_id("eth0".to_string()) .with_host_dev_name("tap0".to_string()) .with_guest_mac("06:00:AC:10:00:02".to_string()) .try_build() .unwrap(); // Assemble configuration let config = Configuration::new("networked_vm".to_string()) .with_kernel(kernel) .with_executor(executor) .with_drive(drive) .with_interface(iface); // Create and run the VM let mut machine = Machine::new(); machine.create(config).await?; println!("Starting VM with network..."); machine.start().await?; // VM is now running with network interface eth0 // Guest can be configured with IP 172.16.0.2/24 println!("VM running - network available on tap0"); sleep(Duration::from_secs(60)).await; machine.stop().await?; machine.kill().await?; Ok(()) } ``` -------------------------------- ### Configure Network Interfaces with NetworkInterfaceBuilder Source: https://context7.com/rik-org/firepilot/llms.txt Demonstrates creating network interfaces with basic settings, custom MAC addresses, and rate limiting using TokenBucket configurations. ```rust use firepilot::builder::network_interface::NetworkInterfaceBuilder; use firepilot::builder::Builder; use firepilot_models::models::RateLimiter; use firepilot_models::models::TokenBucket; // Basic network interface let basic_iface = NetworkInterfaceBuilder::new() .with_iface_id("eth0".to_string()) .with_host_dev_name("tap0".to_string()) .try_build() .unwrap(); // Network interface with custom MAC address let custom_mac_iface = NetworkInterfaceBuilder::new() .with_iface_id("eth0".to_string()) .with_host_dev_name("tap0".to_string()) .with_guest_mac("06:00:AC:10:00:02".to_string()) .try_build() .unwrap(); // Network interface with rate limiting let rate_limiter = RateLimiter { bandwidth: Some(Box::new(TokenBucket { size: 1048576, // 1 MB one_time_burst: Some(1048576), refill_time: 1000, // 1 second })), ops: None, }; let rate_limited_iface = NetworkInterfaceBuilder::new() .with_iface_id("eth0".to_string()) .with_host_dev_name("tap0".to_string()) .with_rx_rate_limiter(Box::new(rate_limiter.clone())) .with_tx_rate_limiter(Box::new(rate_limiter)) .try_build() .unwrap(); ``` -------------------------------- ### Configure and control a microVM with Executor Source: https://context7.com/rik-org/firepilot/llms.txt Demonstrates initializing a FirecrackerExecutor, configuring boot sources, drives, and network interfaces, and managing VM state transitions. ```rust use firepilot::executor::{Executor, FirecrackerExecutor, Action}; use firepilot_models::models::{BootSource, Drive, NetworkInterface}; use firepilot_models::models::vm::{Vm, State}; use std::path::PathBuf; #[tokio::main] async fn main() -> Result<(), Box> { // Create a low-level executor let firecracker = FirecrackerExecutor { chroot: "/srv/firepilot".to_string(), exec_binary: PathBuf::from("/usr/bin/firecracker"), }; let mut executor = Executor::new_with_firecracker(firecracker) .with_id("low_level_vm".to_string()); // Create workspace directory executor.create_workspace()?; // Start the Firecracker socket process executor.run_socket()?; // Configure boot source directly let boot_source = BootSource { kernel_image_path: "/srv/firepilot/low_level_vm/vmlinux".to_string(), boot_args: Some("reboot=k panic=1 pci=off".to_string()), initrd_path: None, }; executor.configure_boot_source(boot_source).await?; // Configure drives directly let drives = vec![ Drive { drive_id: "rootfs".to_string(), path_on_host: "/srv/firepilot/low_level_vm/rootfs".to_string(), is_root_device: true, is_read_only: true, cache_type: None, partuuid: None, rate_limiter: None, io_engine: None, }, ]; executor.configure_drives(drives).await?; // Configure network interfaces let interfaces = vec![ NetworkInterface { iface_id: "eth0".to_string(), host_dev_name: "tap0".to_string(), guest_mac: Some("06:00:AC:10:00:02".to_string()), rx_rate_limiter: None, tx_rate_limiter: None, }, ]; executor.configure_network(interfaces).await?; // Start the VM executor.send_action(Action::InstanceStart).await?; // Check if running assert!(executor.is_running()); // Pause the VM executor.set_vm_state(Vm::new(State::Paused)).await?; // Resume the VM executor.set_vm_state(Vm::new(State::Resumed)).await?; // Send graceful shutdown signal executor.send_action(Action::SendCtrlAltDel).await?; // Destroy the socket process executor.destroy_socket().await?; Ok(()) } ``` -------------------------------- ### Build Complete VM Configuration with Builders Source: https://context7.com/rik-org/firepilot/llms.txt Aggregates kernel, executor, drives, and network interfaces using a fluent builder pattern. Ensure all necessary builders are correctly configured before creating the final Configuration. ```rust use firepilot::builder::{Configuration, Builder}; use firepilot::builder::kernel::KernelBuilder; use firepilot::builder::drive::DriveBuilder; use firepilot::builder::executor::FirecrackerExecutorBuilder; use firepilot::builder::network_interface::NetworkInterfaceBuilder; use std::path::PathBuf; // Build kernel configuration let kernel = KernelBuilder::new() .with_kernel_image_path("/path/to/kernel.bin".to_string()) .with_boot_args("console=ttyS0 reboot=k panic=1 pci=off".to_string()) .with_initrd_path("/path/to/initrd.img".to_string()) // Optional .try_build() .unwrap(); // Build root drive let rootfs = DriveBuilder::new() .with_drive_id("rootfs".to_string()) .with_path_on_host(PathBuf::from("/path/to/rootfs.ext4")) .as_root_device() .as_read_only() .try_build() .unwrap(); // Build additional data drive let data_drive = DriveBuilder::new() .with_drive_id("data".to_string()) .with_path_on_host(PathBuf::from("/path/to/data.ext4")) .try_build() .unwrap(); // Build network interface let network = NetworkInterfaceBuilder::new() .with_iface_id("eth0".to_string()) .with_host_dev_name("tap0".to_string()) .with_guest_mac("AA:BB:CC:DD:EE:FF".to_string()) .try_build() .unwrap(); // Build executor let executor = FirecrackerExecutorBuilder::new() .with_chroot("/srv/vms/".to_string()) .with_exec_binary(PathBuf::from("/usr/bin/firecracker")) .try_build() .unwrap(); // Create complete configuration let config = Configuration::new("full_vm".to_string()) .with_kernel(kernel) .with_executor(executor) .with_drive(rootfs) .with_drive(data_drive) .with_interface(network); ``` -------------------------------- ### Control VM State with Pause and Resume Source: https://context7.com/rik-org/firepilot/llms.txt Shows how to suspend and resume a running VM using the pause and resume methods. ```rust use firepilot::machine::Machine; use firepilot::builder::{Configuration, Builder}; use firepilot::builder::kernel::KernelBuilder; use firepilot::builder::drive::DriveBuilder; use firepilot::builder::executor::FirecrackerExecutorBuilder; use std::path::PathBuf; use tokio::time::{sleep, Duration}; #[tokio::main] async fn main() -> Result<(), Box> { let kernel = KernelBuilder::new() .with_kernel_image_path("/path/to/kernel.bin".to_string()) .with_boot_args("reboot=k panic=1 pci=off".to_string()) .try_build() .unwrap(); let drive = DriveBuilder::new() .with_drive_id("rootfs".to_string()) .with_path_on_host(PathBuf::from("/path/to/rootfs.ext4")) .as_root_device() .try_build() .unwrap(); let executor = FirecrackerExecutorBuilder::auto()?; let config = Configuration::new("pausable_vm".to_string()) .with_kernel(kernel) .with_executor(executor) .with_drive(drive); let mut machine = Machine::new(); machine.create(config).await?; machine.start().await?; // Let VM run for a bit sleep(Duration::from_secs(5)).await; // Pause the VM machine.pause().await?; println!("VM is now paused"); // Do some work while VM is paused... sleep(Duration::from_secs(2)).await; // Resume the VM machine.resume().await?; println!("VM is now resumed"); sleep(Duration::from_secs(3)).await; machine.stop().await?; machine.kill().await?; Ok(()) } ``` -------------------------------- ### Configure Block Devices with DriveBuilder Source: https://context7.com/rik-org/firepilot/llms.txt Configures block devices such as root filesystems and additional data drives. Supports read-only and root device options. Ensure the `PathBuf` points to a valid disk image. ```rust use firepilot::builder::drive::DriveBuilder; use firepilot::builder::Builder; use std::path::PathBuf; // Root filesystem drive (read-only) let rootfs = DriveBuilder::new() .with_drive_id("rootfs".to_string()) .with_path_on_host(PathBuf::from("/srv/images/ubuntu-18.04.ext4")) .as_root_device() .as_read_only() .try_build() .unwrap(); ``` ```rust use firepilot::builder::drive::DriveBuilder; use firepilot::builder::Builder; use std::path::PathBuf; // Data drive (read-write) let data = DriveBuilder::new() .with_drive_id("data".to_string()) .with_path_on_host(PathBuf::from("/srv/images/data.ext4")) .try_build() .unwrap(); ``` ```rust use firepilot::builder::drive::DriveBuilder; use firepilot::builder::Builder; use std::path::PathBuf; // Scratch drive (read-write, not root) let scratch = DriveBuilder::new() .with_drive_id("scratch".to_string()) .with_path_on_host(PathBuf::from("/srv/images/scratch.ext4")) .try_build() .unwrap(); ``` -------------------------------- ### Vsock Configuration Source: https://github.com/rik-org/firepilot/blob/main/docs/firecracker-vmm-config.md Defines the structure for configuring vsock devices, including guest CID and Unix domain socket path. ```APIDOC ## Vsock Configuration ### Description Configuration details for a vsock device, specifying its ID, the guest context identifier (CID), and the path to the local Unix domain socket. ### Parameters #### Request Body - **vsock** (Object) - Optional - Vsock configuration. - **vsock_id** (Option) - Optional - ID of the vsock device. - **guest_cid** (u32) - Required - A 32-bit Context Identifier (CID) used to identify the guest. - **uds_path** (String) - Required - Path to local unix socket. ### Request Example ```json { "vsock": { "vsock_id": "vsock0", "guest_cid": 3, "uds_path": "/run/firepilot/vsock.sock" } } ``` ### Response #### Success Response (200) - **status** (String) - Indicates the success of the operation. #### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### MicroVM Configuration Structure Source: https://github.com/rik-org/firepilot/blob/main/docs/firecracker-vmm-config.md This section details the structure of the JSON payload used to configure a MicroVM. It covers various aspects like balloon devices, drives, boot source, logging, machine configuration, metrics, MMDS, and network interfaces. ```APIDOC ## MicroVM Configuration ### Description This is the main configuration structure for a Firecracker MicroVM. It allows for detailed setup of various components. ### Request Body - **balloon** (object) - Optional - Configuration for the balloon device. - **amount_mib** (u32) - Required - Target balloon size in MiB. - **deflate_on_oom** (bool) - Required - Option to deflate the balloon in case the guest is out of memory. - **stats_polling_interval_s** (u16) - Required - Interval in seconds between refreshing statistics. - **drives** (array) - Required - Configuration for block devices. - **drive_id** (String) - Required - Unique identifier of the drive. - **path_on_host** (String) - Required - Path of the drive on the host. - **is_root_device** (bool) - Required - If set to true, this device is the root block device. - **partuuid** (String) - Optional - Part-UUID of the boot partition (used if `is_root_device` is true). - **is_read_only** (bool) - Required - If true, the drive is opened in read-only mode. - **cache_type** (Unsafe | Writeback) - Required - Cache type for the drive. - **rate_limiter** (object) - Optional - Rate limiter configuration for I/O operations. - **bandwidth** (object) - Optional - Bandwidth rate limiter settings. - **size** (u64) - Required - The size of the token bucket. - **one_time_burst** (u64) - Required - The maximum burst size. - **refill_time** (u64) - Required - The time in seconds to refill the bucket. - **ops** (object) - Optional - Operations rate limiter settings. - **size** (u64) - Required - The size of the token bucket. - **one_time_burst** (u64) - Required - The maximum burst size. - **refill_time** (u64) - Required - The time in seconds to refill the bucket. - **file_engine_type** (Async | Sync) - Required - The type of IO engine. - **boot-source** (object) - Required - Configuration for the boot source. - **kernel_image_path** (String) - Required - Path to the kernel image. - **initrd_path** (String) - Optional - Path to the initrd image. - **boot_args** (String) - Optional - Kernel command line arguments. - **logger** (object) - Optional - Logger configuration. - **log_path** (PathBuf) - Required - Path for logger output. - **level** (Error | Warning | Info | Debug) - Required - Logging level. - **show_level** (bool) - Required - Whether to show log level. - **show_log_origin** (bool) - Required - Whether to show log origin. - **machine-config** (object) - Optional - Machine configuration. - **vcpu_count** (u8) - Required - Number of vCPUs. - **mem_size_mib** (u32) - Required - Memory size in MiB. - **smt** (bool) - Required - Enable or disable SMT. - **cpu_template** (C3 | T2 | T2S | None | T2CL | T2A) - Required - CPU template to use. - **track_dirty_pages** (bool) - Required - Enable or disable dirty page tracking. - **metrics** (object) - Optional - Metrics configuration. - **metrics_path** (PathBuf) - Required - Path for metrics output. - **mmds-config** (object) - Optional - MMDS configuration. - **version** (V1 | V2) - Required - MMDS version. - **network-interface** (array) - Required - Network interfaces allowed to forward packets to MMDS. - **ipv4_address** (Ipv4Addr) - Optional - Configured IPv4 address for MMDS. - **network-interfaces** (array) - Required - Configuration for network interfaces. - (object) - Each object represents a network interface configuration. ### Request Example ```json { "balloon": { "amount_mib": 1024, "deflate_on_oom": true, "stats_polling_interval_s": 10 }, "drives": [ { "drive_id": "rootfs", "path_on_host": "/path/to/rootfs.img", "is_root_device": true, "is_read_only": false, "cache_type": "Writeback", "rate_limiter": { "bandwidth": { "size": 50000000, "one_time_burst": 50000000, "refill_time": 1 } }, "file_engine_type": "Async" } ], "boot-source": { "kernel_image_path": "/path/to/vmlinux", "initrd_path": "/path/to/initrd", "boot_args": "console=ttyS0" }, "logger": { "log_path": "/path/to/firecracker.log", "level": "Info", "show_level": true, "show_log_origin": true }, "machine-config": { "vcpu_count": 2, "mem_size_mib": 1024, "smt": false, "cpu_template": "T2", "track_dirty_pages": true }, "metrics": { "metrics_path": "/path/to/metrics.json" }, "mmds-config": { "version": "V2", "network-interface": ["eth0"], "ipv4_address": "169.254.169.254" }, "network-interfaces": [ { "iface_id": "eth0", "guest_mac": "02:00:00:00:00:01", "host_dev_name": "tap0" } ] } ``` ``` -------------------------------- ### Configure Firecracker Executor with FirecrackerExecutorBuilder Source: https://context7.com/rik-org/firepilot/llms.txt Shows manual path configuration and automatic binary detection for the Firecracker executor. ```rust use firepilot::builder::executor::FirecrackerExecutorBuilder; use firepilot::builder::Builder; use std::path::PathBuf; // Manual configuration with explicit paths let executor_manual = FirecrackerExecutorBuilder::new() .with_chroot("/srv/firepilot/".to_string()) .with_exec_binary(PathBuf::from("/usr/bin/firecracker")) .try_build() .unwrap(); // Automatic configuration - searches for firecracker binary in: // 1. FIRECRACKER_LOCATION environment variable // 2. System PATH // 3. Current working directory // Uses /srv as default chroot let executor_auto = FirecrackerExecutorBuilder::auto() .expect("Firecracker binary not found"); // Automatic binary detection with custom chroot let binary_path = FirecrackerExecutorBuilder::determine_binary_location() .expect("Could not find firecracker binary"); let executor_custom_chroot = FirecrackerExecutorBuilder::new() .with_chroot("/var/lib/firepilot/vms/".to_string()) .with_exec_binary(binary_path) .try_build() .unwrap(); ``` -------------------------------- ### Firecracker MicroVM Configuration Structure Source: https://github.com/rik-org/firepilot/blob/main/docs/firecracker-vmm-config.md This Rust struct represents the strongly typed equivalent of the JSON body for configuring a MicroVM. It includes options for balloon devices, drives, boot source, logger, machine configuration, metrics, MMDS, and network interfaces. ```rust { /// This struct represents the strongly typed equivalent of the json body /// from balloon related requests. "balloon": Option<{ /// Target balloon size in MiB. "amount_mib": u32, /// Option to deflate the balloon in case the guest is out of memory. "deflate_on_oom": bool, /// Interval in seconds between refreshing statistics. "stats_polling_interval_s": u16, }>, /// Use this structure to set up the Block Device before booting the kernel. "drives": [ { /// Unique identifier of the drive. "drive_id": String, /// Path of the drive. "path_on_host": String, /// If set to true, it makes the current device the root block device. /// Setting this flag to true will mount the block device in the /// guest under /dev/vda unless the partuuid is present. "is_root_device": bool, /// Part-UUID. Represents the unique id of the boot partition of this device. It is /// optional and it will be used only if the `is_root_device` field is true. "partuuid": Option, /// If set to true, the drive is opened in read-only mode. Otherwise, /// the drive is opened as read-write. "is_read_only": bool, /// If set to true, the drive will ignore flush requests coming from /// the guest driver. "cache_type": Unsafe | Writeback, /// Rate Limiter for I/O operations. /// A public-facing, stateless structure, holding all the data we need to create a RateLimiter /// (live) object. "rate_limiter": { /// Data used to initialize the RateLimiter::bandwidth bucket. "bandwidth": Option<{ "size": u64, "one_time_burst": u64, "refill_time": u64, }>, /// Data used to initialize the RateLimiter::ops bucket. "ops": Option<{ "size": u64, "one_time_burst": u64, "refill_time": u64, }>, }, /// The type of IO engine used by the device. "file_engine_type": Async | Sync, } ], /// Strongly typed data structure used to configure the boot source of the /// microvm. "boot-source": { /// Path to the kernel image. "kernel_image_path": String, /// Path to the initrd image. "initrd_path": Option, /// The boot arguments to pass to the kernel. If this field is uninitialized, the default /// kernel command line is used: `reboot=k panic=1 pci=off nomodules 8250.nr_uarts=0`. "boot_args": Option, }, /// Strongly typed structure used to describe the logger. "logger": Option<{ /// Named pipe where the logger will output the metrics. "log_path": PathBuf, /// The level of the logger "level": Error | Warning | Info | Debug, /// When enabled, the logger will append to the output the severity of the log entry. "show_level": bool, /// When enabled, the logger will append the origin of the log entry. "show_log_origin": bool, }>, /// Strongly typed structure that represents the configuration of the /// microvm. "machine-config": Option<{ /// Number of vcpu to start "vcpu_count": u8, /// The memory size in MiB. "mem_size_mib": u32, /// Enables or disabled SMT. "smt": bool, /// A CPU template that it is used to filter the CPU features exposed to the guest. "cpu_template": C3 | T2 | T2S | None | T2CL | T2A, /// Enables or disables dirty page tracking. Enabling allows incremental snapshots. "track_dirty_pages": bool, }>, "metrics": Option<{ /// Named pipe or file used as output for metrics. "metrics_path": PathBuf, }>, /// Keeps the MMDS configuration. "mmds-config": Option<{ /// MMDS version. "version": V1 | V2, /// Network interfaces that allow forwarding packets to MMDS. "network-interface": [String], /// MMDS IPv4 configured address. "ipv4_address": Option, }>, /// This struct represents the strongly typed equivalent of the json body from net iface /// related requests. "network-interfaces": Vec<{ ``` -------------------------------- ### Network Interface Configuration Source: https://github.com/rik-org/firepilot/blob/main/docs/firecracker-vmm-config.md Defines the structure for configuring network interfaces, including rate limiting for received and transmitted packets. ```APIDOC ## Network Interface Configuration ### Description Configuration details for a network interface, including its ID, host device name, guest MAC address, and rate limiters for ingress and egress traffic. ### Parameters #### Request Body - **iface_id** (String) - Required - ID of the guest network interface. - **host_dev_name** (String) - Required - Host name of the network interface. - **guest_mac** (Option) - Optional - Guest MAC address. - **rx_rate_limiter** (Object) - Optional - Rate Limiter for receiving packages. - **bandwidth** (Object) - Optional - Data used to initialize the RateLimiter::bandwidth bucket. - **size** (u64) - Required - See TokenBucket::size. - **one_time_burst** (Option) - Optional - See TokenBucket::one_time_burst. - **refill_time** (u64) - Required - See TokenBucket::refill_time. - **ops** (Object) - Optional - Data used to initialize the RateLimiter::ops bucket. - **size** (u64) - Required - See TokenBucket::size. - **one_time_burst** (Option) - Optional - See TokenBucket::one_time_burst. - **refill_time** (u64) - Required - See TokenBucket::refill_time. - **tx_rate_limiter** (Object) - Optional - Rate Limiter for transmitted packages. - **bandwidth** (Object) - Optional - Data used to initialize the RateLimiter::bandwidth bucket. - **size** (u64) - Required - See TokenBucket::size. - **one_time_burst** (Option) - Optional - See TokenBucket::one_time_burst. - **refill_time** (u64) - Required - See TokenBucket::refill_time. - **ops** (Object) - Optional - Data used to initialize the RateLimiter::ops bucket. - **size** (u64) - Required - See TokenBucket::size. - **one_time_burst** (Option) - Optional - See TokenBucket::one_time_burst. - **refill_time** (u64) - Required - See TokenBucket::refill_time. ### Request Example ```json { "iface_id": "eth0", "host_dev_name": "/dev/tap0", "guest_mac": "02:42:ac:11:00:02", "rx_rate_limiter": { "bandwidth": { "size": 10000000, "refill_time": 1000 }, "ops": { "size": 1000, "one_time_burst": 50, "refill_time": 1000 } }, "tx_rate_limiter": { "bandwidth": { "size": 10000000, "one_time_burst": 5000000, "refill_time": 1000 } } } ``` ### Response #### Success Response (200) - **status** (String) - Indicates the success of the operation. #### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### Handle Firepilot Builder Errors Source: https://context7.com/rik-org/firepilot/llms.txt Catch `BuilderError` variants like `MissingRequiredField` and `BinaryNotFound` when building components. Ensure all required fields are provided and binaries are accessible. ```rust use firepilot::machine::{Machine, FirepilotError}; use firepilot::builder::{Configuration, Builder, BuilderError}; use firepilot::builder::kernel::KernelBuilder; use firepilot::builder::drive::DriveBuilder; use firepilot::builder::executor::FirecrackerExecutorBuilder; use std::path::PathBuf; #[tokio::main] async fn main() { // Handle builder errors let kernel_result = KernelBuilder::new() .with_boot_args("reboot=k".to_string()) // Missing required kernel_image_path .try_build(); match kernel_result { Ok(_) => println!("Kernel configured"), Err(BuilderError::MissingRequiredField(field)) => { eprintln!("Missing required field: {}", field); } Err(BuilderError::BinaryNotFound(msg)) => { eprintln!("Binary not found: {}", msg); } } // Handle executor auto-detection errors let executor_result = FirecrackerExecutorBuilder::auto(); match executor_result { Ok(builder) => { let executor = builder.try_build().unwrap(); println!("Executor configured automatically"); } Err(BuilderError::BinaryNotFound(msg)) => { eprintln!("Firecracker not found: {}", msg); eprintln!("Set FIRECRACKER_LOCATION or add to PATH"); } Err(e) => eprintln!("Error: {:?}", e), } // Handle machine lifecycle errors let kernel = KernelBuilder::new() .with_kernel_image_path("/path/to/kernel.bin".to_string()) .try_build() .unwrap(); let drive = DriveBuilder::new() .with_drive_id("rootfs".to_string()) .with_path_on_host(PathBuf::from("/path/to/rootfs.ext4")) .as_root_device() .try_build() .unwrap(); let executor = FirecrackerExecutorBuilder::new() .with_chroot("/srv/vms/".to_string()) .with_exec_binary(PathBuf::from("/usr/bin/firecracker")) .try_build() .unwrap(); let config = Configuration::new("error_handling_vm".to_string()) .with_kernel(kernel) .with_executor(executor) .with_drive(drive); let mut machine = Machine::new(); match machine.create(config).await { Ok(_) => println!("VM created successfully"), Err(FirepilotError::Setup(msg)) => { eprintln!("Setup error (file/directory issue): {}", msg); } Err(FirepilotError::Configure(msg)) => { eprintln!("Configuration error (socket communication): {}", msg); } Err(FirepilotError::Execute(msg)) => { eprintln!("Execution error (process issue): {}", msg); } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.