hysn-firecracker-python 1.0.7__tar.gz → 1.0.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/AGENTS.md +40 -24
  2. hysn_firecracker_python-1.0.8/FIRECRACKER_SETUP.md +89 -0
  3. {hysn_firecracker_python-1.0.7/hysn_firecracker_python.egg-info → hysn_firecracker_python-1.0.8}/PKG-INFO +80 -57
  4. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/QUICKSTART.md +12 -15
  5. hysn_firecracker_python-1.0.8/README.md +226 -0
  6. hysn_firecracker_python-1.0.8/docs/README.md +64 -0
  7. hysn_firecracker_python-1.0.8/docs/advanced.md +169 -0
  8. hysn_firecracker_python-1.0.8/docs/api-reference.md +357 -0
  9. hysn_firecracker_python-1.0.8/docs/cleanup.md +185 -0
  10. hysn_firecracker_python-1.0.8/docs/cli.md +264 -0
  11. hysn_firecracker_python-1.0.8/docs/configuration.md +120 -0
  12. hysn_firecracker_python-1.0.8/docs/examples.md +220 -0
  13. hysn_firecracker_python-1.0.8/docs/getting-started.md +195 -0
  14. hysn_firecracker_python-1.0.8/docs/network.md +149 -0
  15. hysn_firecracker_python-1.0.8/docs/rootfs.md +127 -0
  16. hysn_firecracker_python-1.0.8/docs/snapshots.md +113 -0
  17. hysn_firecracker_python-1.0.8/examples/configure_vm_network.py +62 -0
  18. hysn_firecracker_python-1.0.8/examples/create_vm.py +31 -0
  19. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/examples/create_vm_with_filesystem_format.py +12 -2
  20. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/examples/load_snapshot.py +28 -25
  21. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/examples/sample.py +3 -3
  22. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/firecracker/__init__.py +3 -1
  23. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/firecracker/_version.py +3 -3
  24. hysn_firecracker_python-1.0.8/firecracker/cli.py +1098 -0
  25. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/firecracker/microvm.py +44 -3
  26. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/firecracker/network.py +154 -73
  27. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/firecracker/process.py +48 -13
  28. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/firecracker/vmm.py +41 -17
  29. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8/hysn_firecracker_python.egg-info}/PKG-INFO +80 -57
  30. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/hysn_firecracker_python.egg-info/SOURCES.txt +9 -1
  31. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/hysn_firecracker_python.egg-info/entry_points.txt +1 -0
  32. hysn_firecracker_python-1.0.8/hysn_firecracker_python.egg-info/scm_file_list.json +87 -0
  33. hysn_firecracker_python-1.0.8/hysn_firecracker_python.egg-info/scm_version.json +8 -0
  34. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/pyproject.toml +1 -0
  35. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/setup.py +1 -0
  36. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/tests/README.md +1 -1
  37. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/tests/conftest.py +13 -17
  38. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/tests/test_cleanup.py +4 -4
  39. hysn_firecracker_python-1.0.8/tests/test_cli.py +937 -0
  40. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/tests/test_network_error_paths.py +3 -7
  41. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/tests/test_process_manager.py +14 -12
  42. hysn_firecracker_python-1.0.8/tests/test_resource_leaks.py +310 -0
  43. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/verify-setup.py +5 -7
  44. hysn_firecracker_python-1.0.7/FIRECRACKER_SETUP.md +0 -103
  45. hysn_firecracker_python-1.0.7/README.md +0 -203
  46. hysn_firecracker_python-1.0.7/docs/README.md +0 -74
  47. hysn_firecracker_python-1.0.7/docs/api-reference.md +0 -308
  48. hysn_firecracker_python-1.0.7/docs/cleanup.md +0 -569
  49. hysn_firecracker_python-1.0.7/docs/configuration.md +0 -175
  50. hysn_firecracker_python-1.0.7/docs/examples.md +0 -315
  51. hysn_firecracker_python-1.0.7/docs/getting-started.md +0 -139
  52. hysn_firecracker_python-1.0.7/docs/index.md +0 -58
  53. hysn_firecracker_python-1.0.7/docs/network.md +0 -297
  54. hysn_firecracker_python-1.0.7/examples/configure_vm_network.py +0 -93
  55. hysn_firecracker_python-1.0.7/examples/create_vm.py +0 -22
  56. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  57. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  58. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/.github/workflows/pypi-release.yml +0 -0
  59. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/.gitignore +0 -0
  60. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/Dockerfile.test +0 -0
  61. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/LICENSE +0 -0
  62. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/Makefile +0 -0
  63. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/TODO.md +0 -0
  64. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/assets/img/firecracker.png +0 -0
  65. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/assets/rootfs/setup-firecracker-official.sh +0 -0
  66. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/cleanup_firecracker.py +0 -0
  67. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/debian/compat +0 -0
  68. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/debian/control +0 -0
  69. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/debian/copyright +0 -0
  70. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/debian/rules +0 -0
  71. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/docker-compose.test.yml +0 -0
  72. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/docs/testing-in-docker.md +0 -0
  73. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/examples/Dockerfile +0 -0
  74. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/examples/id_rsa +0 -0
  75. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/examples/id_rsa.pub +0 -0
  76. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/examples/init +0 -0
  77. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/examples/setup.sh +0 -0
  78. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/firecracker/api.py +0 -0
  79. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/firecracker/config.py +0 -0
  80. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/firecracker/exceptions.py +0 -0
  81. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/firecracker/logger.py +0 -0
  82. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/firecracker/scripts.py +0 -0
  83. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/firecracker/utils.py +0 -0
  84. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/hysn_firecracker_python.egg-info/dependency_links.txt +0 -0
  85. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/hysn_firecracker_python.egg-info/requires.txt +0 -0
  86. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/hysn_firecracker_python.egg-info/top_level.txt +0 -0
  87. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/requirements.txt +0 -0
  88. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/scripts/cleanup_resources.py +0 -0
  89. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/scripts/run-tests-docker.sh +0 -0
  90. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/setup.cfg +0 -0
  91. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/tests/test_api_client.py +0 -0
  92. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/tests/test_docker_integration.py +0 -0
  93. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/tests/test_error_handling.py +0 -0
  94. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/tests/test_logger.py +0 -0
  95. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/tests/test_microvm.py +0 -0
  96. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/tests/test_microvm_error_paths.py +0 -0
  97. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/tests/test_microvm_initialization.py +0 -0
  98. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/tests/test_networking.py +0 -0
  99. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/tests/test_port_forward.py +0 -0
  100. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/tests/test_rootfs_format.py +0 -0
  101. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/tests/test_scripts.py +0 -0
  102. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/tests/test_snapshots.py +0 -0
  103. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/tests/test_utils.py +0 -0
  104. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/tests/test_vm_configuration.py +0 -0
  105. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/tests/test_vmm_manager.py +0 -0
  106. {hysn_firecracker_python-1.0.7 → hysn_firecracker_python-1.0.8}/uv.lock +0 -0
@@ -26,7 +26,7 @@ Before working on this project, ensure you have:
26
26
  - **Python 3.9+** installed
27
27
  - **KVM** enabled on your system (`lsmod | grep kvm`)
28
28
  - **Docker** installed and running
29
- - **Firecracker** binary in `/usr/local/bin/firecracker` or `/usr/bin/firecracker`
29
+ - **Firecracker** binary in `/usr/local/bin/firecracker`
30
30
  - **python3-nftables** module installed
31
31
  - **uv** package manager (recommended) or pip
32
32
 
@@ -34,7 +34,7 @@ Before working on this project, ensure you have:
34
34
 
35
35
  ```bash
36
36
  # Clone the repository
37
- git clone https://github.com/myugan/firecracker-python.git
37
+ git clone https://github.com/hysnsec/firecracker-python.git
38
38
  cd firecracker-python
39
39
 
40
40
  # Using uv (recommended)
@@ -204,10 +204,8 @@ Coverage reports are generated in `htmlcov/` directory when running `make test-c
204
204
 
205
205
  ### Working with Firecracker
206
206
 
207
- 1. **Firecracker Binary Location**: The library looks for the Firecracker binary at:
208
- - `/usr/local/bin/firecracker`
209
- - `/usr/bin/firecracker`
210
-
207
+ 1. **Firecracker Binary Location**: The library starts the binary at `MicroVMConfig.binary_path`, which is `/usr/local/bin/firecracker`. It does not search other paths.
208
+
211
209
  Use `firecracker-check` to verify installation.
212
210
 
213
211
  2. **KVM Access**: Ensure KVM is enabled:
@@ -229,13 +227,16 @@ Coverage reports are generated in `htmlcov/` directory when running `make test-c
229
227
 
230
228
  The project supports building rootfs from Docker images:
231
229
 
232
- ```bash
233
- # Build rootfs from Docker image
234
- vm = MicroVM(image="ubuntu:24.04", base_rootfs="./rootfs.img")
230
+ ```python
231
+ # Build rootfs from Docker image (run as root), then create the VM
232
+ vm = MicroVM(image="my-rootfs:latest", base_rootfs="./rootfs.img", kernel_file="./vmlinux")
235
233
  vm.build()
234
+ vm.create()
236
235
  ```
237
236
 
238
- See [`FIRECRACKER_SETUP.md`](FIRECRACKER_SETUP.md) for detailed setup instructions.
237
+ - `create()` does not call `build()`. Call `build()` first.
238
+ - The image must contain an init system and an SSH server. See [`docs/rootfs.md`](docs/rootfs.md).
239
+ - For the official CI kernel and rootfs, see [`FIRECRACKER_SETUP.md`](FIRECRACKER_SETUP.md).
239
240
 
240
241
  ### Debugging
241
242
 
@@ -259,7 +260,7 @@ The default SSH user is `root`.
259
260
 
260
261
  ### Terminal Connection Timeout
261
262
 
262
- When spawning a terminal connection to microVMs, the default timeout is **1800000 milliseconds** (30 minutes). This timeout applies to SSH connections and can be configured when needed for long-running operations.
263
+ When you spawn a terminal connection to a microVM from an agent tool, use a timeout of **1800000 milliseconds** (30 minutes) for long-running operations. This is guidance for the tool call. The library itself sets no SSH connection timeout.
263
264
 
264
265
  ## Security Considerations
265
266
 
@@ -312,22 +313,31 @@ firecracker-python/
312
313
  │ ├── utils.py # Utility functions
313
314
  │ ├── exceptions.py # Custom exceptions
314
315
  │ └── scripts.py # CLI scripts
315
- ├── tests/ # Test suite
316
- │ ├── conftest.py # Pytest configuration
317
- │ └── test_microvm.py # MicroVM tests
318
- ├── docs/ # Documentation
316
+ ├── tests/ # Test suite (conftest.py + test_*.py, see tests/README.md)
317
+ ├── docs/ # Documentation (index: docs/README.md)
319
318
  │ ├── getting-started.md
319
+ │ ├── rootfs.md
320
320
  │ ├── api-reference.md
321
321
  │ ├── configuration.md
322
+ │ ├── network.md
323
+ │ ├── snapshots.md
324
+ │ ├── advanced.md
322
325
  │ ├── examples.md
323
- │ └── network.md
326
+ │ ├── cleanup.md
327
+ │ └── testing-in-docker.md
324
328
  ├── examples/ # Example scripts
329
+ │ ├── sample.py
325
330
  │ ├── create_vm.py
331
+ │ ├── create_vm_with_filesystem_format.py
326
332
  │ ├── configure_vm_network.py
327
333
  │ ├── load_snapshot.py
334
+ │ ├── init # Example init that runs MMDS user data
335
+ │ ├── setup.sh # Host setup for Ubuntu
328
336
  │ └── Dockerfile
337
+ ├── assets/rootfs/ # setup-firecracker-official.sh (CI kernel + rootfs)
329
338
  ├── scripts/ # Utility scripts
330
- │ └── run-tests-docker.sh
339
+ │ ├── run-tests-docker.sh
340
+ │ └── cleanup_resources.py # Used by make cleanup-firecracker (destructive)
331
341
  ├── pyproject.toml # Project configuration
332
342
  ├── setup.py # Setup script
333
343
  ├── requirements.txt # Python dependencies
@@ -409,16 +419,22 @@ See [`TODO.md`](TODO.md) for planned features:
409
419
  ```python
410
420
  from firecracker import MicroVM
411
421
 
412
- # Basic microVM
413
- vm = MicroVM()
422
+ KERNEL = "./firecracker-files/vmlinux"
423
+ ROOTFS = "./firecracker-files/rootfs.img"
424
+
425
+ # Basic microVM (kernel_file and base_rootfs are required)
426
+ vm = MicroVM(kernel_file=KERNEL, base_rootfs=ROOTFS)
414
427
  vm.create()
415
428
 
416
429
  # Custom configuration
417
- vm = MicroVM(vcpu=2, memory="4G")
430
+ vm = MicroVM(kernel_file=KERNEL, base_rootfs=ROOTFS, vcpu=2, memory="4G")
418
431
  vm.create()
419
432
 
420
433
  # With port forwarding
421
- vm = MicroVM(expose_ports=True, host_port=10222, dest_port=22)
434
+ vm = MicroVM(
435
+ kernel_file=KERNEL, base_rootfs=ROOTFS,
436
+ expose_ports=True, host_port=10222, dest_port=22,
437
+ )
422
438
  vm.create()
423
439
  ```
424
440
 
@@ -444,9 +460,9 @@ vm.connect(key_path="/path/to/ssh/key")
444
460
  # Create snapshot
445
461
  vm.snapshot(action="create")
446
462
 
447
- # Load snapshot
448
- vm = MicroVM(kernel_file="...", rootfs_path="...")
449
- vm.create(snapshot=True, memory_path="...", snapshot_path="...")
463
+ # Load snapshot (rootfs_path is a create() argument, not a constructor argument)
464
+ vm = MicroVM(kernel_file="...", base_rootfs="...", ip_addr="<source VM IP>")
465
+ vm.create(snapshot=True, memory_path="...", snapshot_path="...", rootfs_path="...")
450
466
  ```
451
467
 
452
468
  ## Troubleshooting
@@ -0,0 +1,89 @@
1
+ # Firecracker Kernel and Rootfs Setup
2
+
3
+ The script `assets/rootfs/setup-firecracker-official.sh` downloads a guest kernel and an Ubuntu rootfs from the official Firecracker CI bucket. It then prepares the rootfs so that you can log in over SSH as `root`.
4
+
5
+ Use this setup if you want a working kernel and rootfs pair quickly. To build a rootfs from your own Docker image instead, see [Build a rootfs from a Docker image](docs/rootfs.md).
6
+
7
+ ## Requirements
8
+
9
+ - Linux on x86_64 or aarch64
10
+ - `sudo` access
11
+ - `curl`, `wget`, GNU `grep` (the script uses `grep -P`), `unsquashfs` (from `squashfs-tools`), `ssh-keygen` and `mkfs.ext4`
12
+ - Network access to `github.com` and `s3.amazonaws.com`
13
+
14
+ ## Run the script
15
+
16
+ Run it from any directory. The script changes to the project root first.
17
+
18
+ ```bash
19
+ ./assets/rootfs/setup-firecracker-official.sh
20
+ ```
21
+
22
+ The script does these steps:
23
+
24
+ 1. Finds the latest Firecracker release and uses its CI version, for example `v1.12`.
25
+ 2. Downloads the newest guest kernel for that CI version and your CPU architecture.
26
+ 3. Downloads the newest Ubuntu squashfs rootfs for that CI version.
27
+ 4. Creates the SSH key `ssh_keys/ubuntu-22.04` if it does not exist, and adds its public key to `/root/.ssh/authorized_keys` in the rootfs.
28
+ 5. Installs `openssh-server` and a few network tools inside the rootfs with `chroot`, and allows key-based root login.
29
+ 6. Writes `nameserver 1.1.1.1` to `/etc/resolv.conf` in the rootfs.
30
+ 7. Packs the result into a 10 GB ext4 image.
31
+
32
+ ## Files the script creates
33
+
34
+ | File | Purpose |
35
+ |---|---|
36
+ | `firecracker-files/vmlinux` | Guest kernel |
37
+ | `firecracker-files/rootfs.img` | 10 GB ext4 root filesystem |
38
+ | `ssh_keys/ubuntu-22.04` | SSH private key for `root` |
39
+ | `ssh_keys/ubuntu-22.04.pub` | SSH public key |
40
+
41
+ The key is named `ubuntu-22.04` for historical reasons. The Ubuntu version inside the rootfs depends on what the Firecracker CI bucket provides.
42
+
43
+ If `firecracker-files/vmlinux` already exists, the script keeps it. It always rebuilds `rootfs.img`.
44
+
45
+ ## Enable IP forwarding
46
+
47
+ The microVM needs IP forwarding on the host to reach the internet:
48
+
49
+ ```bash
50
+ sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
51
+ sudo iptables -P FORWARD ACCEPT
52
+ ```
53
+
54
+ ## Use the files with firecracker-python
55
+
56
+ ```python
57
+ from firecracker import MicroVM
58
+
59
+ vm = MicroVM(
60
+ kernel_file="./firecracker-files/vmlinux",
61
+ base_rootfs="./firecracker-files/rootfs.img",
62
+ )
63
+ vm.create()
64
+
65
+ vm.connect(key_path="./ssh_keys/ubuntu-22.04")
66
+ ```
67
+
68
+ You can also run the sample script, which uses the same paths:
69
+
70
+ ```bash
71
+ ./examples/sample.py
72
+ ```
73
+
74
+ To check the files before you start a VM, run:
75
+
76
+ ```bash
77
+ python3 verify-setup.py
78
+ ```
79
+
80
+ ## Troubleshooting
81
+
82
+ - **Permission errors.** The script uses `sudo` for `chroot`, `mount` and `mkfs.ext4`. Run it as a user with `sudo` access.
83
+ - **The script stops after a failed command.** The script uses `set -e`. On exit, it unmounts the bind mounts it created under `firecracker-files/squashfs-root`.
84
+ - **SSH times out.** The first boot can take a minute. Check the VM log at `/var/lib/firecracker/<VM_ID>/logs/<VM_ID>.log`.
85
+
86
+ ## References
87
+
88
+ - [Firecracker getting started guide](https://github.com/firecracker-microvm/firecracker/blob/main/docs/getting-started.md)
89
+ - [firecracker-python getting started guide](docs/getting-started.md)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hysn-firecracker-python
3
- Version: 1.0.7
3
+ Version: 1.0.8
4
4
  Summary: A Python client library to interact with Firecracker microVMs
5
5
  Author: PDSO Platform
6
6
  License: MIT License
@@ -49,9 +49,9 @@ Dynamic: requires-python
49
49
 
50
50
  <p align="center">
51
51
  <a href="https://opensource.org/license/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg"></a>
52
- <a href="https://github.com/myugan/firecracker-python"><img src="https://img.shields.io/github/stars/myugan/firecracker-python.svg?style=social&label=Star"></a>
53
- <a href="https://github.com/myugan/firecracker-python"><img src="https://img.shields.io/github/forks/myugan/firecracker-python.svg?style=social&label=Fork"></a>
54
- <a href="https://github.com/myugan/firecracker-python"><img src="https://img.shields.io/github/watchers/myugan/firecracker-python.svg?style=social&label=Watch"></a>
52
+ <a href="https://github.com/hysnsec/firecracker-python"><img src="https://img.shields.io/github/stars/hysnsec/firecracker-python.svg?style=social&label=Star"></a>
53
+ <a href="https://github.com/hysnsec/firecracker-python"><img src="https://img.shields.io/github/forks/hysnsec/firecracker-python.svg?style=social&label=Fork"></a>
54
+ <a href="https://github.com/hysnsec/firecracker-python"><img src="https://img.shields.io/github/watchers/hysnsec/firecracker-python.svg?style=social&label=Watch"></a>
55
55
  </p>
56
56
 
57
57
  ![Firecracker](assets/img/firecracker.png)
@@ -68,21 +68,28 @@ Some features are still being developed and will be added in the future. You can
68
68
  - [Key Features](#key-features)
69
69
  - [Getting Started](#getting-started)
70
70
  - [Usage](#usage)
71
+ - [Documentation](#documentation)
71
72
  - [License](#license)
72
73
  - [Contributing](#contributing)
73
74
 
74
75
  ### How to Install
75
76
 
76
- To install from PyPI, you need to have a personal access token with read access to the repository.
77
+ Install the package from PyPI:
77
78
 
78
79
  ```bash
79
- pip3 install firecracker-python
80
+ pip3 install hysn-firecracker-python
80
81
  ```
81
82
 
82
- Or install from source, by cloning the repository and installing the package using pip:
83
+ The import name is `firecracker`:
84
+
85
+ ```python
86
+ from firecracker import MicroVM
87
+ ```
88
+
89
+ Or install from source:
83
90
 
84
91
  ```bash
85
- git clone https://github.com/myugan/firecracker-python.git
92
+ git clone https://github.com/hysnsec/firecracker-python.git
86
93
  cd firecracker-python
87
94
 
88
95
  # Using uv (recommended)
@@ -97,45 +104,49 @@ pip3 install -e .
97
104
 
98
105
  ### Key Features
99
106
 
100
- - Easily create microVMs with default or custom settings
101
- - View a list of all running microVMs
102
- - Access and modify microVM settings
103
- - Remove one or all microVMs
104
- - Connect to microVMs using SSH
105
- - Set up port forwarding in microVMs
107
+ - Create microVMs with custom vCPU, memory and network settings
108
+ - Build a rootfs image from a Docker image
109
+ - List, pause, resume and delete microVMs
110
+ - Connect to microVMs over SSH
111
+ - Forward host ports to microVMs
112
+ - Create and load snapshots
113
+ - Pass metadata and user data through MMDS
114
+ - Attach a vsock device
106
115
 
107
116
  ### Getting Started
108
117
 
109
118
  The easiest way to get started is to use the official Firecracker setup script:
110
119
 
111
120
  ```bash
112
- # Run the official setup script (downloads official CI kernel and rootfs)
121
+ # Download the official CI kernel and rootfs, and create an SSH key
113
122
  ./assets/rootfs/setup-firecracker-official.sh
114
123
 
115
124
  # Then run the sample script
116
125
  ./examples/sample.py
117
126
  ```
118
127
 
119
- This will:
120
- 1. Download the latest Firecracker kernel from official CI (tested with Ubuntu)
121
- 2. Download the official Ubuntu rootfs from Firecracker CI
122
- 3. Set up SSH keys for root access
123
- 4. Create a properly configured ext4 rootfs image
128
+ The setup script creates these files:
124
129
 
125
- The official setup uses Firecracker's CI kernel and rootfs which are **proven to work together**, avoiding kernel compatibility issues.
130
+ | File | Purpose |
131
+ |---|---|
132
+ | `firecracker-files/vmlinux` | Guest kernel |
133
+ | `firecracker-files/rootfs.img` | 10 GB ext4 rootfs with SSH enabled |
134
+ | `ssh_keys/ubuntu-22.04` | SSH private key for `root` |
126
135
 
127
- **Manual Setup (Alternative):**
136
+ The official setup uses Firecracker's CI kernel and rootfs, which are **tested together**. This avoids kernel compatibility issues. See [`FIRECRACKER_SETUP.md`](FIRECRACKER_SETUP.md) for details.
128
137
 
129
- If you prefer to build your own rootfs, see [`FIRECRACKER_SETUP.md`](FIRECRACKER_SETUP.md) for detailed instructions.
138
+ To build a rootfs from your own Docker image instead, see [Build a rootfs from a Docker image](docs/rootfs.md).
130
139
 
131
140
  #### Prerequisites
132
141
 
133
142
  Before running the setup script, ensure you have:
134
143
 
135
- - **Firecracker binary** installed at `/usr/local/bin/firecracker` or `/usr/bin/firecracker`
136
- - **KVM** enabled on your system: `lsmod | grep kvm`
137
- - **Docker** installed and running (for rootfs setup)
138
- - **Python 3.9+** installed
144
+ - **Linux** with **KVM** enabled: `lsmod | grep kvm`
145
+ - **Firecracker binary** installed at `/usr/local/bin/firecracker`
146
+ - **Docker** installed and running. The library connects to Docker every time you create a `MicroVM` object.
147
+ - **Python 3.9+**
148
+ - **python3-nftables** installed
149
+ - **root** access. The library creates TAP devices and nftables rules.
139
150
 
140
151
  #### Enable IP Forwarding
141
152
 
@@ -154,34 +165,33 @@ source .venv/bin/activate
154
165
  ./examples/sample.py
155
166
  ```
156
167
 
157
- The sample script includes:
158
- - Automatic IP conflict detection
159
- - VM creation with verified files
160
- - SSH connection capability
161
- - Cleanup instructions
168
+ The sample script:
169
+ - Picks a free subnet so the new VM does not conflict with running VMs
170
+ - Creates a VM with the files from the setup script
171
+ - Offers to open an SSH session
172
+ - Prints cleanup instructions
162
173
 
163
- To get started with **firecracker-python**, check out the [getting started guide](docs/getting-started.md)
174
+ For a full walkthrough, read the [getting started guide](docs/getting-started.md).
164
175
 
165
176
  ### Usage
166
177
 
167
- Here are some examples of how to use the library.
178
+ Every microVM needs a kernel (`kernel_file`) and a root filesystem (`base_rootfs`). The examples below use the files from the setup script.
168
179
 
169
180
  #### Create a microVM with custom configuration and list them all
170
181
 
171
182
  ```python
172
183
  from firecracker import MicroVM
173
184
 
174
- # Create a new microVM with custom configuration
175
- vm = MicroVM(vcpu=2, memory="4096")
176
- # Or
177
- vm = MicroVM(vcpu=2, memory="4G")
185
+ KERNEL = "./firecracker-files/vmlinux"
186
+ ROOTFS = "./firecracker-files/rootfs.img"
178
187
 
188
+ # Memory accepts MiB as a number, or a string such as "4G"
189
+ vm = MicroVM(kernel_file=KERNEL, base_rootfs=ROOTFS, vcpu=2, memory="4G")
179
190
  vm.create()
180
191
 
181
192
  # List all running microVMs
182
- vms = MicroVM.list() # Static method to list all VMs
183
- for vm in vms:
184
- print(f"VM with id {vm['id']} has IP {vm['ip_addr']} and is in state {vm['state']}")
193
+ for info in MicroVM.list():
194
+ print(f"VM {info['id']} has IP {info['ip_addr']} and is {info['state']}")
185
195
  ```
186
196
 
187
197
  #### Delete a microVM by id or all microVMs
@@ -189,20 +199,21 @@ for vm in vms:
189
199
  ```python
190
200
  from firecracker import MicroVM
191
201
 
192
- # Create a new microVM
193
- vm = MicroVM()
202
+ vm = MicroVM(kernel_file=KERNEL, base_rootfs=ROOTFS)
194
203
  vm.create()
195
204
 
196
205
  # Delete the microVM just created
197
206
  vm.delete()
198
207
 
199
208
  # Delete a specific microVM by ID
200
- vm.delete(id="<specific_id>")
209
+ MicroVM().delete(id="<specific_id>")
201
210
 
202
211
  # Delete all microVMs
203
- vm.delete(all=True)
212
+ MicroVM().delete(all=True)
204
213
  ```
205
214
 
215
+ `MicroVM()` without arguments is enough to manage VMs that already exist. You only need `kernel_file` and `base_rootfs` to create a new VM.
216
+
206
217
  #### Enable port forwarding
207
218
 
208
219
  During initialization:
@@ -211,9 +222,14 @@ During initialization:
211
222
  from firecracker import MicroVM
212
223
 
213
224
  # Single port
214
- vm = MicroVM(expose_ports=True, host_port=10222, dest_port=22)
215
- # Multiple ports
216
- # vm = MicroVM(expose_ports=True, host_port=[10222, 10280], dest_port=[22, 80])
225
+ vm = MicroVM(
226
+ kernel_file=KERNEL,
227
+ base_rootfs=ROOTFS,
228
+ expose_ports=True,
229
+ host_port=10222,
230
+ dest_port=22,
231
+ )
232
+ # Multiple ports: host_port=[10222, 10280], dest_port=[22, 80]
217
233
 
218
234
  vm.create()
219
235
  ```
@@ -221,25 +237,32 @@ vm.create()
221
237
  After creation you can also expose ports using the `port_forward` function:
222
238
 
223
239
  ```python
224
- from firecracker import MicroVM
225
-
226
- vm = MicroVM()
227
- vm.create()
228
-
229
240
  # Forward a single port
230
241
  vm.port_forward(host_port=10222, dest_port=22)
231
- # 'Port forwarding added successfully'
242
+ # 'Port forwarding added successfully for VMM <id>'
232
243
 
233
244
  # Forward multiple ports
234
245
  vm.port_forward(host_port=[10222, 10280], dest_port=[22, 80])
235
- # 'Port forwarding added successfully'
236
246
 
237
247
  # Remove port forwarding
238
248
  vm.port_forward(host_port=10222, dest_port=22, remove=True)
239
- # 'Port forwarding removed successfully'
249
+ # 'Port forwarding removed successfully for VMM <id>'
240
250
  ```
241
251
 
242
- > **Note:** When using port forwarding, you need to specify both `host_port` and `dest_port`. The number of host ports must match the number of destination ports.
252
+ > **Note:** When using port forwarding, you need to specify both `host_port` and `dest_port`. The number of host ports must match the number of destination ports. Port forwarding supports TCP only.
253
+
254
+ ### Documentation
255
+
256
+ - [Getting started](docs/getting-started.md)
257
+ - [Build a rootfs from a Docker image](docs/rootfs.md)
258
+ - [API reference](docs/api-reference.md)
259
+ - [Configuration](docs/configuration.md)
260
+ - [Network](docs/network.md)
261
+ - [Snapshots](docs/snapshots.md)
262
+ - [MMDS, vsock, overlayfs and initrd](docs/advanced.md)
263
+ - [Examples](docs/examples.md)
264
+ - [Cleanup](docs/cleanup.md)
265
+ - [Testing in Docker](docs/testing-in-docker.md)
243
266
 
244
267
  ### License
245
268
 
@@ -31,6 +31,14 @@ This script will:
31
31
  - Set up SSH keys for root access
32
32
  - Create a properly configured ext4 filesystem
33
33
 
34
+ It creates these files:
35
+
36
+ - `firecracker-files/vmlinux` (kernel)
37
+ - `firecracker-files/rootfs.img` (rootfs)
38
+ - `ssh_keys/ubuntu-22.04` (SSH private key)
39
+
40
+ See [FIRECRACKER_SETUP.md](FIRECRACKER_SETUP.md) for details.
41
+
34
42
  ## Enable Networking
35
43
 
36
44
  Enable IP forwarding for Firecracker VMs:
@@ -68,7 +76,7 @@ python3 verify-setup.py
68
76
  ```
69
77
 
70
78
  This will check:
71
- - Kernel file exists and is executable
79
+ - Kernel file exists and is readable
72
80
  - Rootfs image exists and is valid
73
81
  - SSH key files exist with correct permissions
74
82
  - System prerequisites (Firecracker, KVM, Docker, IP forwarding)
@@ -78,26 +86,15 @@ Check that your VM is running:
78
86
  ```bash
79
87
  # List all running VMs
80
88
  python3 -c "from firecracker import MicroVM; vms = MicroVM.list(); [print(f\"{v['id']}: {v['ip_addr']} ({v['state']})\") for v in vms]"
81
-
82
- # Check VM status
83
- ./examples/sample.py | grep "VM Status"
84
89
  ```
85
90
 
86
91
  ## Connect to VM
87
92
 
88
- The sample script will provide instructions, or you can connect directly:
93
+ The sample script asks if you want to connect. Answer `y` to open an SSH session.
89
94
 
90
- ```bash
91
- # Using the sample script (automatic SSH connection)
92
- ./examples/sample.py
93
- # Answer 'y' when prompted to connect
94
-
95
- # Or connect manually using the SSH key
96
- # Note: The key could be at either location depending on setup:
97
- # - ssh_keys/ubuntu-22.04 (if key generated fresh)
98
- # - firecracker-files/ubuntu-22.04.id_rsa (if moved by setup script)
99
- # Both have the same private key
95
+ To connect yourself, use the key that the setup script created:
100
96
 
97
+ ```bash
101
98
  ssh -i ./ssh_keys/ubuntu-22.04 root@<VM_IP_ADDRESS>
102
99
  ```
103
100