summaryrefslogtreecommitdiff
path: root/cmd/podman/batchcontainer/container.go
diff options
context:
space:
mode:
authorMatthew Heon <mheon@redhat.com>2018-07-13 11:51:06 -0400
committerMatthew Heon <mheon@redhat.com>2018-07-13 14:28:41 -0400
commit5b43a6a7ee6638b6d6cdb129321e42ce0dce6975 (patch)
tree00ed69a91ab6be06c7f3b5a10b15f7ab252a00e5 /cmd/podman/batchcontainer/container.go
parentf08fffa3061fd12763674138719f69290e143e3d (diff)
downloadpodman-5b43a6a7ee6638b6d6cdb129321e42ce0dce6975.tar.gz
podman-5b43a6a7ee6638b6d6cdb129321e42ce0dce6975.tar.bz2
podman-5b43a6a7ee6638b6d6cdb129321e42ce0dce6975.zip
Only print container size JSON if --size was requested
To do this, move it into a separate struct, and embed that in the JSON we return. Signed-off-by: Matthew Heon <mheon@redhat.com>
Diffstat (limited to 'cmd/podman/batchcontainer/container.go')
-rw-r--r--cmd/podman/batchcontainer/container.go48
1 files changed, 29 insertions, 19 deletions
diff --git a/cmd/podman/batchcontainer/container.go b/cmd/podman/batchcontainer/container.go
index 6f002f58a..017837a96 100644
--- a/cmd/podman/batchcontainer/container.go
+++ b/cmd/podman/batchcontainer/container.go
@@ -35,13 +35,13 @@ type PsOptions struct {
// BatchContainerStruct is the return obkect from BatchContainer and contains
// container related information
type BatchContainerStruct struct {
- ConConfig *libpod.ContainerConfig
- ConState libpod.ContainerStatus
- ExitCode int32
- Exited bool
- Pid int
- RootFsSize, RwSize int64
- StartedTime time.Time
+ ConConfig *libpod.ContainerConfig
+ ConState libpod.ContainerStatus
+ ExitCode int32
+ Exited bool
+ Pid int
+ StartedTime time.Time
+ Size *ContainerSize
}
// Namespace describes output for ps namespace
@@ -56,18 +56,25 @@ type Namespace struct {
UTS string `json:"uts,omitempty"`
}
+// ContainerSize holds the size of the container's root filesystem and top
+// read-write layer
+type ContainerSize struct {
+ RootFsSize int64 `json:"rootFsSize"`
+ RwSize int64 `json:"rwSize"`
+}
+
// BatchContainer is used in ps to reduce performance hits by "batching"
// locks.
func BatchContainerOp(ctr *libpod.Container, opts PsOptions) (BatchContainerStruct, error) {
var (
- conConfig *libpod.ContainerConfig
- conState libpod.ContainerStatus
- err error
- exitCode int32
- exited bool
- pid int
- rootFsSize, rwSize int64
- startedTime time.Time
+ conConfig *libpod.ContainerConfig
+ conState libpod.ContainerStatus
+ err error
+ exitCode int32
+ exited bool
+ pid int
+ size *ContainerSize
+ startedTime time.Time
)
batchErr := ctr.Batch(func(c *libpod.Container) error {
@@ -97,16 +104,20 @@ func BatchContainerOp(ctr *libpod.Container, opts PsOptions) (BatchContainerStru
}
}
if opts.Size {
- rootFsSize, err = c.RootFsSize()
+ size = new(ContainerSize)
+
+ rootFsSize, err := c.RootFsSize()
if err != nil {
logrus.Errorf("error getting root fs size for %q: %v", c.ID(), err)
}
- rwSize, err = c.RWSize()
+ rwSize, err := c.RWSize()
if err != nil {
logrus.Errorf("error getting rw size for %q: %v", c.ID(), err)
}
+ size.RootFsSize = rootFsSize
+ size.RwSize = rwSize
}
return nil
})
@@ -119,9 +130,8 @@ func BatchContainerOp(ctr *libpod.Container, opts PsOptions) (BatchContainerStru
ExitCode: exitCode,
Exited: exited,
Pid: pid,
- RootFsSize: rootFsSize,
- RwSize: rwSize,
StartedTime: startedTime,
+ Size: size,
}, nil
}