Firecracker HTTP Client
A comprehensive Rust HTTP client library for interacting with the Firecracker VMM API. This client provides a safe, ergonomic interface for managing Firecracker microVMs with full support for all Firecracker v1.11.0 features.
Features
- Complete API Coverage: Full support for all Firecracker API endpoints
- Async/Await: Built on Tokio for efficient async operations
- Type Safety: Strong typing for all API requests and responses
- Input Validation: Comprehensive validation of all API inputs
- Error Handling: Detailed error types with context
- Rate Limiting: Built-in support for API rate limiting
- Documentation: Extensive documentation and examples
Installation
Add this to your Cargo.toml
:
[]
= "0.1.3"
Core Components
Client Structure
The client is organized into trait-based modules for different Firecracker operations:
BootSourceOperations
: Manage kernel and boot parametersDriveOperations
: Configure block devicesNetworkInterfaceOperations
: Set up network interfacesMachineConfigOperations
: Configure VM resourcesSnapshotOperations
: Create and load VM snapshotsMetricsOperations
: Configure metrics collectionLoggerOperations
: Manage loggingInstanceOperations
: Control VM lifecycle
Key Types
Machine Configuration
use ;
let config = MachineConfig ;
client.put_machine_config.await?;
Network Configuration
use ;
let network = NetworkInterface ;
client.put_network_interface.await?;
Block Devices
use ;
let drive = Drive ;
client.put_drive.await?;
Usage Examples
Basic VM Setup
The basic_vm.rs example shows how to configure a simple microVM:
use ;
async
Complete VM Lifecycle
The vm_lifecycle.rs example demonstrates the full VM lifecycle:
- Initial Configuration
- VM Start
- Runtime Monitoring
- Graceful Shutdown
// Start the VM
let start_action = InstanceActionInfo ;
client.create_sync_action.await?;
// Monitor VM state
let instance_info = client.describe_instance.await?;
println!;
// Graceful shutdown
let shutdown_action = InstanceActionInfo ;
client.create_sync_action.await?;
Snapshot Management
The snapshot.rs example shows how to create and load VM snapshots:
// Create snapshot
let snapshot_params = SnapshotCreateParams ;
client.create_snapshot.await?;
// Load snapshot
let load_params = SnapshotLoadParams ;
client.load_snapshot.await?;
Error Handling
The client provides detailed error types for better error handling:
use FirecrackerError;
match result
Running the Examples
- Start Firecracker API server:
- Run the examples:
# Basic VM setup
# Complete VM lifecycle
# Snapshot management
Development
Running Tests
# Run all tests
# Run specific test
# Run with logs
RUST_LOG=debug
Contributing
- Fork the repository
- Create your feature branch
- Add tests for any new functionality
- Ensure all tests pass
- Submit a pull request
License
This project is licensed under the Apache License, Version 2.0.