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

cli/simbricks/cli/commands : commands for handling files associated with runs...

cli/simbricks/cli/commands : commands for handling files associated with runs + handel creation, deletion, retrieval of runs
parent f8a77e1b
...@@ -81,5 +81,5 @@ async def delete(ident: int): ...@@ -81,5 +81,5 @@ async def delete(ident: int):
"""Delete a namespace.""" """Delete a namespace."""
client = state.ns_client client = state.ns_client
await client.delete(ident) await client.delete_ns(ident)
print(f"Deleted namespace with id {ident}.") print(f"Deleted namespace with id {ident}.")
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import json
import asyncio import asyncio
from pathlib import Path from pathlib import Path
import simbricks.utils.load_mod as load_mod import simbricks.utils.load_mod as load_mod
...@@ -31,9 +32,8 @@ from ..utils import async_cli ...@@ -31,9 +32,8 @@ from ..utils import async_cli
from rich.console import Console from rich.console import Console
from rich.table import Table from rich.table import Table
app = Typer( app = Typer(help="Managing SimBricks runs.")
help="Managing SimBricks runs."
)
@app.command() @app.command()
@async_cli() @async_cli()
...@@ -42,16 +42,16 @@ async def ls(): ...@@ -42,16 +42,16 @@ async def ls():
runs = await state.simbricks_client.get_runs() runs = await state.simbricks_client.get_runs()
table = Table() table = Table()
table.add_column('Id') table.add_column("Id")
table.add_column('Instantiation') table.add_column("Instantiation")
table.add_column('State') table.add_column("State")
for r in runs: for r in runs:
table.add_row(str(r['id']), str(r['instantiation_id']), table.add_row(str(r["id"]), str(r["instantiation_id"]), r["state"])
r['state'])
console = Console() console = Console()
console.print(table) console.print(table)
@app.command() @app.command()
@async_cli() @async_cli()
async def show(run_id: int): async def show(run_id: int):
...@@ -59,36 +59,79 @@ async def show(run_id: int): ...@@ -59,36 +59,79 @@ async def show(run_id: int):
run = await state.simbricks_client.get_run(run_id) run = await state.simbricks_client.get_run(run_id)
print(run) print(run)
async def follow_run(run_id: int): async def follow_run(run_id: int):
last_run = None last_run = None
while True: while True:
run = await state.simbricks_client.get_run(run_id) run = await state.simbricks_client.get_run(run_id)
if not last_run or last_run['state'] != run['state']: if not last_run or last_run["state"] != run["state"]:
print(f'State:', run['state']) print(f"State:", run["state"])
if not last_run or ( if not last_run or (len(last_run["output"]) != len(run["output"]) and len(run["output"]) != 0):
len(last_run['output']) != len(run['output']) and prev_len = len(last_run["output"]) if last_run else 0
len(run['output']) != 0): print(run["output"][prev_len:])
prev_len = len(last_run['output']) if last_run else 0 if run["state"] != "pending" and run["state"] != "running":
print(run['output'][prev_len:])
if run['state'] != 'pending' and run['state'] != 'running':
break break
last_run = run last_run = run
await asyncio.sleep(1) await asyncio.sleep(1)
@app.command() @app.command()
@async_cli() @async_cli()
async def follow(run_id: int): async def follow(run_id: int):
"""Follow individual run as it executes.""" """Follow individual run as it executes."""
await follow_run(run_id) await follow_run(run_id)
@app.command()
@async_cli()
async def delete(run_id: int):
"""Delete an individual run."""
client = state.simbricks_client
await client.delete_run(run_id)
@app.command()
@async_cli()
async def set_input_tarball(run_id: int, source_file: str):
"""Set the tarball input for an individual run."""
client = state.simbricks_client
await client.set_run_input(run_id, source_file)
@app.command()
@async_cli()
async def set_output_artifact(run_id: int, source_file: str):
"""Set the tarball input for an individual run."""
client = state.simbricks_client
await client.set_run_artifact(run_id, source_file)
@app.command()
@async_cli()
async def get_output_artifact(run_id: int, destination_file: str):
"""Follow individual run as it executes."""
client = state.simbricks_client
await client.get_run_artifact(run_id, destination_file)
@app.command()
@async_cli()
async def update_run(run_id: int, updates: str):
"""Update run with the 'updates' json string."""
client = state.simbricks_client
json_updates = json.loads(updates)
await client.update_run(run_id, updates=json_updates)
@app.command() @app.command()
@async_cli() @async_cli()
async def submit_script( async def submit_script(
path: Annotated[Path, Argument(help="Python simulation script to submit.")], path: Annotated[Path, Argument(help="Python simulation script to submit.")],
follow: Annotated[bool, Option("--follow", "-f", follow: Annotated[bool, Option("--follow", "-f", help="Wait for run to terminate and show output live.")] = False,
help="Wait for run to terminate and show output live.")] = False, input: Annotated[
str | None, Option("--input", "-i", help="Specify a tarball file of inputs needed for running the simulation.")
] = None,
): ):
"""Submit a SimBricks python simulation script to run.""" """Submit a SimBricks python simulation script to run."""
...@@ -119,7 +162,12 @@ async def submit_script( ...@@ -119,7 +162,12 @@ async def submit_script(
inst_id = int(instantiation["id"]) inst_id = int(instantiation["id"])
run = await system_client.create_run(inst_id) run = await system_client.create_run(inst_id)
run_id = run["id"]
if input:
await system_client.set_run_input(run_id, input)
await system_client.update_run(run_id, {"state": "pending", "output": ""})
print(run) print(run)
if follow: if follow:
await follow_run(run['id']) await follow_run(run_id)
\ No newline at end of file
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