Unverified Commit 53ce4f40 authored by Jakob Görgen's avatar Jakob Görgen
Browse files

symphony/cli: removed runner id from settings

parent 4e4f0ea8
...@@ -35,6 +35,7 @@ from simbricks.cli.commands import ( ...@@ -35,6 +35,7 @@ from simbricks.cli.commands import (
runners, runners,
) )
from simbricks.client.provider import client_provider from simbricks.client.provider import client_provider
from simbricks.client.settings import client_settings
from simbricks.cli.utils import async_cli from simbricks.cli.utils import async_cli
app = Typer() app = Typer()
...@@ -53,11 +54,9 @@ app.add_typer(rg.app, name="rg") ...@@ -53,11 +54,9 @@ app.add_typer(rg.app, name="rg")
@app.callback() @app.callback()
@async_cli() @async_cli()
async def amain( async def amain(
ns: Annotated[str, Option(help="Namespace to operate in.")] = "foo/bar/baz", ns: Annotated[str, Option(help="Namespace to operate in.")] = client_settings().namespace,
runner_ident: Annotated[int, Option(help="Runner ident to operate on.")] = -1,
): ):
client_provider.namespace = ns client_provider.namespace = ns
client_provider.runner_id = runner_ident
def main(): def main():
......
from typer import Typer, Option from typer import Typer, Option
from typing import Annotated from typing import Annotated
from simbricks.client.provider import client_provider from simbricks.client.provider import client_provider
from simbricks.client.settings import client_settings
from ..utils import async_cli, print_table_generic from ..utils import async_cli, print_table_generic
app = Typer(help="Managing SimBricks organizations.") app = Typer(help="Managing SimBricks organizations.")
organization = '' organization = ""
@app.callback() @app.callback()
@async_cli() @async_cli()
async def amain( async def amain(
org: Annotated[str, Option(help="Organization to operate in.")] = "SimBricks", org: Annotated[str, Option(help="Organization to operate in.")] = client_settings().organization,
): ):
global organization global organization
organization = org organization = org
@app.command() @app.command()
@async_cli() @async_cli()
async def members(): async def members():
"""List organization members.""" """List organization members."""
members = await client_provider.org_client.get_members(organization) members = await client_provider.org_client.get_members(organization)
print_table_generic( print_table_generic("Members", members, "username", "first_name", "last_name")
"Members", members, "username", "first_name", "last_name"
)
@app.command() @app.command()
......
...@@ -27,7 +27,7 @@ from ..utils import async_cli, print_table_generic ...@@ -27,7 +27,7 @@ from ..utils import async_cli, print_table_generic
app = Typer( app = Typer(
help="Managing SimBricks runners. (NOTE: some commands like listing events are relative to a specific runner. To use them properly use either the simbricks-cli commands --runner-ident parameter or a environment variable.)" help="Managing SimBricks runners."
) )
...@@ -35,61 +35,74 @@ app = Typer( ...@@ -35,61 +35,74 @@ app = Typer(
@async_cli() @async_cli()
async def ls(): async def ls():
"""List runners.""" """List runners."""
runners = await client_provider.runner_client.list_runners() runners = await client_provider.runner_client(-1).list_runners()
print_table_generic("Runners", runners, "id", "label", "tags", "namespace_id", "resource_group_id") print_table_generic(
"Runners", runners, "id", "label", "tags", "namespace_id", "resource_group_id"
)
@app.command() @app.command()
@async_cli() @async_cli()
async def show(runner_id: int): async def show(runner_id: int):
"""Show individual runner.""" """Show individual runner."""
runner = await client_provider.runner_client.get_runner(runner_id=runner_id) runner = await client_provider.runner_client(runner_id).get_runner()
print_table_generic("Runners", [runner], "id", "label", "tags", "namespace_id", "resource_group_id") print_table_generic(
"Runners", [runner], "id", "label", "tags", "namespace_id", "resource_group_id"
)
@app.command() @app.command()
@async_cli() @async_cli()
async def delete(runner_id: int): async def delete(runner_id: int):
"""Delete an individual runner.""" """Delete an individual runner."""
await client_provider.runner_client.delete_runner(runner_id=runner_id) await client_provider.runner_client(runner_id).delete_runner()
@app.command() @app.command()
@async_cli() @async_cli()
async def create(resource_group_id: int, label: str, tags: list[str]): async def create(resource_group_id: int, label: str, tags: list[str]):
"""Update a runner with the the given label and tags.""" """Update a runner with the the given label and tags."""
runner = await client_provider.runner_client.create_runner( runner = await client_provider.runner_client(-1).create_runner(
resource_group_id=resource_group_id, label=label, tags=tags resource_group_id=resource_group_id, label=label, tags=tags
) )
print_table_generic("Runner", [runner], "id", "label", "tags", "namespace_id", "resource_group_id") print_table_generic(
"Runner", [runner], "id", "label", "tags", "namespace_id", "resource_group_id"
)
@app.command() @app.command()
@async_cli() @async_cli()
async def create_event( async def create_event(
runner_id: int,
action: str, action: str,
run_id: Annotated[int | None, Option("--run", "-r", help="Set event for specific run.")] = None, run_id: Annotated[int | None, Option("--run", "-r", help="Set event for specific run.")] = None,
): ):
"""Send a run related event to a runner (Available actions: kill (reuires a run id that shall be killed), heartbeat, simulation_status).""" """Send a run related event to a runner (Available actions: kill (reuires a run id that shall be killed), heartbeat, simulation_status)."""
if action == "kill" and not run_id: if action == "kill" and not run_id:
raise Exception("when trying to create a kill action you must specify a run id") raise Exception("when trying to create a kill action you must specify a run id")
event = await client_provider.runner_client.create_runner_event(action=action, run_id=run_id) event = await client_provider.runner_client(runner_id).create_runner_event(
action=action, run_id=run_id
)
print_table_generic("Event", [event], "id", "runner_id", "action", "run_id", "event_status") print_table_generic("Event", [event], "id", "runner_id", "action", "run_id", "event_status")
@app.command() @app.command()
@async_cli() @async_cli()
async def delete_event(event_id: int): async def delete_event(runner_id: int, event_id: int):
"""Delete a runner event.""" """Delete a runner event."""
await client_provider.runner_client.delete_runner_event(event_id=event_id) await client_provider.runner_client(runner_id).delete_runner_event(event_id=event_id)
@app.command() @app.command()
@async_cli() @async_cli()
async def update_event( async def update_event(
event_id: int, event_id: int,
runner_id: int,
action: Annotated[ action: Annotated[
str | None, Option("--action", "-a", help="Action to set (kill, heartbeat, simulation_status, start_run).") str | None,
Option(
"--action", "-a", help="Action to set (kill, heartbeat, simulation_status, start_run)."
),
] = None, ] = None,
event_status: Annotated[ event_status: Annotated[
str | None, Option("--status", "-s", help="Status to set (pending, completed, cancelled).") str | None, Option("--status", "-s", help="Status to set (pending, completed, cancelled).")
...@@ -97,7 +110,7 @@ async def update_event( ...@@ -97,7 +110,7 @@ async def update_event(
run_id: Annotated[int | None, Option("--run", "-r", help="Run to set.")] = None, run_id: Annotated[int | None, Option("--run", "-r", help="Run to set.")] = None,
): ):
"""Update a runner event.""" """Update a runner event."""
event = await client_provider.runner_client.update_runner_event( event = await client_provider.runner_client(runner_id).update_runner_event(
event_id=event_id, action=action, event_status=event_status, run_id=run_id event_id=event_id, action=action, event_status=event_status, run_id=run_id
) )
print_table_generic("Event", [event], "id", "runner_id", "action", "run_id", "event_status") print_table_generic("Event", [event], "id", "runner_id", "action", "run_id", "event_status")
...@@ -106,13 +119,14 @@ async def update_event( ...@@ -106,13 +119,14 @@ async def update_event(
@app.command() @app.command()
@async_cli() @async_cli()
async def ls_events( async def ls_events(
runner_id: int,
action: Annotated[str | None, Option("--action", "-a", help="Filter for action.")] = None, action: Annotated[str | None, Option("--action", "-a", help="Filter for action.")] = None,
event_status: Annotated[str | None, Option("--status", "-s", help="Filter for status.")] = None, event_status: Annotated[str | None, Option("--status", "-s", help="Filter for status.")] = None,
run_id: Annotated[int | None, Option("--run", "-r", help="Filter for run.")] = None, run_id: Annotated[int | None, Option("--run", "-r", help="Filter for run.")] = None,
limit: Annotated[int | None, Option("--limit", "-l", help="Limit results.")] = None, limit: Annotated[int | None, Option("--limit", "-l", help="Limit results.")] = None,
): ):
"""List runner related events""" """List runner related events"""
events = await client_provider.runner_client.get_events( events = await client_provider.runner_client(runner_id).get_events(
action=action, run_id=run_id, event_status=event_status, limit=limit action=action, run_id=run_id, event_status=event_status, limit=limit
) )
print_table_generic("Events", events, "id", "runner_id", "action", "run_id", "event_status") print_table_generic("Events", events, "id", "runner_id", "action", "run_id", "event_status")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment