summaryrefslogtreecommitdiff
path: root/contrib/python/pypodman/lib/actions/rmi_action.py
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2018-07-12 19:26:14 -0700
committerJhon Honce <jhonce@redhat.com>2018-07-13 12:50:12 -0700
commit74ccd9ce5f29a1df4ffe70b4d8bd00c29d5d9d15 (patch)
tree75ba256d70545d79aa61d7c57c20df886be1555f /contrib/python/pypodman/lib/actions/rmi_action.py
parent44b523c946c88e540b50d7ba59f441b5f8e0bad0 (diff)
downloadpodman-74ccd9ce5f29a1df4ffe70b4d8bd00c29d5d9d15.tar.gz
podman-74ccd9ce5f29a1df4ffe70b4d8bd00c29d5d9d15.tar.bz2
podman-74ccd9ce5f29a1df4ffe70b4d8bd00c29d5d9d15.zip
Update python directories to better support setup.py
Signed-off-by: Jhon Honce <jhonce@redhat.com>
Diffstat (limited to 'contrib/python/pypodman/lib/actions/rmi_action.py')
-rw-r--r--contrib/python/pypodman/lib/actions/rmi_action.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/contrib/python/pypodman/lib/actions/rmi_action.py b/contrib/python/pypodman/lib/actions/rmi_action.py
new file mode 100644
index 000000000..91f0deeaf
--- /dev/null
+++ b/contrib/python/pypodman/lib/actions/rmi_action.py
@@ -0,0 +1,50 @@
+"""Remote client command for deleting images."""
+import sys
+
+import podman
+
+from .. import AbstractActionBase
+
+
+class Rmi(AbstractActionBase):
+ """Clas for removing images from storage."""
+
+ @classmethod
+ def subparser(cls, parent):
+ """Add Rmi command to parent parser."""
+ parser = parent.add_parser('rmi', help='delete image(s)')
+ parser.add_argument(
+ '-f',
+ '--force',
+ action='store_true',
+ help=('force delete of image(s) and associated containers.'
+ ' (default: %(default)s)'))
+ parser.add_argument('targets', nargs='*', help='image id(s) to delete')
+ parser.set_defaults(class_=cls, method='remove')
+
+ def __init__(self, args):
+ """Construct Rmi class."""
+ super().__init__(args)
+ if len(args.targets) < 1:
+ raise ValueError('You must supply at least one image id'
+ ' or name to be deleted.')
+
+ def remove(self):
+ """Remove image(s)."""
+ for id in self._args.targets:
+ try:
+ img = self.client.images.get(id)
+ img.remove(self._args.force)
+ print(id)
+ except podman.ImageNotFound as e:
+ sys.stdout.flush()
+ print(
+ 'Image {} not found.'.format(e.name),
+ file=sys.stderr,
+ flush=True)
+ except podman.ErrorOccurred as e:
+ sys.stdout.flush()
+ print(
+ '{}'.format(e.reason).capitalize(),
+ file=sys.stderr,
+ flush=True)