@@ -64,6 +64,9 @@ def setup(self):
6464 "/etc/security/limits.d/memlock.conf" ,
6565 ])
6666
67+ # collect podman data for non root spyre users
68+ self .get_podman_data ()
69+
6770 def get_spyre_cards (self ):
6871 context = pyudev .Context ()
6972 spyre_cards_bus_ids = []
@@ -81,4 +84,88 @@ def get_spyre_cards(self):
8184
8285 return spyre_cards_bus_ids
8386
87+ def get_podman_data (self ):
88+
89+ # All spyre users must be part of sentient group
90+ groupname = "sentient"
91+ non_root_users = self .exec_cmd ("getent group " + groupname )
92+ if non_root_users ['status' ] == 0 :
93+ users = [u .strip () for u in non_root_users ['output' ].split (':' )[3 ].split (',' ) if u .strip ()]
94+ for user in users :
95+ # since root user outputs are collected in podman plugin
96+ # skipping here
97+ if not user or user == 'root' :
98+ continue
99+ command = "sudo -u " + user
100+ validate_cmd = self .exec_cmd (f"{ command } podman system df" )
101+ if validate_cmd ['status' ] != 0 :
102+ continue
103+
104+ self .add_cmd_tags ({
105+ f'{ command } podman images' : 'podman_list_images' ,
106+ f'{ command } podman ps' : 'podman_list_containers'
107+ })
108+
109+ subcmds = [
110+ 'info' ,
111+ 'images' ,
112+ 'image trust show' ,
113+ 'images --digests' ,
114+ 'pod ps' ,
115+ 'port --all' ,
116+ 'ps' ,
117+ 'stats --no-stream --all' ,
118+ 'version' ,
119+ 'volume ls' ,
120+ 'system df -v' ,
121+ ]
122+
123+ self .add_cmd_output ([f"{ command } podman { s } " for s in subcmds ],
124+ subdir = f'podman/{ user } ' , tags = 'podman_commands' )
125+
126+ # separately grab ps -s as this can take a *very* long time
127+ if self .get_option ('size' ):
128+ self .add_cmd_output (f'{ command } podman ps -as' , subdir = f'podman/{ user } ' , priority = 100 )
129+
130+ pnets = self .collect_cmd_output (f'{ command } podman network ls' ,
131+ subdir = f'podman/{ user } ' , tags = 'podman_list_networks' )
132+ if pnets ['status' ] == 0 :
133+ nets = [pn .split ()[0 ] for pn in pnets ['output' ].splitlines ()[1 :] if pn .strip ()]
134+ self .add_cmd_output ([
135+ f"{ command } podman network inspect { net } " for net in nets
136+ ], subdir = f'podman/{ user } /networks' , tags = 'podman_network_inspect' )
137+
138+ containers = self .collect_cmd_output (f'{ command } podman ps -a' , subdir = f'podman/{ user } ' )
139+ if containers ['status' ] == 0 :
140+ cids = [container .split ()[0 ] for container in containers ['output' ].splitlines ()[1 :] if container .strip ()]
141+ self .add_cmd_output ([
142+ f"{ command } podman inspect { cid } " for cid in cids
143+ ], subdir = f'podman/{ user } /containers' , tags = 'podman_container_inspect' )
144+ if self .get_option ('logs' ):
145+ self .add_cmd_output ([f"{ command } podman logs -t { cid } " for cid in cids ],
146+ subdir = f'podman/{ user } /containers' , priority = 50 )
147+
148+ images = self .collect_cmd_output (f'{ command } podman images --no-trunc' , subdir = f'podman/{ user } ' )
149+ if images ['status' ] == 0 :
150+ imageids = [
151+ image .split ()[2 ] if image .split ()[0 ].lower () == 'none' else f"{ image .split ()[0 ]} :{ image .split ()[1 ]} "
152+ for image in images ['output' ].splitlines ()[1 :] if image .strip ()
153+ ]
154+ self .add_cmd_output ([
155+ f"{ command } podman inspect { imageid } " for imageid in imageids
156+ ], subdir = f'podman/{ user } /images' , tags = 'podman_image_inspect' )
157+ self .add_cmd_output (
158+ [f"{ command } podman image tree { imageid } " for imageid in imageids ],
159+ subdir = f'podman/{ user } /images/tree' ,
160+ tags = 'podman_image_tree'
161+ )
162+
163+ volumes = self .collect_cmd_output (f'{ command } podman volume ls --format "{{{{.Name}}}}"' , subdir = f'podman/{ user } ' )
164+ if volumes ['status' ] == 0 :
165+ vols = [v for v in volumes ['output' ].splitlines () if v .strip ()]
166+ self .add_cmd_output ([
167+ f"{ command } podman volume inspect { vol } " for vol in vols
168+ ], subdir = f'podman/{ user } /volumes' , tags = 'podman_volume_inspect' )
169+
170+
84171# vim: set et ts=4 sw=4 :
0 commit comments