forked from OCP-on-NERC/python-batchtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbp.py
More file actions
39 lines (32 loc) · 1.13 KB
/
bp.py
File metadata and controls
39 lines (32 loc) · 1.13 KB
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
30
31
32
33
34
35
36
37
38
39
from imports import *
def print_pods_for(job_name: str):
pods = oc.selector("pods", labels={"job-name": job_name}).objects()
if not pods:
print(f"No pods found for job {job_name}.")
return
print(f"\nPods for {job_name}:\n{'-' * 40}")
for pod in pods:
print(f"- {pod.model.metadata.name}")
def bp(job_names: list[str] | None = None) -> int:
try:
jobs = oc.selector("jobs").objects()
if not jobs:
print("No jobs found.")
return 0
job_dict = {job.model.metadata.name: job for job in jobs}
if job_names:
for name in job_names:
if name not in job_dict:
print(f"{name} does not exist; cannot fetch pod name.")
continue
print_pods_for(name)
else:
print("Displaying pods for all current batch jobs:\n")
for name in job_dict.keys():
print_pods_for(name)
except OpenShiftPythonException as e:
print("Error occurred while retrieving pods:")
print(e)
traceback.print_exc()
return 1
return 0