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

symphony/cli: added clie commands to retreive and delete instantiations

parent 57033c17
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
from typer import Typer, Option from typer import Typer, Option
from typing_extensions import Annotated from typing_extensions import Annotated
from simbricks.cli.commands import audit, admin, namespaces, runs, systems, simulations from simbricks.cli.commands import audit, admin, namespaces, runs, systems, simulations, instantiations
from simbricks.cli.state import state from simbricks.cli.state import state
from simbricks.cli.utils import async_cli from simbricks.cli.utils import async_cli
...@@ -33,6 +33,7 @@ app.add_typer(audit.app, name="audit") ...@@ -33,6 +33,7 @@ app.add_typer(audit.app, name="audit")
app.add_typer(admin.app, name="admin") app.add_typer(admin.app, name="admin")
app.add_typer(systems.app, name="systems") app.add_typer(systems.app, name="systems")
app.add_typer(simulations.app, name="sims") app.add_typer(simulations.app, name="sims")
app.add_typer(instantiations.app, name="insts")
@app.callback() @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_instantiations_table
app = Typer(help="Managing SimBricks Instantiations.")
@app.command()
@async_cli()
async def ls():
"""List Instantiations."""
insts = await state.simbricks_client.get_instantiations()
print_instantiations_table(insts)
@app.command()
@async_cli()
async def show(inst_id: int):
"""Show individual Instantiation."""
inst = await state.simbricks_client.get_instantiation(instantiation_id=inst_id)
print_instantiations_table([inst])
@app.command()
@async_cli()
async def delete(inst_id: int):
"""Delete an individual Instantiation."""
client = state.simbricks_client
await client.delete_instantiation(inst_id=inst_id)
...@@ -73,3 +73,13 @@ def print_simulations_table(instantiations): ...@@ -73,3 +73,13 @@ def print_simulations_table(instantiations):
console = Console() console = Console()
console.print(table) console.print(table)
def print_instantiations_table(instantiations):
table = Table()
table.add_column("Id")
table.add_column("SimulationId")
for sys in instantiations:
table.add_row(str(sys["id"]), str(sys["simulation_id"]))
console = Console()
console.print(table)
...@@ -292,10 +292,14 @@ class SimBricksClient: ...@@ -292,10 +292,14 @@ class SimBricksClient:
async with self._ns_client.delete(url=f"/instantiations/{inst_id}") as resp: async with self._ns_client.delete(url=f"/instantiations/{inst_id}") as resp:
return await resp.json() return await resp.json()
async def get_instantiation(self, instantiation_id: int) -> instantiation.Instantiation: async def get_instantiation(self, instantiation_id: int) -> dict:
async with self._ns_client.get(url=f"/instantiations/{instantiation_id}") as resp: async with self._ns_client.get(url=f"/instantiations/{instantiation_id}") as resp:
return await resp.json() return await resp.json()
async def get_instantiations(self) -> list[dict]:
async with self._ns_client.get(url="/instantiations") as resp:
return await resp.json()
async def create_run(self, inst_db_id: int) -> dict: async def create_run(self, inst_db_id: int) -> dict:
json_obj = { json_obj = {
"instantiation_id": inst_db_id, "instantiation_id": inst_db_id,
......
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