containerd-shim-kata-v2: add the service Pause support

Add the Pause api support to pause a container running
in the pod.

Signed-off-by: ZeroMagic <anthonyliu@zju.edu.cn>
This commit is contained in:
ZeroMagic 2018-08-09 10:31:39 +08:00 committed by fupan
parent cd321a3e6e
commit 8df33d34e8

View File

@ -497,7 +497,28 @@ func (s *service) State(ctx context.Context, r *taskAPI.StateRequest) (*taskAPI.
// Pause the container
func (s *service) Pause(ctx context.Context, r *taskAPI.PauseRequest) (*ptypes.Empty, error) {
return nil, errdefs.ErrNotImplemented
s.Lock()
defer s.Unlock()
c, err := s.getContainer(r.ID)
if err != nil {
return nil, err
}
c.status = task.StatusPausing
err = s.sandbox.PauseContainer(r.ID)
if err == nil {
c.status = task.StatusPaused
return empty, nil
}
c.status, err = s.getContainerStatus(c.id)
if err != nil {
c.status = task.StatusUnknown
}
return empty, err
}
// Resume the container
@ -678,3 +699,24 @@ func (s *service) getContainer(id string) (*container, error) {
return c, nil
}
func (s *service) getContainerStatus(containerID string) (task.Status, error) {
cStatus, err := s.sandbox.StatusContainer(containerID)
if err != nil {
return task.StatusUnknown, err
}
var status task.Status
switch cStatus.State.State {
case vc.StateReady:
status = task.StatusCreated
case vc.StateRunning:
status = task.StatusRunning
case vc.StatePaused:
status = task.StatusPaused
case vc.StateStopped:
status = task.StatusStopped
}
return status, nil
}