Skip to content

Commit 2ddb7fa

Browse files
committed
enable stop for binaries
1 parent 363a94e commit 2ddb7fa

File tree

2 files changed

+25
-26
lines changed

2 files changed

+25
-26
lines changed

src/warnet/control.py

+23-24
Original file line numberDiff line numberDiff line change
@@ -25,39 +25,38 @@
2525
snapshot_bitcoin_datadir,
2626
)
2727
from .process import run_command, stream_command
28+
from .status import _get_active_binaries, _get_active_scenarios
2829

2930
console = Console()
3031

3132

32-
def get_active_scenarios():
33-
"""Get list of active scenarios"""
34-
commanders = get_mission("commander")
35-
return [c.metadata.name for c in commanders]
36-
37-
3833
@click.command()
39-
@click.argument("scenario_name", required=False)
40-
def stop(scenario_name):
41-
"""Stop a running scenario or all scenarios"""
42-
active_scenarios = get_active_scenarios()
34+
@click.argument("name", required=False)
35+
def stop(name):
36+
"""Stop one or all running scenarios or binaries"""
37+
all_running = [c["name"] for c in _get_active_scenarios()] + [
38+
b["name"] for b in _get_active_binaries()
39+
]
4340

44-
if not active_scenarios:
45-
console.print("[bold red]No active scenarios found.[/bold red]")
41+
if not all_running:
42+
console.print("[bold red]No active scenarios or binaries found.[/bold red]")
4643
return
4744

48-
if not scenario_name:
49-
table = Table(title="Active Scenarios", show_header=True, header_style="bold magenta")
45+
if not name:
46+
table = Table(
47+
title="Active Scenarios & binaries", show_header=True, header_style="bold magenta"
48+
)
5049
table.add_column("Number", style="cyan", justify="right")
51-
table.add_column("Scenario Name", style="green")
50+
table.add_column("Name", style="green")
5251

53-
for idx, name in enumerate(active_scenarios, 1):
52+
for idx, name in enumerate(all_running, 1):
5453
table.add_row(str(idx), name)
5554

5655
console.print(table)
5756

58-
choices = [str(i) for i in range(1, len(active_scenarios) + 1)] + ["a", "q"]
57+
choices = [str(i) for i in range(1, len(all_running) + 1)] + ["a", "q"]
5958
choice = Prompt.ask(
60-
"[bold yellow]Enter the number of the scenario to stop, 'a' to stop all, or 'q' to quit[/bold yellow]",
59+
"[bold yellow]Enter the number you want to stop, 'a' to stop all, or 'q' to quit[/bold yellow]",
6160
choices=choices,
6261
show_choices=False,
6362
)
@@ -67,18 +66,18 @@ def stop(scenario_name):
6766
return
6867
elif choice == "a":
6968
if Confirm.ask("[bold red]Are you sure you want to stop all scenarios?[/bold red]"):
70-
stop_all_scenarios(active_scenarios)
69+
stop_all_scenarios(all_running)
7170
else:
7271
console.print("[bold blue]Operation cancelled.[/bold blue]")
7372
return
7473

75-
scenario_name = active_scenarios[int(choice) - 1]
74+
name = all_running[int(choice) - 1]
7675

77-
if scenario_name not in active_scenarios:
78-
console.print(f"[bold red]No active scenario found with name: {scenario_name}[/bold red]")
76+
if name not in all_running:
77+
console.print(f"[bold red]No active scenario or binary found with name: {name}[/bold red]")
7978
return
8079

81-
stop_scenario(scenario_name)
80+
stop_scenario(name)
8281

8382

8483
def stop_scenario(scenario_name):
@@ -111,7 +110,7 @@ def stop_all_scenarios(scenarios):
111110

112111
def list_active_scenarios():
113112
"""List all active scenarios"""
114-
active_scenarios = get_active_scenarios()
113+
active_scenarios = [c["name"] for c in _get_active_scenarios()]
115114
if not active_scenarios:
116115
print("No active scenarios found.")
117116
return

test/test_base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
from time import sleep
1111

1212
from warnet import SRC_DIR
13-
from warnet.control import get_active_scenarios
1413
from warnet.k8s import get_pod_exit_status
1514
from warnet.network import _connected as network_connected
15+
from warnet.status import _get_active_scenarios as get_active_scenarios
1616
from warnet.status import _get_tank_status as network_status
1717

1818

@@ -126,7 +126,7 @@ def wait_for_all_edges(self, timeout=20 * 60, interval=5):
126126

127127
def wait_for_all_scenarios(self):
128128
def check_scenarios():
129-
scns = get_active_scenarios()
129+
scns = [c["name"] for c in get_active_scenarios()]
130130
if len(scns) == 0:
131131
return True
132132
for s in scns:

0 commit comments

Comments
 (0)