diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2018-11-28 09:27:11 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-28 09:27:11 -0800 |
commit | d3bc70d5d02181649032da682fe09418425c9031 (patch) | |
tree | d97eb5df97ed69bededce62bc11947759178f17e /contrib | |
parent | 22d53e2b546e541646c8aec06fa4eb1f61904300 (diff) | |
parent | 2a6b683673ad854ff671921273feac11a5d57a15 (diff) | |
download | podman-d3bc70d5d02181649032da682fe09418425c9031.tar.gz podman-d3bc70d5d02181649032da682fe09418425c9031.tar.bz2 podman-d3bc70d5d02181649032da682fe09418425c9031.zip |
Merge pull request #1851 from jwhonce/wip/cmd
Add support for --all in pypodman ps command
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/python/pypodman/pypodman/lib/actions/ps_action.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/contrib/python/pypodman/pypodman/lib/actions/ps_action.py b/contrib/python/pypodman/pypodman/lib/actions/ps_action.py index cd7a7947d..62ceb2e67 100644 --- a/contrib/python/pypodman/pypodman/lib/actions/ps_action.py +++ b/contrib/python/pypodman/pypodman/lib/actions/ps_action.py @@ -16,6 +16,7 @@ class Ps(AbstractActionBase): """Add Images command to parent parser.""" parser = parent.add_parser('ps', help='list containers') super().subparser(parser) + parser.add_argument( '--sort', choices=('createdat', 'id', 'image', 'names', 'runningfor', 'size', @@ -32,9 +33,9 @@ class Ps(AbstractActionBase): self.columns = OrderedDict({ 'id': - ReportColumn('id', 'CONTAINER ID', 14), + ReportColumn('id', 'CONTAINER ID', 12), 'image': - ReportColumn('image', 'IMAGE', 30), + ReportColumn('image', 'IMAGE', 31), 'command': ReportColumn('column', 'COMMAND', 20), 'createdat': @@ -49,10 +50,15 @@ class Ps(AbstractActionBase): def list(self): """List containers.""" + if self._args.all: + ictnrs = self.client.containers.list() + else: + ictnrs = filter( + lambda c: podman.FoldedString(c['status']) == 'running', + self.client.containers.list()) + # TODO: Verify sorting on dates and size - ctnrs = sorted( - self.client.containers.list(), - key=operator.attrgetter(self._args.sort)) + ctnrs = sorted(ictnrs, key=operator.attrgetter(self._args.sort)) if not ctnrs: return @@ -65,9 +71,6 @@ class Ps(AbstractActionBase): 'createdat': humanize.naturaldate(podman.datetime_parse(ctnr.createdat)), }) - - if self._args.truncate: - fields.update({'image': ctnr.image[-30:]}) rows.append(fields) with Report(self.columns, heading=self._args.heading) as report: |