Skip to content

Commit c3666f7

Browse files
committed
feat: add ui cluster creation and deletion buttons
Signed-off-by: Bobbins228 <[email protected]>
1 parent fb59ba6 commit c3666f7

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/codeflare_sdk/cluster/cluster.py

+43
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
from kubernetes import config
5252
from kubernetes.client.rest import ApiException
5353

54+
import ipywidgets as widgets
55+
from IPython.display import display
56+
5457

5558
class Cluster:
5659
"""
@@ -71,6 +74,11 @@ def __init__(self, config: ClusterConfiguration):
7174
self.app_wrapper_yaml = self.create_app_wrapper()
7275
self._job_submission_client = None
7376
self.app_wrapper_name = self.config.name
77+
if (
78+
"PYDEVD_IPYTHON_COMPATIBLE_DEBUGGING" in os.environ
79+
or "JPY_SESSION_NAME" in os.environ
80+
): # If running Jupyter NBs in VsCode or RHOAI/ODH display UI buttons
81+
self._cluster_up_down_buttons()
7482

7583
@property
7684
def _client_headers(self):
@@ -156,11 +164,42 @@ def up(self):
156164
plural="appwrappers",
157165
body=aw,
158166
)
167+
print(f"AppWrapper: '{self.config.name}' has successfully been created")
159168
else:
160169
self._component_resources_up(namespace, api_instance)
170+
print(
171+
f"Ray Cluster: '{self.config.name}' has successfully been created"
172+
)
161173
except Exception as e: # pragma: no cover
162174
return _kube_api_error_handling(e)
163175

176+
def _cluster_up_down_buttons(self):
177+
delete_button = widgets.Button(
178+
description="Cluster Down",
179+
icon="trash",
180+
)
181+
up_button = widgets.Button(
182+
description="Cluster Up",
183+
icon="play",
184+
)
185+
186+
output = widgets.Output()
187+
# Display the buttons in an HBox
188+
display(widgets.HBox([delete_button, up_button]), output)
189+
190+
def on_up_button_clicked(b):
191+
with output:
192+
output.clear_output()
193+
self.up()
194+
195+
def on_down_button_clicked(b):
196+
with output:
197+
output.clear_output()
198+
self.down()
199+
200+
up_button.on_click(on_up_button_clicked)
201+
delete_button.on_click(on_down_button_clicked)
202+
164203
def _throw_for_no_raycluster(self):
165204
api_instance = client.CustomObjectsApi(api_config_handler())
166205
try:
@@ -198,8 +237,12 @@ def down(self):
198237
plural="appwrappers",
199238
name=self.app_wrapper_name,
200239
)
240+
print(f"AppWrapper: '{self.config.name}' has successfully been deleted")
201241
else:
202242
self._component_resources_down(namespace, api_instance)
243+
print(
244+
f"Ray Cluster: '{self.config.name}' has successfully been deleted"
245+
)
203246
except Exception as e: # pragma: no cover
204247
return _kube_api_error_handling(e)
205248

0 commit comments

Comments
 (0)