Browse Source

Add resize endpoint to api

Guillaume J. Charmes 12 years ago
parent
commit
70d2123efd
3 changed files with 35 additions and 0 deletions
  1. 24 0
      api.go
  2. 4 0
      container.go
  3. 7 0
      server.go

+ 24 - 0
api.go

@@ -48,6 +48,7 @@ func writeJson(w http.ResponseWriter, b []byte) {
 	w.Write(b)
 }
 
+// FIXME: Use stvconv.ParseBool() instead?
 func getBoolParam(value string) (bool, error) {
 	if value == "1" || strings.ToLower(value) == "true" {
 		return true, nil
@@ -485,6 +486,28 @@ func postContainersWait(srv *Server, version float64, w http.ResponseWriter, r *
 	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 {
 	if err := parseForm(r); err != nil {
 		return err
@@ -620,6 +643,7 @@ func ListenAndServe(addr string, srv *Server, logging bool) error {
 			"/containers/{name:.*}/start":   postContainersStart,
 			"/containers/{name:.*}/stop":    postContainersStop,
 			"/containers/{name:.*}/wait":    postContainersWait,
+			"/containers/{name:.*}/resize":  postContainersResize,
 			"/containers/{name:.*}/attach":  postContainersAttach,
 		},
 		"DELETE": {

+ 4 - 0
container.go

@@ -754,6 +754,10 @@ func (container *Container) Wait() int {
 	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) {
 	return Tar(container.rwPath(), Uncompressed)
 }

+ 7 - 0
server.go

@@ -776,6 +776,13 @@ func (srv *Server) ContainerWait(name string) (int, error) {
 	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 {
 	container := srv.runtime.Get(name)
 	if container == nil {