diff options
author | Jhon Honce <jhonce@redhat.com> | 2018-06-01 09:51:32 -0700 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-06-01 21:19:56 +0000 |
commit | 4f5e6728b713798dd0fe4d6f3c8b52e438285190 (patch) | |
tree | 2a5a127dead51dc4b850302f7955bff17ab66769 /contrib/python/examples/eg_latest_containers.py | |
parent | b6753238bcf2e996b1116c6f91e25a6688f835ea (diff) | |
download | podman-4f5e6728b713798dd0fe4d6f3c8b52e438285190.tar.gz podman-4f5e6728b713798dd0fe4d6f3c8b52e438285190.tar.bz2 podman-4f5e6728b713798dd0fe4d6f3c8b52e438285190.zip |
Provide examples for python podman API
Signed-off-by: Jhon Honce <jhonce@redhat.com>
Closes: #870
Approved by: rhatdan
Diffstat (limited to 'contrib/python/examples/eg_latest_containers.py')
-rw-r--r-- | contrib/python/examples/eg_latest_containers.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/contrib/python/examples/eg_latest_containers.py b/contrib/python/examples/eg_latest_containers.py new file mode 100644 index 000000000..446f670dd --- /dev/null +++ b/contrib/python/examples/eg_latest_containers.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 +"""Example: Show all containers created since midnight.""" + +from datetime import datetime, time, timezone + +import podman + +print('{}\n'.format(__doc__)) + + +midnight = datetime.combine(datetime.today(), time.min, tzinfo=timezone.utc) + +with podman.Client() as client: + for c in client.containers.list(): + created_at = podman.datetime_parse(c.createdat) + + if created_at > midnight: + print('{}: image: {} createdAt: {}'.format( + c.id[:12], c.image[:32], podman.datetime_format(created_at))) |