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

symphony/cli: added commands to show and delete systems + simulations

parent e87e6bbc
......@@ -22,7 +22,7 @@
from typer import Typer, Option
from typing_extensions import Annotated
from simbricks.cli.commands import audit, admin, namespaces, runs
from simbricks.cli.commands import audit, admin, namespaces, runs, systems, simulations
from simbricks.cli.state import state
from simbricks.cli.utils import async_cli
......@@ -31,6 +31,8 @@ app.add_typer(namespaces.app, name="ns")
app.add_typer(runs.app, name="runs")
app.add_typer(audit.app, name="audit")
app.add_typer(admin.app, name="admin")
app.add_typer(systems.app, name="systems")
app.add_typer(simulations.app, name="sims")
@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
from ..utils import print_simulations_table
app = Typer(help="Managing SimBricks Simulations.")
@app.command()
@async_cli()
async def ls():
"""List Simulations."""
simulations = await state.simbricks_client.get_simulations()
print_simulations_table(simulations)
@app.command()
@async_cli()
async def show(sim_id: int):
"""Show individual Simulation."""
sim = await state.simbricks_client.get_simulation(simulation_id=sim_id)
print_simulations_table([sim])
@app.command()
@async_cli()
async def delete(sim_id: int):
"""Delete an individual SImulation."""
client = state.simbricks_client
await client.delete_simulation(sim_id=sim_id)
# 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
from ..utils import print_systems_table
app = Typer(help="Managing SimBricks Systems.")
@app.command()
@async_cli()
async def ls():
"""List Systems."""
systems = await state.simbricks_client.get_systems()
print_systems_table(systems=systems)
@app.command()
@async_cli()
async def show(system_id: int):
"""Show individual System."""
run = await state.simbricks_client.get_system(system_id=system_id)
print_systems_table([run])
@app.command()
@async_cli()
async def delete(system_id: int):
"""Delete an individual run."""
client = state.simbricks_client
await client.delete_system(sys_id=system_id)
......@@ -25,18 +25,23 @@ import functools
from rich.table import Table
from rich.console import Console
def async_cli():
"""
Decorator function turning async cli routines into regular ones for
typer.
"""
def decorator_async_cli(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
return asyncio.run(f(*args, **kwargs))
return wrapper
return decorator_async_cli
def print_namespace_table(namespaces) -> None:
table = Table()
table.add_column("Id")
......@@ -46,4 +51,25 @@ def print_namespace_table(namespaces) -> None:
table.add_row(str(ns["id"]), str(ns["name"]), str(ns["parent_id"]))
console = Console()
console.print(table)
\ No newline at end of file
console.print(table)
def print_systems_table(systems):
table = Table()
table.add_column("Id")
for sys in systems:
table.add_row(str(sys["id"]))
console = Console()
console.print(table)
def print_simulations_table(instantiations):
table = Table()
table.add_column("Id")
table.add_column("SystemId")
for sys in instantiations:
table.add_row(str(sys["id"]), str(sys["system_id"]))
console = Console()
console.print(table)
......@@ -252,6 +252,10 @@ class SimBricksClient:
async with self._ns_client.post(url="/systems", json=json_obj) as resp:
return await resp.json()
async def delete_system(self, sys_id: int):
async with self._ns_client.delete(url=f"/systems/{sys_id}") as resp:
return await resp.json()
async def get_systems(self) -> list[dict]:
async with self._ns_client.get(url="/systems") as resp:
return await resp.json()
......@@ -266,6 +270,10 @@ class SimBricksClient:
async with self._ns_client.post(url="/simulations", json=json_obj) as resp:
return await resp.json()
async def delete_simulation(self, sim_id: int):
async with self._ns_client.delete(url=f"/simulations/{sim_id}") as resp:
return await resp.json()
async def get_simulation(self, simulation_id: int) -> dict:
async with self._ns_client.get(url=f"/simulations/{simulation_id}") as resp:
return await resp.json()
......@@ -275,11 +283,15 @@ class SimBricksClient:
return await resp.json()
async def create_instantiation(self, sim_db_id: int, instantiation: simulation.Simulation) -> simulation.Simulation:
inst_json = json.dumps({}) # FIXME
inst_json = json.dumps({}) # FIXME
json_obj = {"simulation_id": sim_db_id, "sb_json": inst_json}
async with self._ns_client.post(url="/instantiations", json=json_obj) as resp:
return await resp.json()
async def delete_instantiation(self, inst_id: int):
async with self._ns_client.delete(url=f"/instantiations/{inst_id}") as resp:
return await resp.json()
async def get_instantiation(self, instantiation_id: int) -> instantiation.Instantiation:
async with self._ns_client.get(url=f"/instantiations/{instantiation_id}") as resp:
return await resp.json()
......
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