summaryrefslogtreecommitdiff
path: root/cmd/podman/ps.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/ps.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/ps.go')
-rw-r--r--cmd/podman/ps.go48
1 files changed, 26 insertions, 22 deletions
diff --git a/cmd/podman/ps.go b/cmd/podman/ps.go
index f2ea3939b..921490ba9 100644
--- a/cmd/podman/ps.go
+++ b/cmd/podman/ps.go
@@ -52,24 +52,23 @@ type psTemplateParams struct {
// psJSONParams will be populated by data from libpod.Container,
// the members of the struct are the sama data types as their sources.
type psJSONParams struct {
- ID string `json:"id"`
- Image string `json:"image"`
- ImageID string `json:"image_id"`
- Command []string `json:"command"`
- CreatedAt time.Time `json:"createdAt"`
- ExitCode int32 `json:"exitCode"`
- Exited bool `json:"exited"`
- RunningFor time.Duration `json:"runningFor"`
- Status string `json:"status"`
- PID int `json:"PID"`
- Ports []ocicni.PortMapping `json:"ports"`
- RootFsSize int64 `json:"rootFsSize,omitempty"`
- RWSize int64 `json:"rwSize,omitempty"`
- Names string `json:"names"`
- Labels fields.Set `json:"labels"`
- Mounts []string `json:"mounts"`
- ContainerRunning bool `json:"ctrRunning"`
- Namespaces *batchcontainer.Namespace `json:"namespace,omitempty"`
+ ID string `json:"id"`
+ Image string `json:"image"`
+ ImageID string `json:"image_id"`
+ Command []string `json:"command"`
+ CreatedAt time.Time `json:"createdAt"`
+ ExitCode int32 `json:"exitCode"`
+ Exited bool `json:"exited"`
+ RunningFor time.Duration `json:"runningFor"`
+ Status string `json:"status"`
+ PID int `json:"PID"`
+ Ports []ocicni.PortMapping `json:"ports"`
+ Size *batchcontainer.ContainerSize `json:"size,omitempty"`
+ Names string `json:"names"`
+ Labels fields.Set `json:"labels"`
+ Mounts []string `json:"mounts"`
+ ContainerRunning bool `json:"ctrRunning"`
+ Namespaces *batchcontainer.Namespace `json:"namespace,omitempty"`
}
// Type declaration and functions for sorting the PS output
@@ -115,7 +114,10 @@ func (a psSortedStatus) Less(i, j int) bool { return a.psSorted[i].Status < a.ps
type psSortedSize struct{ psSorted }
func (a psSortedSize) Less(i, j int) bool {
- return a.psSorted[i].RootFsSize < a.psSorted[j].RootFsSize
+ if a.psSorted[i].Size == nil || a.psSorted[j].Size == nil {
+ return false
+ }
+ return a.psSorted[i].Size.RootFsSize < a.psSorted[j].Size.RootFsSize
}
var (
@@ -497,7 +499,10 @@ func getTemplateOutput(psParams []psJSONParams, opts batchcontainer.PsOptions) (
ns = psParam.Namespaces
}
if opts.Size {
- size = units.HumanSizeWithPrecision(float64(psParam.RWSize), 3) + " (virtual " + units.HumanSizeWithPrecision(float64(psParam.RootFsSize), 3) + ")"
+ if psParam.Size == nil {
+ return nil, errors.Errorf("Container %s does not have a size struct", psParam.ID)
+ }
+ size = units.HumanSizeWithPrecision(float64(psParam.Size.RwSize), 3) + " (virtual " + units.HumanSizeWithPrecision(float64(psParam.Size.RootFsSize), 3) + ")"
}
runningFor := units.HumanDuration(psParam.RunningFor)
@@ -587,8 +592,7 @@ func getAndSortJSONParams(containers []*libpod.Container, opts batchcontainer.Ps
Status: batchInfo.ConState.String(),
PID: batchInfo.Pid,
Ports: batchInfo.ConConfig.PortMappings,
- RootFsSize: batchInfo.RootFsSize,
- RWSize: batchInfo.RwSize,
+ Size: batchInfo.Size,
Names: batchInfo.ConConfig.Name,
Labels: batchInfo.ConConfig.Labels,
Mounts: batchInfo.ConConfig.UserVolumes,