44import logging
55import time
66from pathlib import Path
7- from typing import Optional
87
98import click
109from kubernetes .stream import stream
1110
1211# When we want to select pods based on their role in Warnet, we use "mission" tags. The "mission"
1312# tag for "lightning" nodes is stored in LIGHTNING_MISSION.
14- from warnet .constants import LIGHTNING_MISSION , USER_DIR_TAG
13+ from warnet .constants import LIGHTNING_MISSION , PLUGIN_DIR_TAG
1514from warnet .k8s import (
1615 download ,
1716 get_default_namespace ,
2019 wait_for_init ,
2120 write_file_to_container ,
2221)
23- from warnet .plugins import get_plugins_directory_or
2422from warnet .process import run_command
2523
2624# To make a "mission" tag for your plugin, declare it using the variable name MISSION. This will
@@ -55,15 +53,9 @@ class SimLNError(Exception):
5553@click .pass_context
5654def simln (ctx ):
5755 """Commands for the SimLN plugin"""
58- try :
59- # check if we have set a user directory
60- ctx .obj .get (USER_DIR_TAG )
61- except Exception :
62- # if not, set the great-grandparent of this file as the user dir
63- ctx .ensure_object (dict )
64- user_dir = Path (__file__ ).resolve ().parent .parent .parent
65- ctx .obj [USER_DIR_TAG ] = Path (user_dir )
66- pass
56+ ctx .ensure_object (dict )
57+ plugin_dir = Path (__file__ ).resolve ().parent
58+ ctx .obj [PLUGIN_DIR_TAG ] = Path (plugin_dir )
6759
6860
6961# Make sure to register your plugin by adding the group function like so:
@@ -74,8 +66,8 @@ def warnet_register_plugin(register_command):
7466# The group function name is then used in decorators to create commands. These commands are
7567# available to users when they access your plugin from the command line in Warnet.
7668@simln .command ()
77- def list_simln_podnames ():
78- """Get a list of simln pod names"""
69+ def list_pod_names ():
70+ """Get a list of SimLN pod names"""
7971 print ([pod .metadata .name for pod in get_mission (MISSION )])
8072
8173
@@ -111,14 +103,12 @@ def get_example_activity():
111103 print (json .dumps (_get_example_activity ()))
112104
113105
114- def _launch_activity (activity : list [dict ], user_dir : Optional [ str ] = None ) -> str :
106+ def _launch_activity (activity : list [dict ], plugin_dir : str ) -> str :
115107 """Launch a SimLN chart which includes the `activity`"""
116- plugin_dir = get_plugins_directory_or (user_dir )
117-
118108 timestamp = int (time .time ())
119109 name = f"simln-{ timestamp } "
120110
121- command = f"helm upgrade --install { timestamp } { plugin_dir } /simln/ charts/simln"
111+ command = f"helm upgrade --install { timestamp } { plugin_dir } /charts/simln"
122112 run_command (command )
123113
124114 activity_json = _generate_activity_json (activity )
@@ -147,8 +137,8 @@ def launch_activity(ctx, activity: str):
147137 except json .JSONDecodeError :
148138 log .error ("Invalid JSON input for activity." )
149139 raise click .BadArgumentUsage ("Activity must be a valid JSON string." ) from None
150- user_dir = ctx .obj .get (USER_DIR_TAG )
151- print (_launch_activity (parsed_activity , user_dir ))
140+ plugin_dir = ctx .obj .get (PLUGIN_DIR_TAG )
141+ print (_launch_activity (parsed_activity , plugin_dir ))
152142
153143
154144def _generate_activity_json (activity : list [dict ]) -> str :
0 commit comments