Parsers for podman
This module contains the following parsers:
PodmanPsAllJson - command podman ps --all --no-trunc --size --format=json
- class insights.parsers.podman.PodmanContainerSearch[source]
Bases:
objectMixin providing container search helpers over a flat
self.datalist of container dicts (as produced bypodman ps ... --format=json).- search_by_image(image: str, partial: bool = False) List[dict][source]
Search containers by image.
- Parameters:
image (str) -- The image to search for.
partial (bool) -- When
False(default) match the image exactly; whenTruematch containers whose image containsimage.
- Returns:
The matching raw container jsons (empty list if none match).
- Return type:
list
- Raises:
TypeError -- If
imageis not a string.ValueError -- If
imageis an empty string.
- search_by_name(name: str, partial: bool = False) List[dict][source]
Search containers by name.
- Parameters:
name (str) -- The container name to search for.
partial (bool) -- When
False(default) match the name exactly; whenTruematch containers whose name containsname.
- Returns:
The matching raw container jsons (empty list if none match).
- Return type:
list
- Raises:
TypeError -- If
nameis not a string.ValueError -- If
nameis an empty string.
- class insights.parsers.podman.PodmanPsAllJson(context)[source]
Bases:
JSONParser,PodmanContainerSearchClass for parsing the output of the
podman ps --all --no-trunc --size --format=jsoncommand.The output is a JSON array containing objects with container information.
Typical output of this command:
[ { "AutoRemove": false, "Command": [ "/usr/sbin/httpd", "-DFOREGROUND" ], "Created": "2024-01-15T10:30:45.123456789-05:00", "CreatedAt": "2024-01-15 10:30:45 -0500 EST", "Exited": false, "ExitedAt": -62135596800, "ExitCode": 0, "Id": "03e2861336a76e29155836113ff6560cb70780c32f95062642993b2b3d0fc216", "Image": "rhel7_httpd", "ImageID": "882ab98aae5394aebe91fe6d8a4297fa0387c3cfd421b2d892bddf218ac373b2", "IsInfra": false, "Labels": { "maintainer": "Red Hat" }, "Mounts": [], "Names": [ "angry_saha" ], "Namespaces": {}, "Networks": [ "podman" ], "Pid": 12345, "Pod": "", "PodName": "", "Ports": [ { "host_ip": "0.0.0.0", "container_port": 80, "host_port": 8080, "range": 1, "protocol": "tcp" } ], "Size": { "rootFsSize": 221554338, "rwSize": 0 }, "StartedAt": 1705330245, "State": "running", "Status": "Up 37 seconds" } ]
- data
A list containing the parsed container information as dictionaries
- Type:
list
Examples
>>> type(podman_ps_json.data) <class 'list'> >>> len(podman_ps_json.data) 2 >>> podman_ps_json.data[0]["Id"] '03e2861336a76e29155836113ff6560cb70780c32f95062642993b2b3d0fc216' >>> podman_ps_json.data[0]["State"] 'running' >>> podman_ps_json.data[0]["Names"] ['angry_saha'] >>> podman_ps_json.data[0]["Image"] 'rhel7_httpd' >>> len(podman_ps_json.search_by_name("angry_saha")) 1 >>> podman_ps_json.search_by_image("rhel7_httpd")[0]["Names"] ['angry_saha'] >>> len(podman_ps_json.search_by_image("httpd", partial=True)) 1