hysn-firecracker-python 1.0.3.post0__py3-none-any.whl
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.
- firecracker/__init__.py +23 -0
- firecracker/_version.py +34 -0
- firecracker/api.py +183 -0
- firecracker/config.py +30 -0
- firecracker/exceptions.py +33 -0
- firecracker/logger.py +98 -0
- firecracker/microvm.py +1738 -0
- firecracker/network.py +1230 -0
- firecracker/process.py +438 -0
- firecracker/scripts.py +53 -0
- firecracker/utils.py +192 -0
- firecracker/vmm.py +508 -0
- hysn_firecracker_python-1.0.3.post0.dist-info/METADATA +246 -0
- hysn_firecracker_python-1.0.3.post0.dist-info/RECORD +18 -0
- hysn_firecracker_python-1.0.3.post0.dist-info/WHEEL +5 -0
- hysn_firecracker_python-1.0.3.post0.dist-info/entry_points.txt +2 -0
- hysn_firecracker_python-1.0.3.post0.dist-info/licenses/LICENSE +21 -0
- hysn_firecracker_python-1.0.3.post0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hysn-firecracker-python
|
|
3
|
+
Version: 1.0.3.post0
|
|
4
|
+
Summary: A Python client library to interact with Firecracker microVMs
|
|
5
|
+
Author: Muhammad Yuga Nugraha
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2024 Practical DevSecOps
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
Classifier: Development Status :: 3 - Alpha
|
|
28
|
+
Classifier: Intended Audience :: Developers
|
|
29
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
30
|
+
Classifier: Programming Language :: Python :: 3
|
|
31
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
32
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
33
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
34
|
+
Requires-Python: >=3.8
|
|
35
|
+
Description-Content-Type: text/markdown
|
|
36
|
+
License-File: LICENSE
|
|
37
|
+
Requires-Dist: docker==7.1.0
|
|
38
|
+
Requires-Dist: pyroute2==0.8.1
|
|
39
|
+
Requires-Dist: paramiko==3.5.1
|
|
40
|
+
Requires-Dist: faker==37.9.0
|
|
41
|
+
Dynamic: license-file
|
|
42
|
+
Dynamic: requires-python
|
|
43
|
+
|
|
44
|
+
# firecracker-python
|
|
45
|
+
|
|
46
|
+
<p align="center">
|
|
47
|
+
<a href="https://opensource.org/license/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg"></a>
|
|
48
|
+
<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>
|
|
49
|
+
<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>
|
|
50
|
+
<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>
|
|
51
|
+
</p>
|
|
52
|
+
|
|
53
|
+

|
|
54
|
+
|
|
55
|
+
**firecracker-python** is a simple Python library that makes it easy to manage Firecracker microVMs. It provides a simple way to create, configure, and manage microVMs.
|
|
56
|
+
|
|
57
|
+
Some features are still being developed and will be added in the future. You can track these in the [TODO.md](TODO.md) file.
|
|
58
|
+
|
|
59
|
+
[](https://asciinema.org/a/725316)
|
|
60
|
+
|
|
61
|
+
## Table of Contents
|
|
62
|
+
|
|
63
|
+
- [How to Install](#how-to-install)
|
|
64
|
+
- [Key Features](#key-features)
|
|
65
|
+
- [Getting Started](#getting-started)
|
|
66
|
+
- [Usage](#usage)
|
|
67
|
+
- [License](#license)
|
|
68
|
+
- [Contributing](#contributing)
|
|
69
|
+
|
|
70
|
+
### How to Install
|
|
71
|
+
|
|
72
|
+
To install from PyPI, you need to have a personal access token with read access to the repository.
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
pip3 install firecracker-python
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Or install from source, by cloning the repository and installing the package using pip:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
git clone https://github.com/myugan/firecracker-python.git
|
|
82
|
+
cd firecracker-python
|
|
83
|
+
|
|
84
|
+
# Using uv (recommended)
|
|
85
|
+
uv sync --dev
|
|
86
|
+
|
|
87
|
+
# Or using pip
|
|
88
|
+
python3 -m venv venv
|
|
89
|
+
source venv/bin/activate
|
|
90
|
+
pip3 install -r requirements.txt
|
|
91
|
+
pip3 install -e .
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Key Features
|
|
95
|
+
|
|
96
|
+
- Easily create microVMs with default or custom settings
|
|
97
|
+
- View a list of all running microVMs
|
|
98
|
+
- Access and modify microVM settings
|
|
99
|
+
- Remove one or all microVMs
|
|
100
|
+
- Connect to microVMs using SSH
|
|
101
|
+
- Set up port forwarding in microVMs
|
|
102
|
+
|
|
103
|
+
### Getting Started
|
|
104
|
+
|
|
105
|
+
The easiest way to get started is to use the official Firecracker setup script:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
# Run the official setup script (downloads official CI kernel and rootfs)
|
|
109
|
+
./assets/rootfs/setup-firecracker-official.sh
|
|
110
|
+
|
|
111
|
+
# Then run the sample script
|
|
112
|
+
./examples/sample.py
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
This will:
|
|
116
|
+
1. Download the latest Firecracker kernel from official CI (tested with Ubuntu)
|
|
117
|
+
2. Download the official Ubuntu rootfs from Firecracker CI
|
|
118
|
+
3. Set up SSH keys for root access
|
|
119
|
+
4. Create a properly configured ext4 rootfs image
|
|
120
|
+
|
|
121
|
+
The official setup uses Firecracker's CI kernel and rootfs which are **proven to work together**, avoiding kernel compatibility issues.
|
|
122
|
+
|
|
123
|
+
**Manual Setup (Alternative):**
|
|
124
|
+
|
|
125
|
+
If you prefer to build your own rootfs, see [`FIRECRACKER_SETUP.md`](FIRECRACKER_SETUP.md) for detailed instructions.
|
|
126
|
+
|
|
127
|
+
#### Prerequisites
|
|
128
|
+
|
|
129
|
+
Before running the setup script, ensure you have:
|
|
130
|
+
|
|
131
|
+
- **Firecracker binary** installed at `/usr/local/bin/firecracker` or `/usr/bin/firecracker`
|
|
132
|
+
- **KVM** enabled on your system: `lsmod | grep kvm`
|
|
133
|
+
- **Docker** installed and running (for rootfs setup)
|
|
134
|
+
- **Python 3.9+** installed
|
|
135
|
+
|
|
136
|
+
#### Enable IP Forwarding
|
|
137
|
+
|
|
138
|
+
To enable networking for Firecracker VMs, run:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
|
|
142
|
+
sudo iptables -P FORWARD ACCEPT
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
#### Quick Start Example
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
# Activate virtual environment and run sample
|
|
149
|
+
source .venv/bin/activate
|
|
150
|
+
./examples/sample.py
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
The sample script includes:
|
|
154
|
+
- Automatic IP conflict detection
|
|
155
|
+
- VM creation with verified files
|
|
156
|
+
- SSH connection capability
|
|
157
|
+
- Cleanup instructions
|
|
158
|
+
|
|
159
|
+
To get started with **firecracker-python**, check out the [getting started guide](docs/getting-started.md)
|
|
160
|
+
|
|
161
|
+
### Usage
|
|
162
|
+
|
|
163
|
+
Here are some examples of how to use the library.
|
|
164
|
+
|
|
165
|
+
#### Create a microVM with custom configuration and list them all
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
from firecracker import MicroVM
|
|
169
|
+
|
|
170
|
+
# Create a new microVM with custom configuration
|
|
171
|
+
vm = MicroVM(vcpu=2, memory="4096")
|
|
172
|
+
# Or
|
|
173
|
+
vm = MicroVM(vcpu=2, memory="4G")
|
|
174
|
+
|
|
175
|
+
vm.create()
|
|
176
|
+
|
|
177
|
+
# List all running microVMs
|
|
178
|
+
vms = MicroVM.list() # Static method to list all VMs
|
|
179
|
+
for vm in vms:
|
|
180
|
+
print(f"VM with id {vm['id']} has IP {vm['ip_addr']} and is in state {vm['state']}")
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
#### Delete a microVM by id or all microVMs
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
from firecracker import MicroVM
|
|
187
|
+
|
|
188
|
+
# Create a new microVM
|
|
189
|
+
vm = MicroVM()
|
|
190
|
+
vm.create()
|
|
191
|
+
|
|
192
|
+
# Delete the microVM just created
|
|
193
|
+
vm.delete()
|
|
194
|
+
|
|
195
|
+
# Delete a specific microVM by ID
|
|
196
|
+
vm.delete(id="<specific_id>")
|
|
197
|
+
|
|
198
|
+
# Delete all microVMs
|
|
199
|
+
vm.delete(all=True)
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
#### Enable port forwarding
|
|
203
|
+
|
|
204
|
+
During initialization:
|
|
205
|
+
|
|
206
|
+
```python
|
|
207
|
+
from firecracker import MicroVM
|
|
208
|
+
|
|
209
|
+
# Single port
|
|
210
|
+
vm = MicroVM(expose_ports=True, host_port=10222, dest_port=22)
|
|
211
|
+
# Multiple ports
|
|
212
|
+
# vm = MicroVM(expose_ports=True, host_port=[10222, 10280], dest_port=[22, 80])
|
|
213
|
+
|
|
214
|
+
vm.create()
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
After creation you can also expose ports using the `port_forward` function:
|
|
218
|
+
|
|
219
|
+
```python
|
|
220
|
+
from firecracker import MicroVM
|
|
221
|
+
|
|
222
|
+
vm = MicroVM()
|
|
223
|
+
vm.create()
|
|
224
|
+
|
|
225
|
+
# Forward a single port
|
|
226
|
+
vm.port_forward(host_port=10222, dest_port=22)
|
|
227
|
+
# 'Port forwarding added successfully'
|
|
228
|
+
|
|
229
|
+
# Forward multiple ports
|
|
230
|
+
vm.port_forward(host_port=[10222, 10280], dest_port=[22, 80])
|
|
231
|
+
# 'Port forwarding added successfully'
|
|
232
|
+
|
|
233
|
+
# Remove port forwarding
|
|
234
|
+
vm.port_forward(host_port=10222, dest_port=22, remove=True)
|
|
235
|
+
# 'Port forwarding removed successfully'
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
> **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.
|
|
239
|
+
|
|
240
|
+
### License
|
|
241
|
+
|
|
242
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
|
243
|
+
|
|
244
|
+
### Contributing
|
|
245
|
+
|
|
246
|
+
Contributions are welcome! Please open an issue or submit a Pull Request (PR).
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
firecracker/__init__.py,sha256=tVrFN8DTus2ECu5REZWaaHc-ssuU84TFU4Csq9Oa_cY,444
|
|
2
|
+
firecracker/_version.py,sha256=YvlepUiKrcq1HdxigGnv1IA16ttnJCqVWrXBKQKICDA,727
|
|
3
|
+
firecracker/api.py,sha256=tom62ct8qTO2-HjsoA2BtuQfCZd7hnVOE9XvAYHG9fI,6358
|
|
4
|
+
firecracker/config.py,sha256=8i_ILfzG1DjFGHIFvx_Sm7Z_-pM6WSe4_QVw-xRpS_E,858
|
|
5
|
+
firecracker/exceptions.py,sha256=eP_pvSjTiwbzOXytx6NcMHjrH-DswalDGCIPSCfGyH8,686
|
|
6
|
+
firecracker/logger.py,sha256=Dapmrl4rOaIlV4hTjXJEbfzgXYNnJ2vXt8Xmv9dS9ek,3034
|
|
7
|
+
firecracker/microvm.py,sha256=4Fm2jy1S8ZYiqiOOzjNQix4Vlv6byCLIBqwDBBbKRZM,67553
|
|
8
|
+
firecracker/network.py,sha256=-wstjy_0ZMhmfFzcmh2FTfQX3FYlGPmZ_nTys4I6D1U,46486
|
|
9
|
+
firecracker/process.py,sha256=eIa98O4g5HFQZaZNyG-NbAPwLg1EC3-XKIsedr-pea4,15798
|
|
10
|
+
firecracker/scripts.py,sha256=-5qN1S5nTEyOZnQ3OZKh5E3zmdcfjmBJHdJx3ztzjwE,1715
|
|
11
|
+
firecracker/utils.py,sha256=PATNnvxaThEfBW4OZUVcPQdGD_nbfra9CaYKVeWTiRo,5456
|
|
12
|
+
firecracker/vmm.py,sha256=M9ggvFTflSFYJte4meQADxyl8vNBvjWBTu6gc4XdS3E,16812
|
|
13
|
+
hysn_firecracker_python-1.0.3.post0.dist-info/licenses/LICENSE,sha256=NIYXDmhVsJ3HLDnHQmMrCN504brUDG7_GQAA7u0RJek,1075
|
|
14
|
+
hysn_firecracker_python-1.0.3.post0.dist-info/METADATA,sha256=SFM8qYO86KBFzqRM3TUl4Pa1BqG2_YP9OGFN__wYSfM,7675
|
|
15
|
+
hysn_firecracker_python-1.0.3.post0.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
|
|
16
|
+
hysn_firecracker_python-1.0.3.post0.dist-info/entry_points.txt,sha256=T7TXm3t_0Of1La6E2f8lQGaUD8i7IYdQHkqlKgCdtc0,83
|
|
17
|
+
hysn_firecracker_python-1.0.3.post0.dist-info/top_level.txt,sha256=w30yvfbEl4GrqkeROCQP1HA-NqnfClaD2obrPT0i7t4,12
|
|
18
|
+
hysn_firecracker_python-1.0.3.post0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Practical DevSecOps
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
firecracker
|