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

symphony/cli: added runners cli sub-command

parent b1a2af0c
......@@ -22,7 +22,7 @@
from typer import Typer, Option
from typing_extensions import Annotated
from simbricks.cli.commands import audit, admin, namespaces, runs, systems, simulations, instantiations
from simbricks.cli.commands import audit, admin, namespaces, runs, systems, simulations, instantiations, runners
from simbricks.cli.state import state
from simbricks.cli.utils import async_cli
......@@ -34,6 +34,7 @@ app.add_typer(admin.app, name="admin")
app.add_typer(systems.app, name="systems")
app.add_typer(simulations.app, name="sims")
app.add_typer(instantiations.app, name="insts")
app.add_typer(runners.app, name="runners")
@app.callback()
......
# Copyright 2024 Max Planck Institute for Software Systems, and
# National University of Singapore
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from typer import Typer
from ..state import state
from ..utils import async_cli, print_runner_table
app = Typer(help="Managing SimBricks runners.")
@app.command()
@async_cli()
async def ls():
"""List runners."""
runs = await state.runner_client.list_runners()
print_runner_table(runs)
@app.command()
@async_cli()
async def show(runner_id: int):
"""Show individual runner."""
runner = await state.runner_client.get_runner(runner_id=runner_id)
print_runner_table([runner])
@app.command()
@async_cli()
async def delete(runner_id: int):
"""Delete an individual runner."""
await state.runner_client.delete_runner(runner_id=runner_id)
@app.command()
@async_cli()
async def create(label: str, tags: list[str]):
"""Update a runner with the the given label and tags."""
runner = await state.runner_client.create_runner(label=label, tags=tags)
print_runner_table([runner])
......@@ -21,7 +21,7 @@
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import os
from simbricks.client import BaseClient, AdminClient, NSClient, SimBricksClient
from simbricks.client import BaseClient, AdminClient, NSClient, SimBricksClient, RunnerClient
class State:
......@@ -31,6 +31,7 @@ class State:
self._admin_client: AdminClient = None
self._ns_client: NSClient | None = None
self._simbricks_client: SimBricksClient | None = None
self._runner_client: RunnerClient | None = None
@property
def base_client(self):
......@@ -56,5 +57,11 @@ class State:
self._simbricks_client = SimBricksClient(self.ns_client)
return self._simbricks_client
@property
def runner_client(self):
if self._runner_client is None:
self._runner_client = RunnerClient(self.ns_client, id=-1)
return self._runner_client
state = State()
......@@ -74,6 +74,7 @@ def print_simulations_table(instantiations):
console = Console()
console.print(table)
def print_instantiations_table(instantiations):
table = Table()
table.add_column("Id")
......@@ -83,3 +84,18 @@ def print_instantiations_table(instantiations):
console = Console()
console.print(table)
def print_runner_table(runners):
table = Table()
table.add_column("Id")
table.add_column("Label")
table.add_column("Tags")
for r in runners:
ts = []
for t in r["tags"]:
ts.append(t["label"])
table.add_row(str(r["id"]), str(r["label"]), ",".join(ts))
console = Console()
console.print(table)
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