stuff-from-scratch/infra/src/ntk_infra/podman_interface.py

32 lines
1,006 B
Python
Raw Normal View History

2022-11-30 13:45:59 +00:00
#import podman
"""Demonstrate PodmanClient."""
import json
from podman import PodmanClient
# Provide a URI path for the libpod service. In libpod, the URI can be a unix
# domain socket(UDS) or TCP. The TCP connection has not been implemented in this
# package yet.
uri = "unix:///run/user/1000/podman/podman.sock"
with PodmanClient(base_url=uri) as client:
version = client.version()
print("Release: ", version["Version"])
print("Compatible API: ", version["ApiVersion"])
print("Podman API: ", version["Components"][0]["Details"]["APIVersion"], "\n")
# get all images
for image in client.images.list():
print(image, image.id, "\n")
# find all containers
for container in client.containers.list():
first_name = container['Names'][0]
container = client.containers.get(first_name)
print(container, container.id, "\n")
# available fields
print(sorted(container.attrs.keys()))
print(json.dumps(client.df(), indent=4))