forked from OCP-on-NERC/python-batchtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.py
More file actions
29 lines (22 loc) · 823 Bytes
/
helpers.py
File metadata and controls
29 lines (22 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import openshift_client as oc
def is_logged_in() -> bool:
try:
oc.invoke("whoami")
return True
except oc.OpenShiftPythonException:
return False
def pretty_print(pod: oc.APIObject) -> str:
formatted_logs: str = ""
try:
logs: dict[str, str] = pod.logs()
# ⋆ ˚。⋆୨୧˚ stringify and pretty print for readibility ⋆ ˚。⋆୨୧˚
formatted_logs = str(logs).replace("\\n", "\n")
except oc.OpenShiftPythonException as e:
print(f"Error occurred while retrieving logs: {e}")
return formatted_logs
def oc_delete(job_name: str) -> None:
try:
print(f"Deleting {job_name}")
oc.invoke("delete", ["job", job_name])
except oc.OpenShiftPythonException as e:
print(f"Error occurred while deleting job: {e}")