2
2
from ..utils .pretty_print import RayCluster
3
3
from ..utils import pretty_print
4
4
import openshift as oc
5
- from typing import List
5
+ from typing import List , Optional
6
+
6
7
7
8
class Cluster :
8
9
def __init__ (self , config : ClusterConfiguration ):
9
- pass
10
+ self . config = config
10
11
12
+ # creates a new cluser with the provided or default spec
11
13
def up (self ):
12
14
pass
13
15
14
16
def down (self , name ):
15
17
pass
16
18
17
- def status (self , name ):
18
- pass
19
-
19
+ def status (self , print_to_console = True ):
20
+ cluster = _ray_cluster_status (self .config .name )
21
+ if cluster :
22
+ if print_to_console :
23
+ pretty_print .print_clusters ([cluster ])
24
+ return cluster .status
25
+ else :
26
+ return None
27
+
20
28
21
29
def list_all_clusters (print_to_console = True ):
22
30
clusters = _get_ray_clusters ()
23
31
if print_to_console :
24
32
pretty_print .print_clusters (clusters )
25
33
return clusters
26
-
34
+
27
35
28
36
# private methods
29
37
@@ -33,18 +41,39 @@ def _get_appwrappers(namespace='default'):
33
41
return app_wrappers
34
42
35
43
44
+ def _ray_cluster_status (name , namespace = 'default' ) -> Optional [RayCluster ]:
45
+
46
+ with oc .project (namespace ), oc .timeout (10 * 60 ):
47
+ cluster = oc .selector (f'rayclusters/{ name } ' ).object ()
48
+
49
+ if cluster :
50
+ return _map_to_ray_cluster (cluster )
51
+ else :
52
+ return None
53
+
54
+
55
+
56
+
36
57
def _get_ray_clusters (namespace = 'default' ) -> List [RayCluster ]:
37
58
list_of_clusters = []
59
+
38
60
with oc .project (namespace ), oc .timeout (10 * 60 ):
39
61
ray_clusters = oc .selector ('rayclusters' ).objects ()
40
- for cluster in ray_clusters :
41
- cluster_model = cluster .model
42
- list_of_clusters .append (RayCluster (
43
- name = cluster .name (), status = cluster_model .status .state ,
44
- min_workers = cluster_model .spec .workerGroupSpecs [0 ].replicas ,
45
- max_workers = cluster_model .spec .workerGroupSpecs [0 ].replicas ,
46
- worker_mem_max = cluster_model .spec .workerGroupSpecs [0 ].template .spec .containers [0 ].resources .limits .memory ,
47
- worker_mem_min = cluster_model .spec .workerGroupSpecs [0 ].template .spec .containers [0 ].resources .requests .memory ,
48
- worker_cpu = cluster_model .spec .workerGroupSpecs [0 ].template .spec .containers [0 ].resources .limits .cpu ,
49
- worker_gpu = 0 ))
62
+
63
+ for cluster in ray_clusters :
64
+ list_of_clusters .append (_map_to_ray_cluster (cluster ))
50
65
return list_of_clusters
66
+
67
+
68
+ def _map_to_ray_cluster (cluster ):
69
+ cluster_model = cluster .model
70
+ return RayCluster (
71
+ name = cluster .name (), status = cluster_model .status .state ,
72
+ min_workers = cluster_model .spec .workerGroupSpecs [0 ].replicas ,
73
+ max_workers = cluster_model .spec .workerGroupSpecs [0 ].replicas ,
74
+ worker_mem_max = cluster_model .spec .workerGroupSpecs [
75
+ 0 ].template .spec .containers [0 ].resources .limits .memory ,
76
+ worker_mem_min = cluster_model .spec .workerGroupSpecs [
77
+ 0 ].template .spec .containers [0 ].resources .requests .memory ,
78
+ worker_cpu = cluster_model .spec .workerGroupSpecs [0 ].template .spec .containers [0 ].resources .limits .cpu ,
79
+ worker_gpu = 0 )
0 commit comments