Merge pull request #3 from mrunalp/status_started
Add started time and state to container status
This commit is contained in:
commit
6004dcd73b
2 changed files with 36 additions and 9 deletions
|
@ -73,7 +73,11 @@ func (r *Runtime) CreateContainer(c *Container) error {
|
|||
|
||||
// StartContainer starts a container.
|
||||
func (r *Runtime) StartContainer(c *Container) error {
|
||||
return utils.ExecCmdWithStdStreams(os.Stdin, os.Stdout, os.Stderr, r.path, "start", c.name)
|
||||
if err := utils.ExecCmdWithStdStreams(os.Stdin, os.Stdout, os.Stderr, r.path, "start", c.name); err != nil {
|
||||
return err
|
||||
}
|
||||
c.state.Started = time.Now()
|
||||
return nil
|
||||
}
|
||||
|
||||
// StopContainer stops a container.
|
||||
|
@ -119,6 +123,7 @@ type Container struct {
|
|||
type ContainerState struct {
|
||||
specs.State
|
||||
Created time.Time `json:"created"`
|
||||
Started time.Time `json:"started"`
|
||||
}
|
||||
|
||||
// NewContainer creates a container object.
|
||||
|
|
|
@ -643,16 +643,38 @@ func (s *Server) ContainerStatus(ctx context.Context, req *pb.ContainerStatusReq
|
|||
return nil, err
|
||||
}
|
||||
|
||||
cState := s.runtime.ContainerStatus(c)
|
||||
created := cState.Created.Unix()
|
||||
|
||||
return &pb.ContainerStatusResponse{
|
||||
csr := &pb.ContainerStatusResponse{
|
||||
Status: &pb.ContainerStatus{
|
||||
Id: containerName,
|
||||
CreatedAt: int64Ptr(created),
|
||||
Id: containerName,
|
||||
},
|
||||
}, nil
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
cState := s.runtime.ContainerStatus(c)
|
||||
rStatus := pb.ContainerState_UNKNOWN
|
||||
|
||||
switch cState.Status {
|
||||
case "created":
|
||||
rStatus = pb.ContainerState_CREATED
|
||||
created := cState.Created.Unix()
|
||||
csr.Status.CreatedAt = int64Ptr(created)
|
||||
case "running":
|
||||
rStatus = pb.ContainerState_RUNNING
|
||||
created := cState.Created.Unix()
|
||||
csr.Status.CreatedAt = int64Ptr(created)
|
||||
started := cState.Started.Unix()
|
||||
csr.Status.StartedAt = int64Ptr(started)
|
||||
case "stopped":
|
||||
// TODO: Get the exit time
|
||||
rStatus = pb.ContainerState_EXITED
|
||||
created := cState.Created.Unix()
|
||||
csr.Status.CreatedAt = int64Ptr(created)
|
||||
started := cState.Started.Unix()
|
||||
csr.Status.StartedAt = int64Ptr(started)
|
||||
}
|
||||
|
||||
csr.Status.State = &rStatus
|
||||
|
||||
return csr, nil
|
||||
}
|
||||
|
||||
// Exec executes the command in the container.
|
||||
|
|
Loading…
Reference in a new issue