4
4
import time
5
5
from enum import Enum
6
6
from pathlib import Path
7
+ from typing import Optional
7
8
8
9
import click
9
10
from kubernetes .stream import stream
@@ -81,8 +82,9 @@ def _entrypoint(ctx, plugin_content: dict, warnet_content: dict):
81
82
"""Called by entrypoint"""
82
83
# write your plugin startup commands here
83
84
activity = plugin_content .get (PluginContent .ACTIVITY .value )
84
- activity = json .loads (activity )
85
- print (activity )
85
+ if activity :
86
+ activity = json .loads (activity )
87
+ print (activity )
86
88
_launch_activity (activity , ctx .obj .get (PLUGIN_DIR_TAG ))
87
89
88
90
@@ -132,8 +134,8 @@ def launch_activity(ctx, activity: str):
132
134
print (_launch_activity (parsed_activity , plugin_dir ))
133
135
134
136
135
- def _launch_activity (activity : list [dict ], plugin_dir : str ) -> str :
136
- """Launch a SimLN chart which includes the `activity`"""
137
+ def _launch_activity (activity : Optional [ list [dict ] ], plugin_dir : str ) -> str :
138
+ """Launch a SimLN chart which optionally includes the `activity`"""
137
139
timestamp = int (time .time ())
138
140
name = f"simln-{ timestamp } "
139
141
@@ -156,7 +158,7 @@ def _launch_activity(activity: list[dict], plugin_dir: str) -> str:
156
158
raise PluginError (f"Could not write sim.json to the init container: { name } " )
157
159
158
160
159
- def _generate_activity_json (activity : list [dict ]) -> str :
161
+ def _generate_activity_json (activity : Optional [ list [dict ] ]) -> str :
160
162
nodes = []
161
163
162
164
for i in get_mission (LIGHTNING_MISSION ):
@@ -169,7 +171,10 @@ def _generate_activity_json(activity: list[dict]) -> str:
169
171
}
170
172
nodes .append (node )
171
173
172
- data = {"nodes" : nodes , PluginContent .ACTIVITY .value : activity }
174
+ if activity :
175
+ data = {"nodes" : nodes , PluginContent .ACTIVITY .value : activity }
176
+ else :
177
+ data = {"nodes" : nodes }
173
178
174
179
return json .dumps (data , indent = 2 )
175
180
0 commit comments