From 19ed620b78e3104034b6c46dcc239c5e9bea1720 Mon Sep 17 00:00:00 2001 From: Josef Harte Date: Fri, 5 Sep 2025 11:32:05 +0100 Subject: [PATCH 1/2] function to list AI Service instances --- src/mas/devops/mas.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/mas/devops/mas.py b/src/mas/devops/mas.py index 46419753..c9e8835f 100644 --- a/src/mas/devops/mas.py +++ b/src/mas/devops/mas.py @@ -134,6 +134,22 @@ def listMasInstances(dynClient: DynamicClient) -> list: return suites +def listAiServiceInstances(dynClient: DynamicClient) -> list: + """ + Get a list of AI Service instances on the cluster + """ + api = dynClient.resources.get(api_version="aiservice.ibm.com/v1", kind="AIServiceApp") + + instances = api.get().to_dict()['items'] + if len(instances) > 0: + logger.info(f"There are {len(instances)} AI Service instances installed on this cluster:") + for instance in instances: + logger.info(f" * {instance['metadata']['name']} v{instance['status']['versions']['reconciled']}") + else: + logger.info("There are no AI Service instances installed on this cluster") + return instances + + def getWorkspaceId(dynClient: DynamicClient, instanceId: str) -> str: """ Get the MAS workspace ID for namespace "mas-{instanceId}-core" From f76af339a3ff76ad78320ea894037567cdd198d6 Mon Sep 17 00:00:00 2001 From: Josef Harte Date: Mon, 8 Sep 2025 13:48:26 +0100 Subject: [PATCH 2/2] refactor --- src/mas/devops/mas.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/mas/devops/mas.py b/src/mas/devops/mas.py index c9e8835f..4a7ca8c6 100644 --- a/src/mas/devops/mas.py +++ b/src/mas/devops/mas.py @@ -122,31 +122,28 @@ def listMasInstances(dynClient: DynamicClient) -> list: """ Get a list of MAS instances on the cluster """ - suitesAPI = dynClient.resources.get(api_version="core.mas.ibm.com/v1", kind="Suite") - - suites = suitesAPI.get().to_dict()['items'] - if len(suites) > 0: - logger.info(f"There are {len(suites)} MAS instances installed on this cluster:") - for suite in suites: - logger.info(f" * {suite['metadata']['name']} v{suite['status']['versions']['reconciled']}") - else: - logger.info("There are no MAS instances installed on this cluster") - return suites + return listInstances(dynClient, "core.mas.ibm.com/v1", "Suite") def listAiServiceInstances(dynClient: DynamicClient) -> list: """ Get a list of AI Service instances on the cluster """ - api = dynClient.resources.get(api_version="aiservice.ibm.com/v1", kind="AIServiceApp") + return listInstances(dynClient, "aiservice.ibm.com/v1", "AIServiceApp") + +def listInstances(dynClient: DynamicClient, apiVersion: str, kind: str) -> list: + """ + Get a list of instances of a particular CR on the cluster + """ + api = dynClient.resources.get(api_version=apiVersion, kind=kind) instances = api.get().to_dict()['items'] if len(instances) > 0: - logger.info(f"There are {len(instances)} AI Service instances installed on this cluster:") - for instance in instances: - logger.info(f" * {instance['metadata']['name']} v{instance['status']['versions']['reconciled']}") + logger.info(f"There are {len(instances)} {kind} instances installed on this cluster:") + for instance in instances: + logger.info(f" * {instance['metadata']['name']} v{instance['status']['versions']['reconciled']}") else: - logger.info("There are no AI Service instances installed on this cluster") + logger.info(f"There are no {kind} instances installed on this cluster") return instances