Skip to content
Merged
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
7 changes: 7 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@
packages=find_packages("src"),
package_dir={"": "src"},
python_requires=">=3.7",
entry_points={
'console_scripts': [
'firebolt=firebolt.cli:run',
'fb=firebolt.cli:run',
],
},
install_requires=[
"httpx[http2]==0.18",
"python-dotenv",
"pydantic",
"typer",
"toolz",
],
extras_require={
Expand Down
45 changes: 45 additions & 0 deletions src/firebolt/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import json

import typer

from .firebolt_client import FireboltClient
from .model.engine import Engine

app = typer.Typer()

ENGINE_OPERATIONS = ["start", "stop", "restart"]
READ_COMMANDS = ["ls", "list", "read"]
DELETE_COMMANDS = ["delete", "destroy"]
CREATE_COMMANDS = ["create"]


def run():
with FireboltClient.from_env() as _:
app()


@app.command()
def engine(action: str, name: str = None):
if action in READ_COMMANDS:
if name:
eng = Engine.get_by_name(name)
typer.echo(eng.json())
else:
engines = Engine.list_engines()
typer.echo(json.dumps(engines))
elif action in CREATE_COMMANDS:
pass
elif action in DELETE_COMMANDS:
eng = Engine.get_by_name(name)
eng.delete()
typer.secho(f"Engine: {name} was deleted", fg=typer.colors.RED)
elif action in ENGINE_OPERATIONS:
eng = Engine.get_by_name(name)
getattr(eng, action)()
else:
raise Exception(f"Engine command: {action} not supported")


# @app.command()
# def database(action: str, name: str = None):
# pass
14 changes: 14 additions & 0 deletions src/firebolt/model/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ def get_by_name(cls, engine_name: str):
engine_id = response.json()["engine_id"]["engine_id"]
return cls.get_by_id(engine_id=engine_id)

@classmethod
def list_engines(cls):
fc = cls.get_firebolt_client()
response = fc.http_client.get(
url=f"/core/v1/accounts/{fc.account_id}/engines",
)
return response.json()

def delete(self):
response = self.firebolt_client.http_client.delete(
url=f"/core/v1/accounts/{self.firebolt_client.account_id}/engines/{self.engine_id}",
)
return response.json()

@classmethod
def create_analytics(cls):
pass
Expand Down