mirror of
https://github.com/containers/podman.git
synced 2025-06-22 09:58:10 +08:00
Major fixes to podman ps --format=json output
A number of fields were never being populated. Populate them as best we can. Add a new field, exited, to indicate whether the exit code has meaning (IE, the container has exited). Fix handling of running time - it stops ticking when the container stops. There is further work needed here, I suspect. Signed-off-by: Matthew Heon <mheon@redhat.com>
This commit is contained in:
@ -38,6 +38,7 @@ type BatchContainerStruct struct {
|
|||||||
ConConfig *libpod.ContainerConfig
|
ConConfig *libpod.ContainerConfig
|
||||||
ConState libpod.ContainerStatus
|
ConState libpod.ContainerStatus
|
||||||
ExitCode int32
|
ExitCode int32
|
||||||
|
Exited bool
|
||||||
Pid int
|
Pid int
|
||||||
RootFsSize, RwSize int64
|
RootFsSize, RwSize int64
|
||||||
StartedTime time.Time
|
StartedTime time.Time
|
||||||
@ -63,6 +64,7 @@ func BatchContainerOp(ctr *libpod.Container, opts PsOptions) (BatchContainerStru
|
|||||||
conState libpod.ContainerStatus
|
conState libpod.ContainerStatus
|
||||||
err error
|
err error
|
||||||
exitCode int32
|
exitCode int32
|
||||||
|
exited bool
|
||||||
pid int
|
pid int
|
||||||
rootFsSize, rwSize int64
|
rootFsSize, rwSize int64
|
||||||
startedTime time.Time
|
startedTime time.Time
|
||||||
@ -75,7 +77,7 @@ func BatchContainerOp(ctr *libpod.Container, opts PsOptions) (BatchContainerStru
|
|||||||
return errors.Wrapf(err, "unable to obtain container state")
|
return errors.Wrapf(err, "unable to obtain container state")
|
||||||
}
|
}
|
||||||
|
|
||||||
exitCode, _, err = c.ExitCode()
|
exitCode, exited, err = c.ExitCode()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "unable to obtain container exit code")
|
return errors.Wrapf(err, "unable to obtain container exit code")
|
||||||
}
|
}
|
||||||
@ -115,6 +117,7 @@ func BatchContainerOp(ctr *libpod.Container, opts PsOptions) (BatchContainerStru
|
|||||||
ConConfig: conConfig,
|
ConConfig: conConfig,
|
||||||
ConState: conState,
|
ConState: conState,
|
||||||
ExitCode: exitCode,
|
ExitCode: exitCode,
|
||||||
|
Exited: exited,
|
||||||
Pid: pid,
|
Pid: pid,
|
||||||
RootFsSize: rootFsSize,
|
RootFsSize: rootFsSize,
|
||||||
RwSize: rwSize,
|
RwSize: rwSize,
|
||||||
|
@ -58,6 +58,7 @@ type psJSONParams struct {
|
|||||||
Command []string `json:"command"`
|
Command []string `json:"command"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
ExitCode int32 `json:"exitCode"`
|
ExitCode int32 `json:"exitCode"`
|
||||||
|
Exited bool `json:"exited"`
|
||||||
RunningFor time.Duration `json:"runningFor"`
|
RunningFor time.Duration `json:"runningFor"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
PID int `json:"PID"`
|
PID int `json:"PID"`
|
||||||
@ -576,22 +577,26 @@ func getAndSortJSONParams(containers []*libpod.Container, opts batchcontainer.Ps
|
|||||||
ns = batchcontainer.GetNamespaces(batchInfo.Pid)
|
ns = batchcontainer.GetNamespaces(batchInfo.Pid)
|
||||||
}
|
}
|
||||||
params := psJSONParams{
|
params := psJSONParams{
|
||||||
ID: ctr.ID(),
|
ID: ctr.ID(),
|
||||||
Image: batchInfo.ConConfig.RootfsImageName,
|
Image: batchInfo.ConConfig.RootfsImageName,
|
||||||
ImageID: batchInfo.ConConfig.RootfsImageID,
|
ImageID: batchInfo.ConConfig.RootfsImageID,
|
||||||
Command: batchInfo.ConConfig.Spec.Process.Args,
|
Command: batchInfo.ConConfig.Spec.Process.Args,
|
||||||
CreatedAt: batchInfo.ConConfig.CreatedTime,
|
CreatedAt: batchInfo.ConConfig.CreatedTime,
|
||||||
Status: batchInfo.ConState.String(),
|
ExitCode: batchInfo.ExitCode,
|
||||||
Ports: batchInfo.ConConfig.PortMappings,
|
Exited: batchInfo.Exited,
|
||||||
RootFsSize: batchInfo.RootFsSize,
|
Status: batchInfo.ConState.String(),
|
||||||
RWSize: batchInfo.RwSize,
|
PID: batchInfo.Pid,
|
||||||
Names: batchInfo.ConConfig.Name,
|
Ports: batchInfo.ConConfig.PortMappings,
|
||||||
Labels: batchInfo.ConConfig.Labels,
|
RootFsSize: batchInfo.RootFsSize,
|
||||||
Mounts: batchInfo.ConConfig.UserVolumes,
|
RWSize: batchInfo.RwSize,
|
||||||
Namespaces: ns,
|
Names: batchInfo.ConConfig.Name,
|
||||||
|
Labels: batchInfo.ConConfig.Labels,
|
||||||
|
Mounts: batchInfo.ConConfig.UserVolumes,
|
||||||
|
ContainerRunning: batchInfo.ConState == libpod.ContainerStateRunning,
|
||||||
|
Namespaces: ns,
|
||||||
}
|
}
|
||||||
|
|
||||||
if !batchInfo.StartedTime.IsZero() {
|
if !batchInfo.StartedTime.IsZero() && batchInfo.ConState == libpod.ContainerStateRunning {
|
||||||
params.RunningFor = time.Since(batchInfo.StartedTime)
|
params.RunningFor = time.Since(batchInfo.StartedTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user