Skip to content

Commit bb15e73

Browse files
committed
[major] Tidy up package modules
1 parent 603e974 commit bb15e73

File tree

10 files changed

+520
-452
lines changed

10 files changed

+520
-452
lines changed

src/mas/devops/aiservice.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# *****************************************************************************
2+
# Copyright (c) 2025 IBM Corporation and other Contributors.
3+
#
4+
# All rights reserved. This program and the accompanying materials
5+
# are made available under the terms of the Eclipse Public License v1.0
6+
# which accompanies this distribution, and is available at
7+
# http://www.eclipse.org/legal/epl-v10.html
8+
#
9+
# *****************************************************************************
10+
11+
import logging
12+
from openshift.dynamic import DynamicClient
13+
from openshift.dynamic.exceptions import NotFoundError, ResourceNotFoundError, UnauthorizedError
14+
15+
from .ocp import listInstances
16+
from .olm import getSubscription
17+
18+
logger = logging.getLogger(__name__)
19+
20+
21+
def listAiServiceInstances(dynClient: DynamicClient) -> list:
22+
"""
23+
Get a list of AI Service instances on the cluster
24+
"""
25+
return listInstances(dynClient, "aiservice.ibm.com/v1", "AIServiceApp")
26+
27+
28+
def verifyAiServiceInstance(dynClient: DynamicClient, instanceId: str) -> bool:
29+
"""
30+
Validate that the chosen AI Service instance exists
31+
"""
32+
try:
33+
aiserviceAPI = dynClient.resources.get(api_version="aiservice.ibm.com/v1", kind="AIServiceApp")
34+
aiserviceAPI.get(name=instanceId, namespace=f"aiservice-{instanceId}")
35+
return True
36+
except NotFoundError:
37+
print("NOT FOUND")
38+
return False
39+
except ResourceNotFoundError:
40+
# The AIServiceApp CRD has not even been installed in the cluster
41+
print("RESOURCE NOT FOUND")
42+
return False
43+
except UnauthorizedError as e:
44+
logger.error(f"Error: Unable to verify AI Service instance due to failed authorization: {e}")
45+
return False
46+
47+
48+
def getAiserviceChannel(dynClient: DynamicClient, instanceId: str) -> str:
49+
"""
50+
Get the AI Service channel from the subscription
51+
"""
52+
aiserviceSubscription = getSubscription(dynClient, f"aiservice-{instanceId}", "ibm-aiservice")
53+
if aiserviceSubscription is None:
54+
return None
55+
else:
56+
return aiserviceSubscription.spec.channel

0 commit comments

Comments
 (0)