diff options
Diffstat (limited to 'contrib/python/examples')
-rw-r--r-- | contrib/python/examples/eg_attach.py | 18 | ||||
-rw-r--r-- | contrib/python/examples/eg_containers_by_image.py | 16 | ||||
-rw-r--r-- | contrib/python/examples/eg_image_list.py | 10 | ||||
-rw-r--r-- | contrib/python/examples/eg_inspect_fedora.py | 16 | ||||
-rw-r--r-- | contrib/python/examples/eg_latest_containers.py | 19 | ||||
-rw-r--r-- | contrib/python/examples/eg_new_image.py | 32 | ||||
-rwxr-xr-x | contrib/python/examples/run_example.sh | 43 |
7 files changed, 0 insertions, 154 deletions
diff --git a/contrib/python/examples/eg_attach.py b/contrib/python/examples/eg_attach.py deleted file mode 100644 index f5070dc53..000000000 --- a/contrib/python/examples/eg_attach.py +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env python3 -"""Example: Run top on Alpine container.""" - -import podman - -print('{}\n'.format(__doc__)) - -with podman.Client() as client: - id = client.images.pull('alpine:latest') - img = client.images.get(id) - cntr = img.create(detach=True, tty=True, command=['/usr/bin/top']) - cntr.attach(eot=4) - - try: - cntr.start() - print() - except (BrokenPipeError, KeyboardInterrupt): - print('\nContainer disconnected.') diff --git a/contrib/python/examples/eg_containers_by_image.py b/contrib/python/examples/eg_containers_by_image.py deleted file mode 100644 index bf4fdebf1..000000000 --- a/contrib/python/examples/eg_containers_by_image.py +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env python3 -"""Example: Show containers grouped by image id.""" - -from itertools import groupby - -import podman - -print('{}\n'.format(__doc__)) - -with podman.Client() as client: - ctnrs = sorted(client.containers.list(), key=lambda k: k.imageid) - for key, grp in groupby(ctnrs, key=lambda k: k.imageid): - print('Image: {}'.format(key)) - for c in grp: - print(' : container: {} created at: {}'.format( - c.id[:12], podman.datetime_format(c.createdat))) diff --git a/contrib/python/examples/eg_image_list.py b/contrib/python/examples/eg_image_list.py deleted file mode 100644 index ef31fd708..000000000 --- a/contrib/python/examples/eg_image_list.py +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env python3 -"""Example: Show all images on system.""" - -import podman - -print('{}\n'.format(__doc__)) - -with podman.Client() as client: - for img in client.images.list(): - print(img) diff --git a/contrib/python/examples/eg_inspect_fedora.py b/contrib/python/examples/eg_inspect_fedora.py deleted file mode 100644 index b5bbba46d..000000000 --- a/contrib/python/examples/eg_inspect_fedora.py +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env python3 -"""Example: Pull Fedora and inspect image and container.""" - -import podman - -print('{}\n'.format(__doc__)) - -with podman.Client() as client: - id = client.images.pull('registry.fedoraproject.org/fedora:28') - img = client.images.get(id) - print(img.inspect()) - - cntr = img.create() - print(cntr.inspect()) - - cntr.remove() diff --git a/contrib/python/examples/eg_latest_containers.py b/contrib/python/examples/eg_latest_containers.py deleted file mode 100644 index 446f670dd..000000000 --- a/contrib/python/examples/eg_latest_containers.py +++ /dev/null @@ -1,19 +0,0 @@ -#!/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))) diff --git a/contrib/python/examples/eg_new_image.py b/contrib/python/examples/eg_new_image.py deleted file mode 100644 index 21e076dcb..000000000 --- a/contrib/python/examples/eg_new_image.py +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env python3 -"""Example: Create new image from container.""" - -import sys - -import podman - - -def print_history(details): - """Format history data from an image, in a table.""" - for i, r in enumerate(details): - print( - '{}: {} {} {}'.format(i, r.id[:12], - podman.datetime_format(r.created), r.tags), - sep='\n') - print("-" * 25) - - -print('{}\n'.format(__doc__)) - -with podman.Client() as client: - ctnr = next( - (c for c in client.containers.list() if 'alpine' in c['image']), None) - - if ctnr: - print_history(client.images.get(ctnr.imageid).history()) - - # Make changes as we save the container to a new image - id = ctnr.commit('alpine-ash', changes=['CMD=/bin/ash']) - print_history(client.images.get(id).history()) - else: - print('Unable to find "alpine" container.', file=sys.stderr) diff --git a/contrib/python/examples/run_example.sh b/contrib/python/examples/run_example.sh deleted file mode 100755 index 0f6575073..000000000 --- a/contrib/python/examples/run_example.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash - -export PYTHONPATH=.. - -function examples { - for file in $@; do - python3 -c "import ast; f=open('"${file}"'); t=ast.parse(f.read()); print(ast.get_docstring(t) + ' -- "${file}"')" - done -} - -while getopts "lh" arg; do - case $arg in - l ) examples $(ls eg_*.py); exit 0 ;; - h ) echo 1>&2 $0 [-l] [-h] filename ; exit 2 ;; - esac -done -shift $((OPTIND-1)) - -# podman needs to play some games with resources -if [[ $(id -u) != 0 ]]; then - echo 1>&2 $0 must be run as root. - exit 2 -fi - -if ! systemctl --quiet is-active io.projectatomic.podman.socket; then - echo 1>&2 'podman is not running. systemctl enable --now io.projectatomic.podman.socket' - exit 1 -fi - -function cleanup { - podman rm $1 >/dev/null 2>&1 -} - -# Setup storage with an image and container -podman pull alpine:latest >/tmp/podman.output 2>&1 -CTNR=$(podman create alpine) -trap "cleanup $CTNR" EXIT - -if [[ -f $1 ]]; then - python3 $1 -else - python3 $1.py -fi |