@@ -122,31 +122,28 @@ def listMasInstances(dynClient: DynamicClient) -> list:
122122 """
123123 Get a list of MAS instances on the cluster
124124 """
125- suitesAPI = dynClient .resources .get (api_version = "core.mas.ibm.com/v1" , kind = "Suite" )
126-
127- suites = suitesAPI .get ().to_dict ()['items' ]
128- if len (suites ) > 0 :
129- logger .info (f"There are { len (suites )} MAS instances installed on this cluster:" )
130- for suite in suites :
131- logger .info (f" * { suite ['metadata' ]['name' ]} v{ suite ['status' ]['versions' ]['reconciled' ]} " )
132- else :
133- logger .info ("There are no MAS instances installed on this cluster" )
134- return suites
125+ return listInstances (dynClient , "core.mas.ibm.com/v1" , "Suite" )
135126
136127
137128def listAiServiceInstances (dynClient : DynamicClient ) -> list :
138129 """
139130 Get a list of AI Service instances on the cluster
140131 """
141- api = dynClient .resources .get (api_version = "aiservice.ibm.com/v1" , kind = "AIServiceApp" )
132+ return listInstances (dynClient , "aiservice.ibm.com/v1" , "AIServiceApp" )
133+
142134
135+ def listInstances (dynClient : DynamicClient , apiVersion : str , kind : str ) -> list :
136+ """
137+ Get a list of instances of a particular CR on the cluster
138+ """
139+ api = dynClient .resources .get (api_version = apiVersion , kind = kind )
143140 instances = api .get ().to_dict ()['items' ]
144141 if len (instances ) > 0 :
145- logger .info (f"There are { len (instances )} AI Service instances installed on this cluster:" )
146- for instance in instances :
147- logger .info (f" * { instance ['metadata' ]['name' ]} v{ instance ['status' ]['versions' ]['reconciled' ]} " )
142+ logger .info (f"There are { len (instances )} { kind } instances installed on this cluster:" )
143+ for instance in instances :
144+ logger .info (f" * { instance ['metadata' ]['name' ]} v{ instance ['status' ]['versions' ]['reconciled' ]} " )
148145 else :
149- logger .info ("There are no AI Service instances installed on this cluster" )
146+ logger .info (f "There are no { kind } instances installed on this cluster" )
150147 return instances
151148
152149
0 commit comments