Skip to content

Commit

Permalink
feature: add exec resize router
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Wan <zirenwan@gmail.com>
  • Loading branch information
HusterWan committed Aug 16, 2018
1 parent 18df365 commit 75f5572
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
28 changes: 28 additions & 0 deletions apis/server/exec_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"strconv"

"github.com/alibaba/pouch/apis/types"
"github.com/alibaba/pouch/daemon/mgr"
Expand Down Expand Up @@ -93,3 +94,30 @@ func (s *Server) getExecInfo(ctx context.Context, rw http.ResponseWriter, req *h
}
return EncodeResponse(rw, http.StatusOK, execInfo)
}

func (s *Server) resizeExec(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
height, err := strconv.Atoi(req.FormValue("h"))
if err != nil {
return httputils.NewHTTPError(err, http.StatusBadRequest)
}

width, err := strconv.Atoi(req.FormValue("w"))
if err != nil {
return httputils.NewHTTPError(err, http.StatusBadRequest)
}

opts := types.ResizeOptions{
Height: int64(height),
Width: int64(width),
}

name := mux.Vars(req)["name"]

if err := s.ContainerMgr.ResizeExec(ctx, name, opts); err != nil {
return err
}

rw.WriteHeader(http.StatusOK)
return nil

}
1 change: 1 addition & 0 deletions apis/server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func initRoute(s *Server) http.Handler {
s.addRoute(r, http.MethodPost, "/containers/{name:.*}/exec", s.createContainerExec)
s.addRoute(r, http.MethodGet, "/exec/{name:.*}/json", s.getExecInfo)
s.addRoute(r, http.MethodPost, "/exec/{name:.*}/start", s.startContainerExec)
s.addRoute(r, http.MethodPost, "/exec/{name:.*}/resize", s.resizeExec)
s.addRoute(r, http.MethodPost, "/containers/{name:.*}/rename", s.renameContainer)
s.addRoute(r, http.MethodPost, "/containers/{name:.*}/restart", s.restartContainer)
s.addRoute(r, http.MethodPost, "/containers/{name:.*}/pause", s.pauseContainer)
Expand Down
29 changes: 27 additions & 2 deletions apis/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -820,11 +820,11 @@ paths:
operationId: "ContainerResize"
parameters:
- $ref: "#/parameters/id"
- name: "height"
- name: "h"
in: "query"
description: "height of the tty"
type: "string"
- name: "width"
- name: "w"
in: "query"
description: "width of the tty"
type: "string"
Expand Down Expand Up @@ -966,6 +966,31 @@ paths:
type: "string"
tags: ["Exec"]

/exec/{id}/resize:
post:
summary: "changes the size of the tty for an exec process"
operationId: "ExecResize"
parameters:
- $ref: "#/parameters/id"
- name: "h"
in: "query"
description: "height of the tty"
type: "string"
- name: "w"
in: "query"
description: "width of the tty"
type: "string"
responses:
200:
description: "no error"
400:
description: "bad parameter"
schema:
$ref: "#/definitions/Error"
500:
$ref: "#/responses/500ErrorResponse"
tags: ["Exec"]

/containers/{id}/attach:
post:
summary: "Attach to a container"
Expand Down

0 comments on commit 75f5572

Please sign in to comment.