Skip to content

Commit dcd3da1

Browse files
[sos-spyre] Collect Podman outputs for all Spyre card users
Collect existing Podman command outputs for non-root Spyre card users. This ensures outputs are gathered for all members of the 'sentient' group. Signed-off-by: Sahithi Ravindranath <Sahithi.Ravindranath@ibm.com>
1 parent 1504c13 commit dcd3da1

1 file changed

Lines changed: 86 additions & 0 deletions

File tree

sos-plugin/spyre-external.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,90 @@ class SpyreExternal(Plugin, IndependentPlugin):
2828
card_vendor_ids = ["0x1014"]
2929
card_device_ids = ["0x06a7", "0x06a8"]
3030

31+
def get_podman_data(self):
32+
33+
# All spyre users must be part of sentient group
34+
groupname = "sentient"
35+
non_root_users = self.exec_cmd("getent group "+ groupname)
36+
if non_root_users['status'] == 0:
37+
users = [u.strip() for u in non_root_users['output'].split(':')[3].split(',') if u.strip()]
38+
for user in users:
39+
# since root user outputs are collected in podman plugin
40+
# skipping here
41+
if not user or user == 'root':
42+
continue
43+
command = "sudo -u "+ user
44+
validate_cmd = self.exec_cmd(f"{command} podman system df")
45+
if validate_cmd['status'] != 0:
46+
continue
47+
48+
self.add_cmd_tags({
49+
f'{command} podman images': 'podman_list_images',
50+
f'{command} podman ps': 'podman_list_containers'
51+
})
52+
53+
subcmds = [
54+
'info',
55+
'images',
56+
'image trust show',
57+
'images --digests',
58+
'pod ps',
59+
'port --all',
60+
'ps',
61+
'stats --no-stream --all',
62+
'version',
63+
'volume ls',
64+
'system df -v',
65+
]
66+
67+
self.add_cmd_output([f"{command} podman {s}" for s in subcmds],
68+
subdir=f'podman/{user}', tags='podman_commands')
69+
70+
# separately grab ps -s as this can take a *very* long time
71+
if self.get_option('size'):
72+
self.add_cmd_output(f'{command} podman ps -as', subdir=f'podman/{user}', priority=100)
73+
74+
pnets = self.collect_cmd_output(f'{command} podman network ls',
75+
subdir=f'podman/{user}', tags='podman_list_networks')
76+
if pnets['status'] == 0:
77+
nets = [pn.split()[0] for pn in pnets['output'].splitlines()[1:] if pn.strip()]
78+
self.add_cmd_output([
79+
f"{command} podman network inspect {net}" for net in nets
80+
], subdir=f'podman/{user}/networks', tags='podman_network_inspect')
81+
82+
containers = self.collect_cmd_output(f'{command} podman ps -a', subdir=f'podman/{user}')
83+
if containers['status'] == 0:
84+
cids = [container.split()[0] for container in containers['output'].splitlines()[1:] if container.strip()]
85+
self.add_cmd_output([
86+
f"{command} podman inspect {cid}" for cid in cids
87+
], subdir=f'podman/{user}/containers', tags='podman_container_inspect')
88+
if self.get_option('logs'):
89+
self.add_cmd_output([f"{command} podman logs -t {cid}" for cid in cids],
90+
subdir=f'podman/{user}/containers', priority=50)
91+
92+
images = self.collect_cmd_output(f'{command} podman images --no-trunc', subdir=f'podman/{user}')
93+
if images['status'] == 0:
94+
imageids = [
95+
image.split()[2] if image.split()[0].lower() == 'none' else f"{image.split()[0]}:{image.split()[1]}"
96+
for image in images['output'].splitlines()[1:] if image.strip()
97+
]
98+
self.add_cmd_output([
99+
f"{command} podman inspect {imageid}" for imageid in imageids
100+
], subdir=f'podman/{user}/images', tags='podman_image_inspect')
101+
self.add_cmd_output(
102+
[f"{command} podman image tree {imageid}" for imageid in imageids],
103+
subdir=f'podman/{user}/images/tree',
104+
tags='podman_image_tree'
105+
)
106+
107+
volumes = self.collect_cmd_output(f'{command} podman volume ls --format "{{{{.Name}}}}"', subdir=f'podman/{user}')
108+
if volumes['status'] == 0:
109+
vols = [v for v in volumes['output'].splitlines() if v.strip()]
110+
self.add_cmd_output([
111+
f"{command} podman volume inspect {vol}" for vol in vols
112+
], subdir=f'podman/{user}/volumes', tags='podman_volume_inspect')
113+
114+
31115
def setup(self):
32116
spyre_cards = self.get_spyre_cards()
33117

@@ -64,6 +148,8 @@ def setup(self):
64148
"/etc/security/limits.d/memlock.conf",
65149
])
66150

151+
self.get_podman_data()
152+
67153
def get_spyre_cards(self):
68154
context = pyudev.Context()
69155
spyre_cards_bus_ids = []

0 commit comments

Comments
 (0)