From c0048118a0a2ec76b3f66996d837c68c479f6df9 Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Mon, 15 Aug 2016 16:55:00 -0700 Subject: [PATCH] Add implementation for Stop Pod Sandbox Signed-off-by: Mrunal Patel --- server/runtime.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/server/runtime.go b/server/runtime.go index 137e82f7..6958f193 100644 --- a/server/runtime.go +++ b/server/runtime.go @@ -158,8 +158,23 @@ func (s *Server) CreatePodSandbox(ctx context.Context, req *pb.CreatePodSandboxR // StopPodSandbox stops the sandbox. If there are any running containers in the // sandbox, they should be force terminated. -func (s *Server) StopPodSandbox(context.Context, *pb.StopPodSandboxRequest) (*pb.StopPodSandboxResponse, error) { - return nil, nil +func (s *Server) StopPodSandbox(ctx context.Context, req *pb.StopPodSandboxRequest) (*pb.StopPodSandboxResponse, error) { + sbName := req.PodSandboxId + if *sbName == "" { + return nil, fmt.Errorf("PodSandboxConfig.Name should not be empty") + } + sb := s.state.sandboxes[*sbName] + if sb == nil { + return nil, fmt.Errorf("specified sandbox not found: %s", *sbName) + } + + for _, c := range sb.containers { + if err := s.runtime.StopContainer(c); err != nil { + return nil, fmt.Errorf("failed to stop container %s in sandbox %s: %v", c.Name(), *sbName, err) + } + } + + return &pb.StopPodSandboxResponse{}, nil } // DeletePodSandbox deletes the sandbox. If there are any running containers in the