summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhaircommander <pehunt@redhat.com>2018-08-24 11:07:26 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-08-24 17:37:33 +0000
commit2cde9540f1f6b81fcf3e0b88198080445d8c384d (patch)
tree36759bc72c36585c504c7b8096adcefc92576561
parent72e41c81aaa2c5ea39f7b5bd1c0654937703a346 (diff)
downloadpodman-2cde9540f1f6b81fcf3e0b88198080445d8c384d.tar.gz
podman-2cde9540f1f6b81fcf3e0b88198080445d8c384d.tar.bz2
podman-2cde9540f1f6b81fcf3e0b88198080445d8c384d.zip
Fixed formatting and lowered verbosity of pod ps
CtrInfo now is formatted in the way originally intended. s/Number Of Containers/# Of Containers and s/Infra Container ID/Infra ID. Make json camel case. Signed-off-by: haircommander <pehunt@redhat.com> Closes: #1338 Approved by: mheon
-rw-r--r--cmd/podman/pod_ps.go48
1 files changed, 27 insertions, 21 deletions
diff --git a/cmd/podman/pod_ps.go b/cmd/podman/pod_ps.go
index e03794e7f..31830a01b 100644
--- a/cmd/podman/pod_ps.go
+++ b/cmd/podman/pod_ps.go
@@ -1,6 +1,7 @@
package main
import (
+ "fmt"
"reflect"
"sort"
"strconv"
@@ -57,8 +58,8 @@ type podPsTemplateParams struct {
Status string
Cgroup string
ContainerInfo string
- InfraContainerID string
- SharedNamespaces string
+ InfraID string
+ Namespaces string
}
// podPsJSONParams is used as a base structure for the psParams
@@ -70,12 +71,12 @@ type podPsJSONParams struct {
CreatedAt time.Time `json:"createdAt"`
ID string `json:"id"`
Name string `json:"name"`
- NumberOfContainers int `json:"numberofcontainers"`
+ NumberOfContainers int `json:"numberOfContainers"`
Status string `json:"status"`
- CtrsInfo []podPsCtrInfo `json:"containerinfo,omitempty"`
+ CtrsInfo []podPsCtrInfo `json:"containerInfo,omitempty"`
Cgroup string `json:"cgroup,omitempty"`
- InfraContainerID string `json:"infracontainerid,omitempty"`
- SharedNamespaces []string `json:"sharednamespaces,omitempty"`
+ InfraID string `json:"infraContainerId,omitempty"`
+ Namespaces []string `json:"namespaces,omitempty"`
}
// Type declaration and functions for sorting the pod PS output
@@ -351,14 +352,14 @@ func genPodPsFormat(c *cli.Context) string {
} else {
format = "table {{.ID}}\t{{.Name}}\t{{.Status}}\t{{.Created}}"
if c.Bool("namespace") {
- format += "\t{{.Cgroup}}\t{{.SharedNamespaces}}"
+ format += "\t{{.Cgroup}}\t{{.Namespaces}}"
}
if c.Bool("ctr-names") || c.Bool("ctr-ids") || c.Bool("ctr-status") {
format += "\t{{.ContainerInfo}}"
} else {
format += "\t{{.NumberOfContainers}}"
}
- format += "\t{{.InfraContainerID}}"
+ format += "\t{{.InfraID}}"
}
return format
}
@@ -387,6 +388,9 @@ func (p *podPsTemplateParams) podHeaderMap() map[string]string {
if value == "ID" {
value = "Pod" + value
}
+ if value == "NumberOfContainers" {
+ value = "#OfContainers"
+ }
values[key] = strings.ToUpper(splitCamelCase(value))
}
return values
@@ -418,7 +422,7 @@ func getPodTemplateOutput(psParams []podPsJSONParams, opts podPsOptions) ([]podP
for _, psParam := range psParams {
podID := psParam.ID
- infraID := psParam.InfraContainerID
+ infraID := psParam.InfraID
var ctrStr string
truncated := ""
@@ -431,21 +435,23 @@ func getPodTemplateOutput(psParams []podPsJSONParams, opts podPsOptions) ([]podP
infraID = shortID(infraID)
}
for _, ctrInfo := range psParam.CtrsInfo {
- ctrStr += "[ "
+ infoSlice := make([]string, 0)
if opts.IdsOfContainers {
if opts.NoTrunc {
- ctrStr += ctrInfo.Id
+ infoSlice = append(infoSlice, ctrInfo.Id)
} else {
- ctrStr += shortID(ctrInfo.Id)
+ infoSlice = append(infoSlice, shortID(ctrInfo.Id))
}
}
if opts.NamesOfContainers {
- ctrStr += ctrInfo.Name + " "
+ infoSlice = append(infoSlice, ctrInfo.Name)
}
if opts.StatusOfContainers {
- ctrStr += ctrInfo.Status + " "
+ infoSlice = append(infoSlice, ctrInfo.Status)
+ }
+ if len(infoSlice) != 0 {
+ ctrStr += fmt.Sprintf("[%s] ", strings.Join(infoSlice, ","))
}
- ctrStr += "] "
}
ctrStr += truncated
params := podPsTemplateParams{
@@ -456,8 +462,8 @@ func getPodTemplateOutput(psParams []podPsJSONParams, opts podPsOptions) ([]podP
NumberOfContainers: psParam.NumberOfContainers,
Cgroup: psParam.Cgroup,
ContainerInfo: ctrStr,
- InfraContainerID: infraID,
- SharedNamespaces: strings.Join(psParam.SharedNamespaces, ","),
+ InfraID: infraID,
+ Namespaces: strings.Join(psParam.Namespaces, ","),
}
psOutput = append(psOutput, params)
@@ -466,7 +472,7 @@ func getPodTemplateOutput(psParams []podPsJSONParams, opts podPsOptions) ([]podP
return psOutput, nil
}
-func getSharedNamespaces(pod *libpod.Pod) []string {
+func getNamespaces(pod *libpod.Pod) []string {
var shared []string
if pod.SharesPID() {
shared = append(shared, "pid")
@@ -510,7 +516,7 @@ func getAndSortPodJSONParams(pods []*libpod.Pod, opts podPsOptions, runtime *lib
return nil, err
}
- infraContainerID, err := pod.InfraContainerID()
+ infraID, err := pod.InfraContainerID()
if err != nil {
return nil, err
}
@@ -546,8 +552,8 @@ func getAndSortPodJSONParams(pods []*libpod.Pod, opts podPsOptions, runtime *lib
Cgroup: pod.CgroupParent(),
NumberOfContainers: ctrNum,
CtrsInfo: ctrsInfo,
- SharedNamespaces: getSharedNamespaces(pod),
- InfraContainerID: infraContainerID,
+ Namespaces: getNamespaces(pod),
+ InfraID: infraID,
}
psOutput = append(psOutput, params)