From 819db7d8cca66fd37b2305843693e220cf433e3f Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Mon, 12 Sep 2016 15:43:30 -0700 Subject: [PATCH] Return the started time and ctr state with ctr status Signed-off-by: Mrunal Patel --- server/runtime.go | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/server/runtime.go b/server/runtime.go index 20cf4445..b3cdbab9 100644 --- a/server/runtime.go +++ b/server/runtime.go @@ -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.