4
4
from pathlib import Path
5
5
from subprocess import run
6
6
from time import sleep
7
+ from typing import Optional
7
8
8
9
import click
9
10
from kubernetes .stream import stream
10
11
11
12
# When we want to select pods based on their role in Warnet, we use "mission" tags. The "mission"
12
13
# tag for "lightning" nodes is stored in LIGHTNING_MISSION.
13
- from warnet .constants import LIGHTNING_MISSION
14
+ from warnet .constants import LIGHTNING_MISSION , USER_DIR_TAG
14
15
from warnet .k8s import (
15
16
download ,
16
17
get_default_namespace ,
17
18
get_mission ,
18
19
get_static_client ,
19
20
wait_for_pod ,
20
21
)
21
- from warnet .plugins import get_plugins_directory_or as get_plugin_directory
22
+ from warnet .plugins import get_plugins_directory_or
22
23
from warnet .process import run_command
23
24
from warnet .status import _get_tank_status as network_status
24
25
@@ -86,9 +87,11 @@ def list_simln_podnames():
86
87
87
88
88
89
@simln .command ()
90
+ @click .argument ("pod_name" , type = str )
89
91
def download_results (pod_name : str ):
90
92
"""Download SimLN results to the current directory"""
91
- print (download (pod_name , source_path = Path ("/working/results" )))
93
+ dest = download (pod_name , source_path = Path ("/working/results" ))
94
+ print (f"Downloaded results to: { dest } " )
92
95
93
96
94
97
def prepare_and_launch_activity () -> str :
@@ -123,10 +126,10 @@ def get_example_activity():
123
126
print (json .dumps (_get_example_activity ()))
124
127
125
128
126
- def _launch_activity (activity : list [dict ]) -> str :
129
+ def _launch_activity (activity : list [dict ], user_dir : Optional [ str ] = None ) -> str :
127
130
"""Launch a SimLN chart which includes the `activity`"""
128
131
random_digits = "" .join (random .choices ("0123456789" , k = 10 ))
129
- plugin_dir = get_plugin_directory ( )
132
+ plugin_dir = get_plugins_directory_or ( user_dir )
130
133
_generate_nodes_file (activity , plugin_dir / Path ("simln/charts/simln/files/sim.json" ))
131
134
command = f"helm upgrade --install simln-{ random_digits } { plugin_dir } /simln/charts/simln"
132
135
log .info (f"generate activity: { command } " )
@@ -137,10 +140,12 @@ def _launch_activity(activity: list[dict]) -> str:
137
140
# Take note of how click expects us to explicitly declare command line arguments.
138
141
@simln .command ()
139
142
@click .argument ("activity" , type = str )
140
- def launch_activity (activity : str ):
143
+ @click .pass_context
144
+ def launch_activity (ctx , activity : str ):
141
145
"""Takes a SimLN Activity which is a JSON list of objects."""
142
146
parsed_activity = json .loads (activity )
143
- print (_launch_activity (parsed_activity ))
147
+ user_dir = ctx .obj .get (USER_DIR_TAG )
148
+ print (_launch_activity (parsed_activity , user_dir ))
144
149
145
150
146
151
def _init_network ():
0 commit comments