51
51
from kubernetes import config
52
52
from kubernetes .client .rest import ApiException
53
53
54
+ import ipywidgets as widgets
55
+ from IPython .display import display
56
+
54
57
55
58
class Cluster :
56
59
"""
@@ -71,6 +74,11 @@ def __init__(self, config: ClusterConfiguration):
71
74
self .app_wrapper_yaml = self .create_app_wrapper ()
72
75
self ._job_submission_client = None
73
76
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 ()
74
82
75
83
@property
76
84
def _client_headers (self ):
@@ -156,11 +164,42 @@ def up(self):
156
164
plural = "appwrappers" ,
157
165
body = aw ,
158
166
)
167
+ print (f"AppWrapper: '{ self .config .name } ' has successfully been created" )
159
168
else :
160
169
self ._component_resources_up (namespace , api_instance )
170
+ print (
171
+ f"Ray Cluster: '{ self .config .name } ' has successfully been created"
172
+ )
161
173
except Exception as e : # pragma: no cover
162
174
return _kube_api_error_handling (e )
163
175
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
+
164
203
def _throw_for_no_raycluster (self ):
165
204
api_instance = client .CustomObjectsApi (api_config_handler ())
166
205
try :
@@ -198,8 +237,12 @@ def down(self):
198
237
plural = "appwrappers" ,
199
238
name = self .app_wrapper_name ,
200
239
)
240
+ print (f"AppWrapper: '{ self .config .name } ' has successfully been deleted" )
201
241
else :
202
242
self ._component_resources_down (namespace , api_instance )
243
+ print (
244
+ f"Ray Cluster: '{ self .config .name } ' has successfully been deleted"
245
+ )
203
246
except Exception as e : # pragma: no cover
204
247
return _kube_api_error_handling (e )
205
248
0 commit comments