"vscode:/vscode.git/clone" did not exist on "4308fb4e0547f595cc0c1703226c2dbb7d3d1f8c"
Unverified Commit b2696fc5 authored by Jakob Görgen's avatar Jakob Görgen
Browse files

symphony/cli: removed state and use client provider instead

parent d487c932
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,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, instantiations, runners from simbricks.cli.commands import audit, admin, namespaces, runs, systems, simulations, instantiations, runners
from simbricks.cli.state import state from simbricks.client.provider import client_provider
from simbricks.cli.utils import async_cli from simbricks.cli.utils import async_cli
app = Typer() app = Typer()
...@@ -43,8 +43,8 @@ async def amain( ...@@ -43,8 +43,8 @@ async def amain(
ns: Annotated[str, Option(help="Namespace to operate in.")] = "foo/bar/baz", ns: Annotated[str, Option(help="Namespace to operate in.")] = "foo/bar/baz",
runner_ident: Annotated[int, Option(help="Runner ident to operate on.")] = -1, runner_ident: Annotated[int, Option(help="Runner ident to operate on.")] = -1,
): ):
state.namespace = ns client_provider.namespace = ns
state.runner_id = runner_ident client_provider.runner_id = runner_ident
def main(): def main():
......
...@@ -22,8 +22,7 @@ ...@@ -22,8 +22,7 @@
from typer import Typer, Option from typer import Typer, Option
from typing_extensions import Annotated from typing_extensions import Annotated
from simbricks.client.provider import client_provider
from ..state import state
from ..utils import async_cli, print_namespace_table from ..utils import async_cli, print_namespace_table
app = Typer(help="SimBricks admin commands.") app = Typer(help="SimBricks admin commands.")
...@@ -33,7 +32,7 @@ app = Typer(help="SimBricks admin commands.") ...@@ -33,7 +32,7 @@ app = Typer(help="SimBricks admin commands.")
@async_cli() @async_cli()
async def ns_ls(): async def ns_ls():
"""List all available namespaces.""" """List all available namespaces."""
client = state.admin_client client = client_provider.admin_client
namespaces = await client.get_all_ns() namespaces = await client.get_all_ns()
print_namespace_table(namespaces) print_namespace_table(namespaces)
...@@ -42,7 +41,7 @@ async def ns_ls(): ...@@ -42,7 +41,7 @@ async def ns_ls():
@async_cli() @async_cli()
async def ns_ls_id(ident: int): async def ns_ls_id(ident: int):
"""List namespace with given id ident.""" """List namespace with given id ident."""
client = state.admin_client client = client_provider.admin_client
namespace = await client.get_ns(ns_id=ident) namespace = await client.get_ns(ns_id=ident)
print_namespace_table([namespace]) print_namespace_table([namespace])
...@@ -51,16 +50,16 @@ async def ns_ls_id(ident: int): ...@@ -51,16 +50,16 @@ async def ns_ls_id(ident: int):
@async_cli() @async_cli()
async def ns_create(name: str, parent_id: Annotated[int, Option(help="optional parent namesapce")] = None): async def ns_create(name: str, parent_id: Annotated[int, Option(help="optional parent namesapce")] = None):
"""Create a new namespace.""" """Create a new namespace."""
client = state.admin_client client = client_provider.admin_client
namespace = await client.create_ns(parent_id=parent_id, name=name) namespace = await client.create_ns(parent_id=parent_id, name=name)
ns_id = namespace["id"] ns_id = namespace["id"]
print(f"Creating namespace {name} in {state.namespace}. New namespace: {ns_id}") print(f"Creating namespace {name} in {client_provider.namespace}. New namespace: {ns_id}")
@app.command() @app.command()
@async_cli() @async_cli()
async def ns_delete(ident: int): async def ns_delete(ident: int):
"""Delete a namespace.""" """Delete a namespace."""
client = state.admin_client client = client_provider.admin_client
await client.delete(ns_id=ident) await client.delete(ns_id=ident)
print(f"Deleted namespace with id {ident}.") print(f"Deleted namespace with id {ident}.")
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from typer import Typer from typer import Typer
from ..state import state
from ..utils import async_cli from ..utils import async_cli
app = Typer( app = Typer(
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from typer import Typer from typer import Typer
from ..state import state from simbricks.client.provider import client_provider
from ..utils import async_cli from ..utils import async_cli
from ..utils import print_instantiations_table from ..utils import print_instantiations_table
...@@ -32,7 +32,7 @@ app = Typer(help="Managing SimBricks Instantiations.") ...@@ -32,7 +32,7 @@ app = Typer(help="Managing SimBricks Instantiations.")
@async_cli() @async_cli()
async def ls(): async def ls():
"""List Instantiations.""" """List Instantiations."""
insts = await state.simbricks_client.get_instantiations() insts = await client_provider.simbricks_client.get_instantiations()
print_instantiations_table(insts) print_instantiations_table(insts)
...@@ -40,7 +40,7 @@ async def ls(): ...@@ -40,7 +40,7 @@ async def ls():
@async_cli() @async_cli()
async def show(inst_id: int): async def show(inst_id: int):
"""Show individual Instantiation.""" """Show individual Instantiation."""
inst = await state.simbricks_client.get_instantiation(instantiation_id=inst_id) inst = await client_provider.simbricks_client.get_instantiation(instantiation_id=inst_id)
print_instantiations_table([inst]) print_instantiations_table([inst])
...@@ -48,5 +48,5 @@ async def show(inst_id: int): ...@@ -48,5 +48,5 @@ async def show(inst_id: int):
@async_cli() @async_cli()
async def delete(inst_id: int): async def delete(inst_id: int):
"""Delete an individual Instantiation.""" """Delete an individual Instantiation."""
client = state.simbricks_client client = client_provider.simbricks_client
await client.delete_instantiation(inst_id=inst_id) await client.delete_instantiation(inst_id=inst_id)
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from typer import Typer from typer import Typer
from ..state import state from simbricks.client.provider import client_provider
from ..utils import async_cli, print_namespace_table, print_members_table from ..utils import async_cli, print_namespace_table, print_members_table
app = Typer(help="Managing SimBricks namespaces.") app = Typer(help="Managing SimBricks namespaces.")
...@@ -31,7 +31,7 @@ app = Typer(help="Managing SimBricks namespaces.") ...@@ -31,7 +31,7 @@ app = Typer(help="Managing SimBricks namespaces.")
@async_cli() @async_cli()
async def ls(): async def ls():
"""List available namespaces.""" """List available namespaces."""
client = state.ns_client client = client_provider.ns_client
namespaces = await client.get_all() namespaces = await client.get_all()
print_namespace_table(namespaces) print_namespace_table(namespaces)
...@@ -41,7 +41,7 @@ async def ls(): ...@@ -41,7 +41,7 @@ async def ls():
@async_cli() @async_cli()
async def ls_id(ident: int): async def ls_id(ident: int):
"""List namespace with given id ident.""" """List namespace with given id ident."""
client = state.ns_client client = client_provider.ns_client
namespace = await client.get_ns(ident) namespace = await client.get_ns(ident)
print_namespace_table([namespace]) print_namespace_table([namespace])
...@@ -51,7 +51,7 @@ async def ls_id(ident: int): ...@@ -51,7 +51,7 @@ async def ls_id(ident: int):
@async_cli() @async_cli()
async def ls_cur(): async def ls_cur():
"""List current namespace.""" """List current namespace."""
client = state.ns_client client = client_provider.ns_client
namespace = await client.get_cur() namespace = await client.get_cur()
print_namespace_table([namespace]) print_namespace_table([namespace])
...@@ -62,7 +62,7 @@ async def ls_cur(): ...@@ -62,7 +62,7 @@ async def ls_cur():
async def create(name: str): async def create(name: str):
"""Create a new namespace.""" """Create a new namespace."""
client = state.ns_client client = client_provider.ns_client
# create namespace relative to current namespace # create namespace relative to current namespace
cur_ns = await client.get_cur() cur_ns = await client.get_cur()
...@@ -72,7 +72,7 @@ async def create(name: str): ...@@ -72,7 +72,7 @@ async def create(name: str):
namespace = await client.create(parent_id=cur_ns_id, name=name) namespace = await client.create(parent_id=cur_ns_id, name=name)
ns_id = namespace["id"] ns_id = namespace["id"]
print(f"Creating namespace {name} in {state.namespace}. New namespace: {ns_id}") print(f"Creating namespace {name} in {client_provider.namespace}. New namespace: {ns_id}")
@app.command() @app.command()
...@@ -80,7 +80,7 @@ async def create(name: str): ...@@ -80,7 +80,7 @@ async def create(name: str):
async def delete(ident: int): async def delete(ident: int):
"""Delete a namespace.""" """Delete a namespace."""
client = state.ns_client client = client_provider.ns_client
await client.delete_ns(ident) await client.delete_ns(ident)
print(f"Deleted namespace with id {ident}.") print(f"Deleted namespace with id {ident}.")
...@@ -90,7 +90,7 @@ async def delete(ident: int): ...@@ -90,7 +90,7 @@ async def delete(ident: int):
async def members(): async def members():
"""List all members.""" """List all members."""
client = state.ns_client client = client_provider.ns_client
members = await client.get_members() members = await client.get_members()
print_members_table(members) print_members_table(members)
...@@ -100,6 +100,6 @@ async def members(): ...@@ -100,6 +100,6 @@ async def members():
async def member_add(user: str, role: str): async def member_add(user: str, role: str):
"""Add member to namespace.""" """Add member to namespace."""
client = state.ns_client client = client_provider.ns_client
members = await client.add_member(role, user) members = await client.add_member(role, user)
print(f"Added user {user} with role {role}.") print(f"Added user {user} with role {role}.")
\ No newline at end of file
...@@ -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 ..state import state from simbricks.client.provider import client_provider
from ..utils import async_cli, print_runner_table, print_table_generic from ..utils import async_cli, print_runner_table, print_table_generic
...@@ -33,7 +33,7 @@ app = Typer(help="Managing SimBricks runners.") ...@@ -33,7 +33,7 @@ app = Typer(help="Managing SimBricks runners.")
@async_cli() @async_cli()
async def ls(): async def ls():
"""List runners.""" """List runners."""
runs = await state.runner_client.list_runners() runs = await client_provider.runner_client.list_runners()
print_runner_table(runs) print_runner_table(runs)
...@@ -41,7 +41,7 @@ async def ls(): ...@@ -41,7 +41,7 @@ async def ls():
@async_cli() @async_cli()
async def show(runner_id: int): async def show(runner_id: int):
"""Show individual runner.""" """Show individual runner."""
runner = await state.runner_client.get_runner(runner_id=runner_id) runner = await client_provider.runner_client.get_runner(runner_id=runner_id)
print_runner_table([runner]) print_runner_table([runner])
...@@ -49,14 +49,14 @@ async def show(runner_id: int): ...@@ -49,14 +49,14 @@ async def show(runner_id: int):
@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 state.runner_client.delete_runner(runner_id=runner_id) await client_provider.runner_client.delete_runner(runner_id=runner_id)
@app.command() @app.command()
@async_cli() @async_cli()
async def create(label: str, tags: list[str]): async def create(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 state.runner_client.create_runner(label=label, tags=tags) runner = await client_provider.runner_client.create_runner(label=label, tags=tags)
print_runner_table([runner]) print_runner_table([runner])
...@@ -67,7 +67,7 @@ async def create_event( ...@@ -67,7 +67,7 @@ async def create_event(
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, heartbeat, simulation_status, start_run).""" """Send a run related event to a runner (Available actions: kill, heartbeat, simulation_status, start_run)."""
event = await state.runner_client.create_runner_event(action=action, run_id=run_id) event = await client_provider.runner_client.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")
...@@ -75,7 +75,7 @@ async def create_event( ...@@ -75,7 +75,7 @@ async def create_event(
@async_cli() @async_cli()
async def delete_event(event_id: int): async def delete_event(event_id: int):
"""Delete a runner event.""" """Delete a runner event."""
await state.runner_client.delete_runner_event(event_id=event_id) await client_provider.runner_client.delete_runner_event(event_id=event_id)
@app.command() @app.command()
...@@ -91,7 +91,7 @@ async def update_event( ...@@ -91,7 +91,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 state.runner_client.update_runner_event( event = await client_provider.runner_client.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,5 +106,5 @@ async def ls_events( ...@@ -106,5 +106,5 @@ async def ls_events(
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 state.runner_client.get_events(action=action, run_id=run_id, event_status=event_status, limit=limit) events = await client_provider.runner_client.get_events(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")
...@@ -26,7 +26,7 @@ from pathlib import Path ...@@ -26,7 +26,7 @@ from pathlib import Path
import simbricks.utils.load_mod as load_mod import simbricks.utils.load_mod as load_mod
from typer import Typer, Argument, Option from typer import Typer, Argument, Option
from typing_extensions import Annotated from typing_extensions import Annotated
from ..state import state from simbricks.client.provider import client_provider
from ..utils import async_cli from ..utils import async_cli
from rich.console import Console from rich.console import Console
...@@ -39,7 +39,7 @@ app = Typer(help="Managing SimBricks runs.") ...@@ -39,7 +39,7 @@ app = Typer(help="Managing SimBricks runs.")
@async_cli() @async_cli()
async def ls(): async def ls():
"""List runs.""" """List runs."""
runs = await state.simbricks_client.get_runs() runs = await client_provider.simbricks_client.get_runs()
table = Table() table = Table()
table.add_column("Id") table.add_column("Id")
...@@ -56,7 +56,7 @@ async def ls(): ...@@ -56,7 +56,7 @@ async def ls():
@async_cli() @async_cli()
async def show(run_id: int): async def show(run_id: int):
"""Show individual run.""" """Show individual run."""
run = await state.simbricks_client.get_run(run_id) run = await client_provider.simbricks_client.get_run(run_id)
print(run) print(run)
...@@ -64,7 +64,7 @@ async def show(run_id: int): ...@@ -64,7 +64,7 @@ async def show(run_id: int):
@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."""
client = state.simbricks_client client = client_provider.simbricks_client
await client.follow_run(run_id) await client.follow_run(run_id)
...@@ -72,7 +72,7 @@ async def follow(run_id: int): ...@@ -72,7 +72,7 @@ async def follow(run_id: int):
@async_cli() @async_cli()
async def delete(run_id: int): async def delete(run_id: int):
"""Delete an individual run.""" """Delete an individual run."""
client = state.simbricks_client client = client_provider.simbricks_client
await client.delete_run(run_id) await client.delete_run(run_id)
...@@ -80,7 +80,7 @@ async def delete(run_id: int): ...@@ -80,7 +80,7 @@ async def delete(run_id: int):
@async_cli() @async_cli()
async def set_input_tarball(run_id: int, source_file: str): async def set_input_tarball(run_id: int, source_file: str):
"""Set the tarball input for an individual run.""" """Set the tarball input for an individual run."""
client = state.simbricks_client client = client_provider.simbricks_client
await client.set_run_input(run_id, source_file) await client.set_run_input(run_id, source_file)
...@@ -88,7 +88,7 @@ async def set_input_tarball(run_id: int, source_file: str): ...@@ -88,7 +88,7 @@ async def set_input_tarball(run_id: int, source_file: str):
@async_cli() @async_cli()
async def set_output_artifact(run_id: int, source_file: str): async def set_output_artifact(run_id: int, source_file: str):
"""Set the tarball input for an individual run.""" """Set the tarball input for an individual run."""
client = state.simbricks_client client = client_provider.simbricks_client
await client.set_run_artifact(run_id, source_file) await client.set_run_artifact(run_id, source_file)
...@@ -96,7 +96,7 @@ async def set_output_artifact(run_id: int, source_file: str): ...@@ -96,7 +96,7 @@ async def set_output_artifact(run_id: int, source_file: str):
@async_cli() @async_cli()
async def get_output_artifact(run_id: int, destination_file: str): async def get_output_artifact(run_id: int, destination_file: str):
"""Follow individual run as it executes.""" """Follow individual run as it executes."""
client = state.simbricks_client client = client_provider.simbricks_client
await client.get_run_artifact(run_id, destination_file) await client.get_run_artifact(run_id, destination_file)
...@@ -104,7 +104,7 @@ async def get_output_artifact(run_id: int, destination_file: str): ...@@ -104,7 +104,7 @@ async def get_output_artifact(run_id: int, destination_file: str):
@async_cli() @async_cli()
async def update_run(run_id: int, updates: str): async def update_run(run_id: int, updates: str):
"""Update run with the 'updates' json string.""" """Update run with the 'updates' json string."""
client = state.simbricks_client client = client_provider.simbricks_client
json_updates = json.loads(updates) json_updates = json.loads(updates)
await client.update_run(run_id, updates=json_updates) await client.update_run(run_id, updates=json_updates)
...@@ -128,7 +128,7 @@ async def submit_script( ...@@ -128,7 +128,7 @@ async def submit_script(
): ):
"""Submit a SimBricks python simulation script to run.""" """Submit a SimBricks python simulation script to run."""
system_client = state.simbricks_client system_client = client_provider.simbricks_client
experiment_mod = load_mod.load_module(module_path=path) experiment_mod = load_mod.load_module(module_path=path)
instantiations = experiment_mod.instantiations instantiations = experiment_mod.instantiations
...@@ -154,7 +154,7 @@ async def submit_script( ...@@ -154,7 +154,7 @@ async def submit_script(
await system_client.set_run_input(run_id, input) await system_client.set_run_input(run_id, input)
if start: if start:
await state.runner_client.create_runner_event(action="start_run", run_id=run_id) await client_provider.runner_client.create_runner_event(action="start_run", run_id=run_id)
if follow: if follow:
await system_client.follow_run(run_id) await system_client.follow_run(run_id)
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from typer import Typer from typer import Typer
from ..state import state from simbricks.client.provider import client_provider
from ..utils import async_cli from ..utils import async_cli
from ..utils import print_simulations_table from ..utils import print_simulations_table
...@@ -32,7 +32,7 @@ app = Typer(help="Managing SimBricks Simulations.") ...@@ -32,7 +32,7 @@ app = Typer(help="Managing SimBricks Simulations.")
@async_cli() @async_cli()
async def ls(): async def ls():
"""List Simulations.""" """List Simulations."""
simulations = await state.simbricks_client.get_simulations() simulations = await client_provider.simbricks_client.get_simulations()
print_simulations_table(simulations) print_simulations_table(simulations)
...@@ -40,7 +40,7 @@ async def ls(): ...@@ -40,7 +40,7 @@ async def ls():
@async_cli() @async_cli()
async def show(sim_id: int): async def show(sim_id: int):
"""Show individual Simulation.""" """Show individual Simulation."""
sim = await state.simbricks_client.get_simulation(simulation_id=sim_id) sim = await client_provider.simbricks_client.get_simulation(simulation_id=sim_id)
print_simulations_table([sim]) print_simulations_table([sim])
...@@ -48,5 +48,5 @@ async def show(sim_id: int): ...@@ -48,5 +48,5 @@ async def show(sim_id: int):
@async_cli() @async_cli()
async def delete(sim_id: int): async def delete(sim_id: int):
"""Delete an individual SImulation.""" """Delete an individual SImulation."""
client = state.simbricks_client client = client_provider.simbricks_client
await client.delete_simulation(sim_id=sim_id) await client.delete_simulation(sim_id=sim_id)
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from typer import Typer from typer import Typer
from ..state import state from simbricks.client.provider import client_provider
from ..utils import async_cli from ..utils import async_cli
from ..utils import print_systems_table from ..utils import print_systems_table
...@@ -32,7 +32,7 @@ app = Typer(help="Managing SimBricks Systems.") ...@@ -32,7 +32,7 @@ app = Typer(help="Managing SimBricks Systems.")
@async_cli() @async_cli()
async def ls(): async def ls():
"""List Systems.""" """List Systems."""
systems = await state.simbricks_client.get_systems() systems = await client_provider.simbricks_client.get_systems()
print_systems_table(systems=systems) print_systems_table(systems=systems)
...@@ -40,7 +40,7 @@ async def ls(): ...@@ -40,7 +40,7 @@ async def ls():
@async_cli() @async_cli()
async def show(system_id: int): async def show(system_id: int):
"""Show individual System.""" """Show individual System."""
run = await state.simbricks_client.get_system(system_id=system_id) run = await client_provider.simbricks_client.get_system(system_id=system_id)
print_systems_table([run]) print_systems_table([run])
...@@ -48,5 +48,5 @@ async def show(system_id: int): ...@@ -48,5 +48,5 @@ async def show(system_id: int):
@async_cli() @async_cli()
async def delete(system_id: int): async def delete(system_id: int):
"""Delete an individual run.""" """Delete an individual run."""
client = state.simbricks_client client = client_provider.simbricks_client
await client.delete_system(sys_id=system_id) await client.delete_system(sys_id=system_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.
import os
from simbricks.client import BaseClient, AdminClient, NSClient, SimBricksClient, RunnerClient
class State:
def __init__(self):
self.namespace = ""
self.runner_id: int = -1
self._base_client: BaseClient | None = None
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):
if self._base_client is None:
self._base_client = BaseClient()
return self._base_client
@property
def admin_client(self):
if self._admin_client is None:
self._admin_client = AdminClient(base_client=self.base_client)
return self._admin_client
@property
def ns_client(self):
if self._ns_client is None:
self._ns_client = NSClient(base_client=self.base_client, namespace=self.namespace)
return self._ns_client
@property
def simbricks_client(self):
if self._simbricks_client is None:
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=self.runner_id)
return self._runner_client
state = State()
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