Skip to content

Commit 3581a05

Browse files
committed
[patch] Add sls.py
1 parent cd5ade5 commit 3581a05

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/mas/devops/ocp.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ def connect(server: str, token: str, skipVerify: bool = False) -> bool:
6161
return True
6262

6363

64+
def getNamespace(dynClient: DynamicClient, namespace: str) -> dict:
65+
"""
66+
Get a namespace
67+
"""
68+
namespaceAPI = dynClient.resources.get(api_version="v1", kind="Namespace")
69+
namespace = {}
70+
71+
try:
72+
namespace = namespaceAPI.get(name=namespace)
73+
logger.debug(f"Namespace {namespace} exists")
74+
except NotFoundError:
75+
logger.debug(f"Namespace {namespace} does not exist")
76+
77+
return namespace
78+
79+
6480
def createNamespace(dynClient: DynamicClient, namespace: str) -> bool:
6581
"""
6682
Create a namespace if it does not exist

src/mas/devops/sls.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import logging
2+
from openshift.dynamic import DynamicClient
3+
4+
logger = logging.getLogger(__name__)
5+
6+
def listSLSInstances(dynClient: DynamicClient) -> list:
7+
"""
8+
Get a list of SLS instances on the cluster
9+
"""
10+
slsAPI = dynClient.resources.get(api_version="sls.ibm.com/v1", kind="LicenseService")
11+
12+
licenseservices = slsAPI.get().to_dict()['items']
13+
14+
numSLS = len(licenseservices)
15+
16+
if numSLS == 1:
17+
logger.info(f"There is 1 SLS instance installed on this cluster:")
18+
logger.info(f" * {licenseservices[0]['metadata']['name']} ({{licenseservices[0]['metadata']['namespace']}}) v{licenseservices[0]['status']['versions']['reconciled']}")
19+
elif numSLS > 0:
20+
logger.info(f"There are {numSLS} SLS instances installed on this cluster:")
21+
for licenseservice in licenseservices:
22+
logger.info(f" * {licenseservice['metadata']['name']} ({{licenseservice['metadata']['namespace']}}) v{licenseservice['status']['versions']['reconciled']}")
23+
else:
24+
logger.info("There are no SLS instances installed on this cluster")
25+
return licenseservices

0 commit comments

Comments
 (0)