From 97fd597069ca03f4037702ea1e0bdf35e2c24336 Mon Sep 17 00:00:00 2001 From: Miguel Angel Ajo Pelayo Date: Tue, 15 Jul 2025 13:38:05 +0200 Subject: [PATCH] Stream exporter logs in jmp shell It's not enabled by default, now it requires the --exporter-logs flag, otherwise it becomes too annoying, for example when doing a serial console session or other activities. --- packages/jumpstarter-cli/jumpstarter_cli/j.py | 3 +- .../jumpstarter-cli/jumpstarter_cli/shell.py | 28 +++++++++++++------ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/packages/jumpstarter-cli/jumpstarter_cli/j.py b/packages/jumpstarter-cli/jumpstarter_cli/j.py index 5f9a8c552..1cf7befdc 100644 --- a/packages/jumpstarter-cli/jumpstarter_cli/j.py +++ b/packages/jumpstarter-cli/jumpstarter_cli/j.py @@ -19,8 +19,7 @@ async def cli(): async with BlockingPortal() as portal: with ExitStack() as stack: async with env_async(portal, stack) as client: - async with client.log_stream_async(): - await to_thread.run_sync(lambda: client.cli()(standalone_mode=False)) + await to_thread.run_sync(lambda: client.cli()(standalone_mode=False)) try: async with create_task_group() as tg: diff --git a/packages/jumpstarter-cli/jumpstarter_cli/shell.py b/packages/jumpstarter-cli/jumpstarter_cli/shell.py index 7df2d4574..64e682035 100644 --- a/packages/jumpstarter-cli/jumpstarter_cli/shell.py +++ b/packages/jumpstarter-cli/jumpstarter_cli/shell.py @@ -20,9 +20,10 @@ @click.option("--lease", "lease_name") @opt_selector @opt_duration_partial(default=timedelta(minutes=30), show_default="00:30:00") +@click.option("--exporter-logs", is_flag=True, help="Enable exporter log streaming") # end client specific @handle_exceptions_with_reauthentication(relogin_client) -def shell(config, command: tuple[str, ...], lease_name, selector, duration): +def shell(config, command: tuple[str, ...], lease_name, selector, duration, exporter_logs): """ Spawns a shell (or custom command) connecting to a local or remote exporter @@ -42,13 +43,24 @@ def shell(config, command: tuple[str, ...], lease_name, selector, duration): with config.lease(selector=selector, lease_name=lease_name, duration=duration) as lease: with lease.serve_unix() as path: with lease.monitor(): - exit_code = launch_shell( - path, - "remote", - config.drivers.allow, - config.drivers.unsafe, - command=command, - ) + if exporter_logs: + with lease.connect() as client: + with client.log_stream(): + exit_code = launch_shell( + path, + "remote", + config.drivers.allow, + config.drivers.unsafe, + command=command, + ) + else: + exit_code = launch_shell( + path, + "remote", + config.drivers.allow, + config.drivers.unsafe, + command=command, + ) sys.exit(exit_code)