42
42
RayCluster ,
43
43
RayClusterStatus ,
44
44
)
45
+ from .widgets import cluster_up_down_buttons , is_notebook
45
46
from kubernetes import client , config
46
47
from kubernetes .utils import parse_quantity
47
48
import yaml
51
52
from kubernetes import config
52
53
from kubernetes .client .rest import ApiException
53
54
55
+ import ipywidgets as widgets
56
+ from IPython .display import display
57
+
54
58
55
59
class Cluster :
56
60
"""
@@ -71,6 +75,8 @@ def __init__(self, config: ClusterConfiguration):
71
75
self .app_wrapper_yaml = self .create_app_wrapper ()
72
76
self ._job_submission_client = None
73
77
self .app_wrapper_name = self .config .name
78
+ if is_notebook ():
79
+ self ._cluster_up_down_buttons ()
74
80
75
81
@property
76
82
def _client_headers (self ):
@@ -156,11 +162,34 @@ def up(self):
156
162
plural = "appwrappers" ,
157
163
body = aw ,
158
164
)
165
+ print (f"AppWrapper: '{ self .config .name } ' has successfully been created" )
159
166
else :
160
167
self ._component_resources_up (namespace , api_instance )
168
+ print (
169
+ f"Ray Cluster: '{ self .config .name } ' has successfully been created"
170
+ )
161
171
except Exception as e : # pragma: no cover
162
172
return _kube_api_error_handling (e )
163
173
174
+ def _cluster_up_down_buttons (self ):
175
+ up_button , delete_button = cluster_up_down_buttons (self .config .appwrapper )
176
+ output = widgets .Output ()
177
+ # Display the buttons in an HBox
178
+ display (widgets .HBox ([up_button , delete_button ]), output )
179
+
180
+ def on_up_button_clicked (b ):
181
+ with output :
182
+ output .clear_output ()
183
+ self .up ()
184
+
185
+ def on_down_button_clicked (b ):
186
+ with output :
187
+ output .clear_output ()
188
+ self .down ()
189
+
190
+ up_button .on_click (on_up_button_clicked )
191
+ delete_button .on_click (on_down_button_clicked )
192
+
164
193
def _throw_for_no_raycluster (self ):
165
194
api_instance = client .CustomObjectsApi (api_config_handler ())
166
195
try :
@@ -198,8 +227,12 @@ def down(self):
198
227
plural = "appwrappers" ,
199
228
name = self .app_wrapper_name ,
200
229
)
230
+ print (f"AppWrapper: '{ self .config .name } ' has successfully been deleted" )
201
231
else :
202
232
self ._component_resources_down (namespace , api_instance )
233
+ print (
234
+ f"Ray Cluster: '{ self .config .name } ' has successfully been deleted"
235
+ )
203
236
except Exception as e : # pragma: no cover
204
237
return _kube_api_error_handling (e )
205
238
0 commit comments