mirror of https://github.com/containers/podman.git
Add APIv2 handler for resizing exec sessions
Signed-off-by: Matthew Heon <mheon@redhat.com>
This commit is contained in:
parent
4d410b7cb7
commit
cf1f13af98
|
@ -14,6 +14,7 @@ import (
|
||||||
"github.com/gorilla/schema"
|
"github.com/gorilla/schema"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
"k8s.io/client-go/tools/remotecommand"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ExecCreateHandler creates an exec session for a given container.
|
// ExecCreateHandler creates an exec session for a given container.
|
||||||
|
@ -107,6 +108,45 @@ func ExecInspectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
utils.WriteResponse(w, http.StatusOK, inspectOut)
|
utils.WriteResponse(w, http.StatusOK, inspectOut)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExecResizeHandler resizes a given exec session's TTY.
|
||||||
|
func ExecResizeHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
||||||
|
decoder := r.Context().Value("decoder").(*schema.Decoder)
|
||||||
|
|
||||||
|
sessionID := mux.Vars(r)["id"]
|
||||||
|
|
||||||
|
query := struct {
|
||||||
|
Height uint16 `schema:"h"`
|
||||||
|
Width uint16 `schema:"w"`
|
||||||
|
}{
|
||||||
|
// override any golang type defaults
|
||||||
|
}
|
||||||
|
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
|
||||||
|
utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest,
|
||||||
|
errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
sessionCtr, err := runtime.GetExecSessionContainer(sessionID)
|
||||||
|
if err != nil {
|
||||||
|
utils.Error(w, fmt.Sprintf("No such exec session: %s", sessionID), http.StatusNotFound, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
newSize := remotecommand.TerminalSize{
|
||||||
|
Width: query.Width,
|
||||||
|
Height: query.Height,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := sessionCtr.ExecResize(sessionID, newSize); err != nil {
|
||||||
|
utils.InternalServerError(w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is a 201 some reason, not a 204.
|
||||||
|
utils.WriteResponse(w, http.StatusCreated, "")
|
||||||
|
}
|
||||||
|
|
||||||
// ExecStartHandler runs a given exec session.
|
// ExecStartHandler runs a given exec session.
|
||||||
func ExecStartHandler(w http.ResponseWriter, r *http.Request) {
|
func ExecStartHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
||||||
|
|
|
@ -114,7 +114,7 @@ func (s *APIServer) registerExecHandlers(r *mux.Router) error {
|
||||||
// $ref: "#/responses/InternalError"
|
// $ref: "#/responses/InternalError"
|
||||||
r.Handle(VersionedPath("/exec/{id}/start"), s.APIHandler(compat.ExecStartHandler)).Methods(http.MethodPost)
|
r.Handle(VersionedPath("/exec/{id}/start"), s.APIHandler(compat.ExecStartHandler)).Methods(http.MethodPost)
|
||||||
// Added non version path to URI to support docker non versioned paths
|
// Added non version path to URI to support docker non versioned paths
|
||||||
r.Handle("/exec/{id}/start", s.APIHandler(compat.UnsupportedHandler)).Methods(http.MethodPost)
|
r.Handle("/exec/{id}/start", s.APIHandler(compat.ExecStartHandler)).Methods(http.MethodPost)
|
||||||
// swagger:operation POST /exec/{id}/resize compat resizeExec
|
// swagger:operation POST /exec/{id}/resize compat resizeExec
|
||||||
// ---
|
// ---
|
||||||
// tags:
|
// tags:
|
||||||
|
@ -145,9 +145,9 @@ func (s *APIServer) registerExecHandlers(r *mux.Router) error {
|
||||||
// $ref: "#/responses/NoSuchExecInstance"
|
// $ref: "#/responses/NoSuchExecInstance"
|
||||||
// 500:
|
// 500:
|
||||||
// $ref: "#/responses/InternalError"
|
// $ref: "#/responses/InternalError"
|
||||||
r.Handle(VersionedPath("/exec/{id}/resize"), s.APIHandler(compat.UnsupportedHandler)).Methods(http.MethodPost)
|
r.Handle(VersionedPath("/exec/{id}/resize"), s.APIHandler(compat.ExecResizeHandler)).Methods(http.MethodPost)
|
||||||
// Added non version path to URI to support docker non versioned paths
|
// Added non version path to URI to support docker non versioned paths
|
||||||
r.Handle("/exec/{id}/resize", s.APIHandler(compat.UnsupportedHandler)).Methods(http.MethodPost)
|
r.Handle("/exec/{id}/resize", s.APIHandler(compat.ExecResizeHandler)).Methods(http.MethodPost)
|
||||||
// swagger:operation GET /exec/{id}/json compat inspectExec
|
// swagger:operation GET /exec/{id}/json compat inspectExec
|
||||||
// ---
|
// ---
|
||||||
// tags:
|
// tags:
|
||||||
|
@ -264,10 +264,10 @@ func (s *APIServer) registerExecHandlers(r *mux.Router) error {
|
||||||
// properties:
|
// properties:
|
||||||
// Detach:
|
// Detach:
|
||||||
// type: boolean
|
// type: boolean
|
||||||
// description: Detach from the command
|
// description: Detach from the command. Not presently supported.
|
||||||
// Tty:
|
// Tty:
|
||||||
// type: boolean
|
// type: boolean
|
||||||
// description: Allocate a pseudo-TTY
|
// description: Allocate a pseudo-TTY. Not presently supported.
|
||||||
// produces:
|
// produces:
|
||||||
// - application/json
|
// - application/json
|
||||||
// responses:
|
// responses:
|
||||||
|
@ -276,10 +276,10 @@ func (s *APIServer) registerExecHandlers(r *mux.Router) error {
|
||||||
// 404:
|
// 404:
|
||||||
// $ref: "#/responses/NoSuchExecInstance"
|
// $ref: "#/responses/NoSuchExecInstance"
|
||||||
// 409:
|
// 409:
|
||||||
// description: container is stopped or paused
|
// description: container is not running.
|
||||||
// 500:
|
// 500:
|
||||||
// $ref: "#/responses/InternalError"
|
// $ref: "#/responses/InternalError"
|
||||||
r.Handle(VersionedPath("/libpod/exec/{id}/start"), s.APIHandler(compat.UnsupportedHandler)).Methods(http.MethodPost)
|
r.Handle(VersionedPath("/libpod/exec/{id}/start"), s.APIHandler(compat.ExecStartHandler)).Methods(http.MethodPost)
|
||||||
// swagger:operation POST /libpod/exec/{id}/resize libpod libpodResizeExec
|
// swagger:operation POST /libpod/exec/{id}/resize libpod libpodResizeExec
|
||||||
// ---
|
// ---
|
||||||
// tags:
|
// tags:
|
||||||
|
@ -310,7 +310,7 @@ func (s *APIServer) registerExecHandlers(r *mux.Router) error {
|
||||||
// $ref: "#/responses/NoSuchExecInstance"
|
// $ref: "#/responses/NoSuchExecInstance"
|
||||||
// 500:
|
// 500:
|
||||||
// $ref: "#/responses/InternalError"
|
// $ref: "#/responses/InternalError"
|
||||||
r.Handle(VersionedPath("/libpod/exec/{id}/resize"), s.APIHandler(compat.UnsupportedHandler)).Methods(http.MethodPost)
|
r.Handle(VersionedPath("/libpod/exec/{id}/resize"), s.APIHandler(compat.ExecResizeHandler)).Methods(http.MethodPost)
|
||||||
// swagger:operation GET /libpod/exec/{id}/json libpod libpodInspectExec
|
// swagger:operation GET /libpod/exec/{id}/json libpod libpodInspectExec
|
||||||
// ---
|
// ---
|
||||||
// tags:
|
// tags:
|
||||||
|
|
Loading…
Reference in New Issue