mirror of https://github.com/containers/podman.git
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
This commit is contained in:
parent
72e41c81aa
commit
2cde9540f1
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
@ -57,8 +58,8 @@ type podPsTemplateParams struct {
|
||||||
Status string
|
Status string
|
||||||
Cgroup string
|
Cgroup string
|
||||||
ContainerInfo string
|
ContainerInfo string
|
||||||
InfraContainerID string
|
InfraID string
|
||||||
SharedNamespaces string
|
Namespaces string
|
||||||
}
|
}
|
||||||
|
|
||||||
// podPsJSONParams is used as a base structure for the psParams
|
// podPsJSONParams is used as a base structure for the psParams
|
||||||
|
|
@ -70,12 +71,12 @@ type podPsJSONParams struct {
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
NumberOfContainers int `json:"numberofcontainers"`
|
NumberOfContainers int `json:"numberOfContainers"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
CtrsInfo []podPsCtrInfo `json:"containerinfo,omitempty"`
|
CtrsInfo []podPsCtrInfo `json:"containerInfo,omitempty"`
|
||||||
Cgroup string `json:"cgroup,omitempty"`
|
Cgroup string `json:"cgroup,omitempty"`
|
||||||
InfraContainerID string `json:"infracontainerid,omitempty"`
|
InfraID string `json:"infraContainerId,omitempty"`
|
||||||
SharedNamespaces []string `json:"sharednamespaces,omitempty"`
|
Namespaces []string `json:"namespaces,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type declaration and functions for sorting the pod PS output
|
// Type declaration and functions for sorting the pod PS output
|
||||||
|
|
@ -351,14 +352,14 @@ func genPodPsFormat(c *cli.Context) string {
|
||||||
} else {
|
} else {
|
||||||
format = "table {{.ID}}\t{{.Name}}\t{{.Status}}\t{{.Created}}"
|
format = "table {{.ID}}\t{{.Name}}\t{{.Status}}\t{{.Created}}"
|
||||||
if c.Bool("namespace") {
|
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") {
|
if c.Bool("ctr-names") || c.Bool("ctr-ids") || c.Bool("ctr-status") {
|
||||||
format += "\t{{.ContainerInfo}}"
|
format += "\t{{.ContainerInfo}}"
|
||||||
} else {
|
} else {
|
||||||
format += "\t{{.NumberOfContainers}}"
|
format += "\t{{.NumberOfContainers}}"
|
||||||
}
|
}
|
||||||
format += "\t{{.InfraContainerID}}"
|
format += "\t{{.InfraID}}"
|
||||||
}
|
}
|
||||||
return format
|
return format
|
||||||
}
|
}
|
||||||
|
|
@ -387,6 +388,9 @@ func (p *podPsTemplateParams) podHeaderMap() map[string]string {
|
||||||
if value == "ID" {
|
if value == "ID" {
|
||||||
value = "Pod" + value
|
value = "Pod" + value
|
||||||
}
|
}
|
||||||
|
if value == "NumberOfContainers" {
|
||||||
|
value = "#OfContainers"
|
||||||
|
}
|
||||||
values[key] = strings.ToUpper(splitCamelCase(value))
|
values[key] = strings.ToUpper(splitCamelCase(value))
|
||||||
}
|
}
|
||||||
return values
|
return values
|
||||||
|
|
@ -418,7 +422,7 @@ func getPodTemplateOutput(psParams []podPsJSONParams, opts podPsOptions) ([]podP
|
||||||
|
|
||||||
for _, psParam := range psParams {
|
for _, psParam := range psParams {
|
||||||
podID := psParam.ID
|
podID := psParam.ID
|
||||||
infraID := psParam.InfraContainerID
|
infraID := psParam.InfraID
|
||||||
var ctrStr string
|
var ctrStr string
|
||||||
|
|
||||||
truncated := ""
|
truncated := ""
|
||||||
|
|
@ -431,21 +435,23 @@ func getPodTemplateOutput(psParams []podPsJSONParams, opts podPsOptions) ([]podP
|
||||||
infraID = shortID(infraID)
|
infraID = shortID(infraID)
|
||||||
}
|
}
|
||||||
for _, ctrInfo := range psParam.CtrsInfo {
|
for _, ctrInfo := range psParam.CtrsInfo {
|
||||||
ctrStr += "[ "
|
infoSlice := make([]string, 0)
|
||||||
if opts.IdsOfContainers {
|
if opts.IdsOfContainers {
|
||||||
if opts.NoTrunc {
|
if opts.NoTrunc {
|
||||||
ctrStr += ctrInfo.Id
|
infoSlice = append(infoSlice, ctrInfo.Id)
|
||||||
} else {
|
} else {
|
||||||
ctrStr += shortID(ctrInfo.Id)
|
infoSlice = append(infoSlice, shortID(ctrInfo.Id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if opts.NamesOfContainers {
|
if opts.NamesOfContainers {
|
||||||
ctrStr += ctrInfo.Name + " "
|
infoSlice = append(infoSlice, ctrInfo.Name)
|
||||||
}
|
}
|
||||||
if opts.StatusOfContainers {
|
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
|
ctrStr += truncated
|
||||||
params := podPsTemplateParams{
|
params := podPsTemplateParams{
|
||||||
|
|
@ -456,8 +462,8 @@ func getPodTemplateOutput(psParams []podPsJSONParams, opts podPsOptions) ([]podP
|
||||||
NumberOfContainers: psParam.NumberOfContainers,
|
NumberOfContainers: psParam.NumberOfContainers,
|
||||||
Cgroup: psParam.Cgroup,
|
Cgroup: psParam.Cgroup,
|
||||||
ContainerInfo: ctrStr,
|
ContainerInfo: ctrStr,
|
||||||
InfraContainerID: infraID,
|
InfraID: infraID,
|
||||||
SharedNamespaces: strings.Join(psParam.SharedNamespaces, ","),
|
Namespaces: strings.Join(psParam.Namespaces, ","),
|
||||||
}
|
}
|
||||||
|
|
||||||
psOutput = append(psOutput, params)
|
psOutput = append(psOutput, params)
|
||||||
|
|
@ -466,7 +472,7 @@ func getPodTemplateOutput(psParams []podPsJSONParams, opts podPsOptions) ([]podP
|
||||||
return psOutput, nil
|
return psOutput, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSharedNamespaces(pod *libpod.Pod) []string {
|
func getNamespaces(pod *libpod.Pod) []string {
|
||||||
var shared []string
|
var shared []string
|
||||||
if pod.SharesPID() {
|
if pod.SharesPID() {
|
||||||
shared = append(shared, "pid")
|
shared = append(shared, "pid")
|
||||||
|
|
@ -510,7 +516,7 @@ func getAndSortPodJSONParams(pods []*libpod.Pod, opts podPsOptions, runtime *lib
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
infraContainerID, err := pod.InfraContainerID()
|
infraID, err := pod.InfraContainerID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -546,8 +552,8 @@ func getAndSortPodJSONParams(pods []*libpod.Pod, opts podPsOptions, runtime *lib
|
||||||
Cgroup: pod.CgroupParent(),
|
Cgroup: pod.CgroupParent(),
|
||||||
NumberOfContainers: ctrNum,
|
NumberOfContainers: ctrNum,
|
||||||
CtrsInfo: ctrsInfo,
|
CtrsInfo: ctrsInfo,
|
||||||
SharedNamespaces: getSharedNamespaces(pod),
|
Namespaces: getNamespaces(pod),
|
||||||
InfraContainerID: infraContainerID,
|
InfraID: infraID,
|
||||||
}
|
}
|
||||||
|
|
||||||
psOutput = append(psOutput, params)
|
psOutput = append(psOutput, params)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue