Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions firecracker/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
from typing_extensions import Annotated

import typer
from rich import print
from rich.console import Console
from rich.table import Table
from firecracker import MicroVM

app = typer.Typer()
console = Console()


@app.command()
def create(
name: Annotated[str, typer.Option()] = None,
kernel_file: Annotated[str, typer.Option()] = None,
base_rootfs: Annotated[str, typer.Option()] = None,
rootfs_url: Annotated[str, typer.Option()] = None,
vcpu: Annotated[int, typer.Option()] = 2,
mem_size_mib: Annotated[int, typer.Option()] = 1024,
ip_addr: Annotated[str, typer.Option()] = None,
bridge: Annotated[bool, typer.Option()] = False,
bridge_name: Annotated[str, typer.Option()] = None,
mmds_enabled: Annotated[bool, typer.Option()] = False,
mmds_ip: Annotated[str, typer.Option()] = None,
# labels: Annotated[dict, typer.Option()],
working_dir: Annotated[str, typer.Option()] = None,
expose_ports: Annotated[bool, typer.Option()] = False,
host_port: Annotated[int, typer.Option()] = None,
dest_port: Annotated[int, typer.Option()] = None,
verbose: Annotated[bool, typer.Option()] = False,
):
MicroVM(
name=name,
kernel_file=kernel_file,
base_rootfs=base_rootfs,
rootfs_url=rootfs_url,
vcpu=vcpu,
mem_size_mib=mem_size_mib,
ip_addr=ip_addr,
bridge=bridge,
bridge_name=bridge_name,
mmds_enabled=mmds_enabled,
mmds_ip=mmds_ip,
# labels=labels,
working_dir=working_dir,
expose_ports=expose_ports,
host_port=host_port,
dest_port=dest_port,
verbose=verbose,
).create()


@app.command()
def rm(id: Annotated[str, typer.Argument()]):
MicroVM().delete(id=id)


@app.command()
def resume(id: Annotated[str, typer.Argument()]):
MicroVM().resume(id=id)


@app.command()
def pause(id: Annotated[str, typer.Argument()]):
MicroVM().pause(id=id)


@app.command()
def inspect(id: Annotated[str, typer.Argument()]):
print(MicroVM().inspect(id=id))


@app.command()
def ps():
table = Table("MicroVM ID", "STATUS", "IP", "PID", "NAMES")
for vm in MicroVM.list():
table.add_row(vm["id"], vm["state"], vm["ip_addr"], str(vm["pid"]), vm["name"])

console.print(table)


@app.command()
def version():
print("Firecracker version")


def main() -> None:
app()
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ description = "A Python client library to interact with Firecracker microVMs"
authors = [
{name = "Muhammad Yuga Nugraha"}
]
requires-python = ">=3.8"
requires-python = ">=3.9"
dependencies = [
"requests==2.32.3",
"requests-unixsocket==0.4.1",
"tenacity==9.0.0",
"psutil==7.0.0",
"pyroute2==0.8.1",
"paramiko==3.5.1",
"faker==37.0.2"
"faker==37.0.2",
"typer>=0.15.2",
"rich>=14.0.0",
]
license = {file = "LICENSE"}
readme = "README.md"
Expand All @@ -32,6 +34,7 @@ classifiers = [
]

[project.scripts]
pyfirecracker = "firecracker.cli:main"
firecracker-check = "firecracker.scripts:check_firecracker_binary"

[tool.setuptools_scm]
Expand Down