github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/pkg/api/handlers/compat/containers_pause.go (about)

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