@@ -28,57 +28,57 @@ def __str__(self):
2828 return str (self .value )
2929
3030
31- class LoginNodesStatus :
32- """Represents the status of the cluster login nodes pools ."""
31+ class PoolStatus :
32+ """Represents the status of a pool of login nodes."""
3333
34- def __init__ (self , stack_name ):
35- self ._stack_name = stack_name
36- self ._login_nodes_pool_name = None
37- self ._login_nodes_pool_available = False
38- self ._load_balancer_arn = None
39- self ._target_group_arn = None
40- self ._status = None
34+ def __init__ (self , stack_name , pool_name ):
4135 self ._dns_name = None
36+ self ._status = None
4237 self ._scheme = None
38+ self ._pool_name = pool_name
39+ self ._pool_available = False
40+ self ._stack_name = stack_name
4341 self ._healthy_nodes = None
4442 self ._unhealthy_nodes = None
43+ self ._load_balancer_arn = None
44+ self ._target_group_arn = None
45+ self ._retrieve_data ()
4546
4647 def __str__ (self ):
4748 return (
4849 f'("status": "{ self ._status } ", "address": "{ self ._dns_name } ", "scheme": "{ self ._scheme } ", '
49- f'"healthyNodes ": "{ self ._healthy_nodes } ", "unhealthy_nodes": "{ self ._unhealthy_nodes } ")'
50+ f'"healthy_nodes ": "{ self ._healthy_nodes } ", "unhealthy_nodes": "{ self ._unhealthy_nodes } "), '
5051 )
5152
52- def get_login_nodes_pool_available (self ):
53- """Return the status of a login nodes fleet."""
54- return self ._login_nodes_pool_available
53+ def get_healthy_nodes (self ):
54+ """Return the number of healthy nodes of the login node pool."""
55+ return self ._healthy_nodes
56+
57+ def get_unhealthy_nodes (self ):
58+ """Return the number of unhealthy nodes of the login node pool."""
59+ return self ._unhealthy_nodes
60+
61+ def get_pool_available (self ):
62+ """Return true if the pool is available."""
63+ return self ._pool_available
5564
5665 def get_status (self ):
57- """Return the status of a login nodes fleet ."""
66+ """Return the status of the login node pool ."""
5867 return self ._status
5968
6069 def get_address (self ):
61- """Return the single connection address of a login nodes fleet ."""
70+ """Return the connection addresses of the login node pool ."""
6271 return self ._dns_name
6372
6473 def get_scheme (self ):
65- """Return the schema of a login nodes fleet ."""
74+ """Return the schema of the login node pool ."""
6675 return self ._scheme
6776
68- def get_healthy_nodes (self ):
69- """Return the number of healthy nodes of a login nodes fleet."""
70- return self ._healthy_nodes
71-
72- def get_unhealthy_nodes (self ):
73- """Return the number of unhealthy nodes of a login nodes fleet."""
74- return self ._unhealthy_nodes
75-
76- def retrieve_data (self , login_nodes_pool_name ):
77+ def _retrieve_data (self ):
7778 """Initialize the class with the information related to the login nodes pool."""
78- self ._login_nodes_pool_name = login_nodes_pool_name
7979 self ._retrieve_assigned_load_balancer ()
8080 if self ._load_balancer_arn :
81- self ._login_nodes_pool_available = True
81+ self ._pool_available = True
8282 self ._populate_target_groups ()
8383 self ._populate_target_group_health ()
8484
@@ -98,7 +98,7 @@ def _load_balancer_arn_from_tags(self, tags_list):
9898 for tags in tags_list :
9999 if self ._key_value_tag_found (
100100 tags , "parallelcluster:cluster-name" , self ._stack_name
101- ) and self ._key_value_tag_found (tags , "parallelcluster:login-nodes-pool" , self ._login_nodes_pool_name ):
101+ ) and self ._key_value_tag_found (tags , "parallelcluster:login-nodes-pool" , self ._pool_name ):
102102 self ._load_balancer_arn = tags .get ("ResourceArn" )
103103 break
104104
@@ -153,3 +153,64 @@ def _populate_target_group_health(self):
153153 "This is expected if login nodes pool creation/deletion is in progress" ,
154154 e ,
155155 )
156+
157+
158+ class LoginNodesStatus :
159+ """Represents the status of the cluster login nodes pools."""
160+
161+ def __init__ (self , stack_name ):
162+ self ._stack_name = stack_name
163+ self ._pool_status_dict = dict ()
164+ self ._login_nodes_pool_available = False
165+ self ._total_healthy_nodes = None
166+ self ._total_unhealthy_nodes = None
167+
168+ def __str__ (self ):
169+ out = ""
170+ for pool_status in self ._pool_status_dict .values ():
171+ out += str (pool_status )
172+ return out
173+
174+ def get_login_nodes_pool_available (self ):
175+ """Return true if a pool is available in the login nodes fleet."""
176+ return self ._login_nodes_pool_available
177+
178+ def get_pool_status_dict (self ):
179+ """Return a dictionary mapping each login node pool name to respective pool status."""
180+ return self ._pool_status_dict
181+
182+ def get_healthy_nodes (self , pool_name = None ):
183+ """Return the total number of healthy login nodes in the cluster or a specific pool."""
184+ healthy_nodes = (
185+ self ._pool_status_dict .get (pool_name ).get_healthy_nodes () if pool_name else self ._total_healthy_nodes
186+ )
187+ return healthy_nodes
188+
189+ def get_unhealthy_nodes (self , pool_name = None ):
190+ """Return the total number of unhealthy login nodes in the cluster or a specific pool."""
191+ unhealthy_nodes = (
192+ self ._pool_status_dict .get (pool_name ).get_unhealthy_nodes () if pool_name else self ._total_unhealthy_nodes
193+ )
194+ return unhealthy_nodes
195+
196+ def retrieve_data (self , login_node_pool_names ):
197+ """Initialize the class with the information related to the login node fleet."""
198+ for pool_name in login_node_pool_names :
199+ self ._pool_status_dict [pool_name ] = PoolStatus (self ._stack_name , pool_name )
200+ self ._total_healthy_nodes = sum (
201+ (
202+ pool_status .get_healthy_nodes ()
203+ for pool_status in self ._pool_status_dict .values ()
204+ if pool_status .get_healthy_nodes ()
205+ )
206+ )
207+ self ._total_unhealthy_nodes = sum (
208+ (
209+ pool_status .get_unhealthy_nodes ()
210+ for pool_status in self ._pool_status_dict .values ()
211+ if pool_status .get_unhealthy_nodes ()
212+ )
213+ )
214+ self ._login_nodes_pool_available = any (
215+ (pool_status .get_pool_available () for pool_status in self ._pool_status_dict .values ())
216+ )
0 commit comments