aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2018-01-23 21:15:02 -0500
committerGitHub <noreply@github.com>2018-01-23 21:15:02 -0500
commit274908fd1349872cd1a661483c100e3a7a837da0 (patch)
tree483deef066982c24729a71713638e95802ecb278
parent2803435624d21946d83b52db090f53996807e0bf (diff)
parentc04fb6c5643795d30208ae041be6adf747c2ecdc (diff)
downloadpodman-274908fd1349872cd1a661483c100e3a7a837da0.tar.gz
podman-274908fd1349872cd1a661483c100e3a7a837da0.tar.bz2
podman-274908fd1349872cd1a661483c100e3a7a837da0.zip
Merge pull request #251 from baude/psbatch
Use batched operations in ps
-rw-r--r--cmd/podman/ps.go45
1 files changed, 30 insertions, 15 deletions
diff --git a/cmd/podman/ps.go b/cmd/podman/ps.go
index ef5d40c43..be6c5aef5 100644
--- a/cmd/podman/ps.go
+++ b/cmd/podman/ps.go
@@ -396,23 +396,38 @@ func (p *psTemplateParams) headerMap() map[string]string {
// getTemplateOutput returns the modified container information
func getTemplateOutput(containers []*libpod.Container, opts psOptions) ([]psTemplateParams, error) {
- var psOutput []psTemplateParams
- var status string
+ var (
+ psOutput []psTemplateParams
+ status, ctrID string
+ conConfig *libpod.ContainerConfig
+ conState libpod.ContainerStatus
+ err error
+ exitCode int32
+ pid int
+ )
+
for _, ctr := range containers {
- ctrID := ctr.ID()
- conConfig := ctr.Config()
- conState, err := ctr.State()
- if err != nil {
- return psOutput, errors.Wrapf(err, "unable to obtain container state")
- }
- exitCode, err := ctr.ExitCode()
- if err != nil {
- return psOutput, errors.Wrapf(err, "unable to obtain container exit code")
- }
- pid, err := ctr.PID()
- if err != nil {
- return psOutput, errors.Wrapf(err, "unable to obtain container pid")
+ batchErr := ctr.Batch(func(c *libpod.Container) error {
+ ctrID = c.ID()
+ conConfig = c.Config()
+ conState, err = c.State()
+ if err != nil {
+ return errors.Wrapf(err, "unable to obtain container state")
+ }
+ exitCode, err = c.ExitCode()
+ if err != nil {
+ return errors.Wrapf(err, "unable to obtain container exit code")
+ }
+ pid, err = c.PID()
+ if err != nil {
+ return errors.Wrapf(err, "unable to obtain container pid")
+ }
+ return nil
+ })
+ if batchErr != nil {
+ return nil, err
}
+
runningFor := units.HumanDuration(time.Since(conConfig.CreatedTime))
createdAt := runningFor + " ago"
imageName := conConfig.RootfsImageName