Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add exec resize router #2105

Merged
merged 1 commit into from
Aug 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
35 changes: 33 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 All @@ -835,6 +835,10 @@ paths:
description: "bad parameter"
schema:
$ref: "#/definitions/Error"
404:
$ref: "#/responses/404ErrorResponse"
500:
$ref: "#/responses/500ErrorResponse"
tags: ["Container"]

/containers/{id}/checkpoints:
Expand Down Expand Up @@ -966,6 +970,33 @@ 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"
404:
$ref: "#/responses/404ErrorResponse"
500:
$ref: "#/responses/500ErrorResponse"
tags: ["Exec"]

/containers/{id}/attach:
post:
summary: "Attach to a container"
Expand Down
19 changes: 17 additions & 2 deletions apis/types/history_result_item.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.