github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/pkg/api/handlers/compat/containers_pause.go (about)

     1  package compat
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/containers/podman/v2/libpod"
     7  	"github.com/containers/podman/v2/pkg/api/handlers/utils"
     8  )
     9  
    10  func PauseContainer(w http.ResponseWriter, r *http.Request) {
    11  	runtime := r.Context().Value("runtime").(*libpod.Runtime)
    12  
    13  	// /{version}/containers/(name)/pause
    14  	name := utils.GetName(r)
    15  	con, err := runtime.LookupContainer(name)
    16  	if err != nil {
    17  		utils.ContainerNotFound(w, name, err)
    18  		return
    19  	}
    20  
    21  	// the api does not error if the Container is already paused, so just into it
    22  	if err := con.Pause(); err != nil {
    23  		utils.InternalServerError(w, err)
    24  		return
    25  	}
    26  	// Success
    27  	utils.WriteResponse(w, http.StatusNoContent, "")
    28  }