Add resize endpoint to api
This commit is contained in:
parent
ecb64be6a8
commit
70d2123efd
3 changed files with 35 additions and 0 deletions
24
api.go
24
api.go
|
@ -48,6 +48,7 @@ func writeJson(w http.ResponseWriter, b []byte) {
|
||||||
w.Write(b)
|
w.Write(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: Use stvconv.ParseBool() instead?
|
||||||
func getBoolParam(value string) (bool, error) {
|
func getBoolParam(value string) (bool, error) {
|
||||||
if value == "1" || strings.ToLower(value) == "true" {
|
if value == "1" || strings.ToLower(value) == "true" {
|
||||||
return true, nil
|
return true, nil
|
||||||
|
@ -485,6 +486,28 @@ func postContainersWait(srv *Server, version float64, w http.ResponseWriter, r *
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func postContainersResize(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||||
|
if err := parseForm(r); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
height, err := strconv.Atoi(r.Form.Get("h"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
width, err := strconv.Atoi(r.Form.Get("w"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if vars == nil {
|
||||||
|
return fmt.Errorf("Missing parameter")
|
||||||
|
}
|
||||||
|
name := vars["name"]
|
||||||
|
if err := srv.ContainerResize(name, height, width); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func postContainersAttach(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
func postContainersAttach(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||||
if err := parseForm(r); err != nil {
|
if err := parseForm(r); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -620,6 +643,7 @@ func ListenAndServe(addr string, srv *Server, logging bool) error {
|
||||||
"/containers/{name:.*}/start": postContainersStart,
|
"/containers/{name:.*}/start": postContainersStart,
|
||||||
"/containers/{name:.*}/stop": postContainersStop,
|
"/containers/{name:.*}/stop": postContainersStop,
|
||||||
"/containers/{name:.*}/wait": postContainersWait,
|
"/containers/{name:.*}/wait": postContainersWait,
|
||||||
|
"/containers/{name:.*}/resize": postContainersResize,
|
||||||
"/containers/{name:.*}/attach": postContainersAttach,
|
"/containers/{name:.*}/attach": postContainersAttach,
|
||||||
},
|
},
|
||||||
"DELETE": {
|
"DELETE": {
|
||||||
|
|
|
@ -754,6 +754,10 @@ func (container *Container) Wait() int {
|
||||||
return container.State.ExitCode
|
return container.State.ExitCode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (container *Container) Resize(h, w int) error {
|
||||||
|
return fmt.Errorf("Resize not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
func (container *Container) ExportRw() (Archive, error) {
|
func (container *Container) ExportRw() (Archive, error) {
|
||||||
return Tar(container.rwPath(), Uncompressed)
|
return Tar(container.rwPath(), Uncompressed)
|
||||||
}
|
}
|
||||||
|
|
|
@ -776,6 +776,13 @@ func (srv *Server) ContainerWait(name string) (int, error) {
|
||||||
return 0, fmt.Errorf("No such container: %s", name)
|
return 0, fmt.Errorf("No such container: %s", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (srv *Server) ContainerResize(name string, h, w int) error {
|
||||||
|
if container := srv.runtime.Get(name); container != nil {
|
||||||
|
return container.Resize(h, w)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("No such container: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
func (srv *Server) ContainerAttach(name string, logs, stream, stdin, stdout, stderr bool, in io.ReadCloser, out io.Writer) error {
|
func (srv *Server) ContainerAttach(name string, logs, stream, stdin, stdout, stderr bool, in io.ReadCloser, out io.Writer) error {
|
||||||
container := srv.runtime.Get(name)
|
container := srv.runtime.Get(name)
|
||||||
if container == nil {
|
if container == nil {
|
||||||
|
|
Loading…
Reference in a new issue