|
@@ -1,9 +1,6 @@
|
|
package server
|
|
package server
|
|
|
|
|
|
import (
|
|
import (
|
|
- "runtime"
|
|
|
|
- "time"
|
|
|
|
-
|
|
|
|
"encoding/base64"
|
|
"encoding/base64"
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"fmt"
|
|
"fmt"
|
|
@@ -11,8 +8,10 @@ import (
|
|
"net"
|
|
"net"
|
|
"net/http"
|
|
"net/http"
|
|
"os"
|
|
"os"
|
|
|
|
+ "runtime"
|
|
"strconv"
|
|
"strconv"
|
|
"strings"
|
|
"strings"
|
|
|
|
+ "time"
|
|
|
|
|
|
"code.google.com/p/go.net/websocket"
|
|
"code.google.com/p/go.net/websocket"
|
|
"github.com/gorilla/mux"
|
|
"github.com/gorilla/mux"
|
|
@@ -25,7 +24,6 @@ import (
|
|
"github.com/docker/docker/cliconfig"
|
|
"github.com/docker/docker/cliconfig"
|
|
"github.com/docker/docker/daemon"
|
|
"github.com/docker/docker/daemon"
|
|
"github.com/docker/docker/daemon/networkdriver/bridge"
|
|
"github.com/docker/docker/daemon/networkdriver/bridge"
|
|
- "github.com/docker/docker/engine"
|
|
|
|
"github.com/docker/docker/graph"
|
|
"github.com/docker/docker/graph"
|
|
"github.com/docker/docker/pkg/jsonmessage"
|
|
"github.com/docker/docker/pkg/jsonmessage"
|
|
"github.com/docker/docker/pkg/parsers"
|
|
"github.com/docker/docker/pkg/parsers"
|
|
@@ -53,26 +51,31 @@ type ServerConfig struct {
|
|
}
|
|
}
|
|
|
|
|
|
type Server struct {
|
|
type Server struct {
|
|
- daemon *daemon.Daemon
|
|
|
|
- cfg *ServerConfig
|
|
|
|
- router *mux.Router
|
|
|
|
- start chan struct{}
|
|
|
|
-
|
|
|
|
- // TODO: delete engine
|
|
|
|
- eng *engine.Engine
|
|
|
|
|
|
+ daemon *daemon.Daemon
|
|
|
|
+ cfg *ServerConfig
|
|
|
|
+ router *mux.Router
|
|
|
|
+ start chan struct{}
|
|
|
|
+ servers []serverCloser
|
|
}
|
|
}
|
|
|
|
|
|
-func New(cfg *ServerConfig, eng *engine.Engine) *Server {
|
|
|
|
|
|
+func New(cfg *ServerConfig) *Server {
|
|
srv := &Server{
|
|
srv := &Server{
|
|
cfg: cfg,
|
|
cfg: cfg,
|
|
start: make(chan struct{}),
|
|
start: make(chan struct{}),
|
|
- eng: eng,
|
|
|
|
}
|
|
}
|
|
- r := createRouter(srv, eng)
|
|
|
|
|
|
+ r := createRouter(srv)
|
|
srv.router = r
|
|
srv.router = r
|
|
return srv
|
|
return srv
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func (s *Server) Close() {
|
|
|
|
+ for _, srv := range s.servers {
|
|
|
|
+ if err := srv.Close(); err != nil {
|
|
|
|
+ logrus.Error(err)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
func (s *Server) SetDaemon(d *daemon.Daemon) {
|
|
func (s *Server) SetDaemon(d *daemon.Daemon) {
|
|
s.daemon = d
|
|
s.daemon = d
|
|
}
|
|
}
|
|
@@ -92,19 +95,15 @@ func (s *Server) ServeApi(protoAddrs []string) error {
|
|
if len(protoAddrParts) != 2 {
|
|
if len(protoAddrParts) != 2 {
|
|
return fmt.Errorf("bad format, expected PROTO://ADDR")
|
|
return fmt.Errorf("bad format, expected PROTO://ADDR")
|
|
}
|
|
}
|
|
|
|
+ srv, err := s.newServer(protoAddrParts[0], protoAddrParts[1])
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ s.servers = append(s.servers, srv)
|
|
|
|
+
|
|
go func(proto, addr string) {
|
|
go func(proto, addr string) {
|
|
logrus.Infof("Listening for HTTP on %s (%s)", proto, addr)
|
|
logrus.Infof("Listening for HTTP on %s (%s)", proto, addr)
|
|
- srv, err := s.newServer(proto, addr)
|
|
|
|
- if err != nil {
|
|
|
|
- chErrors <- err
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- s.eng.OnShutdown(func() {
|
|
|
|
- if err := srv.Close(); err != nil {
|
|
|
|
- logrus.Error(err)
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- if err = srv.Serve(); err != nil && strings.Contains(err.Error(), "use of closed network connection") {
|
|
|
|
|
|
+ if err := srv.Serve(); err != nil && strings.Contains(err.Error(), "use of closed network connection") {
|
|
err = nil
|
|
err = nil
|
|
}
|
|
}
|
|
chErrors <- err
|
|
chErrors <- err
|
|
@@ -133,7 +132,7 @@ func (s *HttpServer) Close() error {
|
|
return s.l.Close()
|
|
return s.l.Close()
|
|
}
|
|
}
|
|
|
|
|
|
-type HttpApiFunc func(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error
|
|
|
|
|
|
+type HttpApiFunc func(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error
|
|
|
|
|
|
func hijackServer(w http.ResponseWriter) (io.ReadCloser, io.Writer, error) {
|
|
func hijackServer(w http.ResponseWriter) (io.ReadCloser, io.Writer, error) {
|
|
conn, _, err := w.(http.Hijacker).Hijack()
|
|
conn, _, err := w.(http.Hijacker).Hijack()
|
|
@@ -230,16 +229,7 @@ func writeJSON(w http.ResponseWriter, code int, v interface{}) error {
|
|
return json.NewEncoder(w).Encode(v)
|
|
return json.NewEncoder(w).Encode(v)
|
|
}
|
|
}
|
|
|
|
|
|
-func streamJSON(out *engine.Output, w http.ResponseWriter, flush bool) {
|
|
|
|
- w.Header().Set("Content-Type", "application/json")
|
|
|
|
- if flush {
|
|
|
|
- out.Add(utils.NewWriteFlusher(w))
|
|
|
|
- } else {
|
|
|
|
- out.Add(w)
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func (s *Server) postAuth(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) postAuth(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
var config *cliconfig.AuthConfig
|
|
var config *cliconfig.AuthConfig
|
|
err := json.NewDecoder(r.Body).Decode(&config)
|
|
err := json.NewDecoder(r.Body).Decode(&config)
|
|
r.Body.Close()
|
|
r.Body.Close()
|
|
@@ -255,7 +245,7 @@ func (s *Server) postAuth(eng *engine.Engine, version version.Version, w http.Re
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) getVersion(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) getVersion(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
|
|
v := &types.Version{
|
|
v := &types.Version{
|
|
@@ -273,7 +263,7 @@ func (s *Server) getVersion(eng *engine.Engine, version version.Version, w http.
|
|
return writeJSON(w, http.StatusOK, v)
|
|
return writeJSON(w, http.StatusOK, v)
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) postContainersKill(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) postContainersKill(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if vars == nil {
|
|
if vars == nil {
|
|
return fmt.Errorf("Missing parameter")
|
|
return fmt.Errorf("Missing parameter")
|
|
}
|
|
}
|
|
@@ -308,7 +298,7 @@ func (s *Server) postContainersKill(eng *engine.Engine, version version.Version,
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) postContainersPause(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) postContainersPause(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if vars == nil {
|
|
if vars == nil {
|
|
return fmt.Errorf("Missing parameter")
|
|
return fmt.Errorf("Missing parameter")
|
|
}
|
|
}
|
|
@@ -332,7 +322,7 @@ func (s *Server) postContainersPause(eng *engine.Engine, version version.Version
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) postContainersUnpause(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) postContainersUnpause(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if vars == nil {
|
|
if vars == nil {
|
|
return fmt.Errorf("Missing parameter")
|
|
return fmt.Errorf("Missing parameter")
|
|
}
|
|
}
|
|
@@ -356,7 +346,7 @@ func (s *Server) postContainersUnpause(eng *engine.Engine, version version.Versi
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) getContainersExport(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) getContainersExport(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if vars == nil {
|
|
if vars == nil {
|
|
return fmt.Errorf("Missing parameter")
|
|
return fmt.Errorf("Missing parameter")
|
|
}
|
|
}
|
|
@@ -364,7 +354,7 @@ func (s *Server) getContainersExport(eng *engine.Engine, version version.Version
|
|
return s.daemon.ContainerExport(vars["name"], w)
|
|
return s.daemon.ContainerExport(vars["name"], w)
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) getImagesJSON(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) getImagesJSON(version version.Version, 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
|
|
}
|
|
}
|
|
@@ -405,7 +395,7 @@ func (s *Server) getImagesJSON(eng *engine.Engine, version version.Version, w ht
|
|
return writeJSON(w, http.StatusOK, legacyImages)
|
|
return writeJSON(w, http.StatusOK, legacyImages)
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) getInfo(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) getInfo(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
|
|
info, err := s.daemon.SystemInfo()
|
|
info, err := s.daemon.SystemInfo()
|
|
@@ -416,7 +406,7 @@ func (s *Server) getInfo(eng *engine.Engine, version version.Version, w http.Res
|
|
return writeJSON(w, http.StatusOK, info)
|
|
return writeJSON(w, http.StatusOK, info)
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) getEvents(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) getEvents(version version.Version, 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
|
|
}
|
|
}
|
|
@@ -520,7 +510,7 @@ func (s *Server) getEvents(eng *engine.Engine, version version.Version, w http.R
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) getImagesHistory(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) getImagesHistory(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if vars == nil {
|
|
if vars == nil {
|
|
return fmt.Errorf("Missing parameter")
|
|
return fmt.Errorf("Missing parameter")
|
|
}
|
|
}
|
|
@@ -534,7 +524,7 @@ func (s *Server) getImagesHistory(eng *engine.Engine, version version.Version, w
|
|
return writeJSON(w, http.StatusOK, history)
|
|
return writeJSON(w, http.StatusOK, history)
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) getContainersChanges(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) getContainersChanges(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if vars == nil {
|
|
if vars == nil {
|
|
return fmt.Errorf("Missing parameter")
|
|
return fmt.Errorf("Missing parameter")
|
|
}
|
|
}
|
|
@@ -553,7 +543,7 @@ func (s *Server) getContainersChanges(eng *engine.Engine, version version.Versio
|
|
return writeJSON(w, http.StatusOK, changes)
|
|
return writeJSON(w, http.StatusOK, changes)
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) getContainersTop(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) getContainersTop(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if version.LessThan("1.4") {
|
|
if version.LessThan("1.4") {
|
|
return fmt.Errorf("top was improved a lot since 1.3, Please upgrade your docker client.")
|
|
return fmt.Errorf("top was improved a lot since 1.3, Please upgrade your docker client.")
|
|
}
|
|
}
|
|
@@ -574,7 +564,7 @@ func (s *Server) getContainersTop(eng *engine.Engine, version version.Version, w
|
|
return writeJSON(w, http.StatusOK, procList)
|
|
return writeJSON(w, http.StatusOK, procList)
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) getContainersJSON(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) getContainersJSON(version version.Version, 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
|
|
}
|
|
}
|
|
@@ -603,7 +593,7 @@ func (s *Server) getContainersJSON(eng *engine.Engine, version version.Version,
|
|
return writeJSON(w, http.StatusOK, containers)
|
|
return writeJSON(w, http.StatusOK, containers)
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) getContainersStats(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) getContainersStats(version version.Version, 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
|
|
}
|
|
}
|
|
@@ -614,7 +604,7 @@ func (s *Server) getContainersStats(eng *engine.Engine, version version.Version,
|
|
return s.daemon.ContainerStats(vars["name"], utils.NewWriteFlusher(w))
|
|
return s.daemon.ContainerStats(vars["name"], utils.NewWriteFlusher(w))
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) getContainersLogs(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) getContainersLogs(version version.Version, 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
|
|
}
|
|
}
|
|
@@ -644,7 +634,7 @@ func (s *Server) getContainersLogs(eng *engine.Engine, version version.Version,
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) postImagesTag(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) postImagesTag(version version.Version, 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
|
|
}
|
|
}
|
|
@@ -662,7 +652,7 @@ func (s *Server) postImagesTag(eng *engine.Engine, version version.Version, w ht
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) postCommit(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) postCommit(version version.Version, 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
|
|
}
|
|
}
|
|
@@ -708,7 +698,7 @@ func (s *Server) postCommit(eng *engine.Engine, version version.Version, w http.
|
|
}
|
|
}
|
|
|
|
|
|
// Creates an image from Pull or from Import
|
|
// Creates an image from Pull or from Import
|
|
-func (s *Server) postImagesCreate(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) postImagesCreate(version version.Version, 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
|
|
}
|
|
}
|
|
@@ -788,7 +778,7 @@ func (s *Server) postImagesCreate(eng *engine.Engine, version version.Version, w
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) getImagesSearch(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) getImagesSearch(version version.Version, 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
|
|
}
|
|
}
|
|
@@ -818,7 +808,7 @@ func (s *Server) getImagesSearch(eng *engine.Engine, version version.Version, w
|
|
return json.NewEncoder(w).Encode(query.Results)
|
|
return json.NewEncoder(w).Encode(query.Results)
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) postImagesPush(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) postImagesPush(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if vars == nil {
|
|
if vars == nil {
|
|
return fmt.Errorf("Missing parameter")
|
|
return fmt.Errorf("Missing parameter")
|
|
}
|
|
}
|
|
@@ -875,7 +865,7 @@ func (s *Server) postImagesPush(eng *engine.Engine, version version.Version, w h
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) getImagesGet(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) getImagesGet(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if vars == nil {
|
|
if vars == nil {
|
|
return fmt.Errorf("Missing parameter")
|
|
return fmt.Errorf("Missing parameter")
|
|
}
|
|
}
|
|
@@ -907,11 +897,11 @@ func (s *Server) getImagesGet(eng *engine.Engine, version version.Version, w htt
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) postImagesLoad(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) postImagesLoad(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
return s.daemon.Repositories().Load(r.Body, w)
|
|
return s.daemon.Repositories().Load(r.Body, w)
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) postContainersCreate(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) postContainersCreate(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if err := parseForm(r); err != nil {
|
|
if err := parseForm(r); err != nil {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
@@ -939,7 +929,7 @@ func (s *Server) postContainersCreate(eng *engine.Engine, version version.Versio
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) postContainersRestart(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) postContainersRestart(version version.Version, 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
|
|
}
|
|
}
|
|
@@ -961,7 +951,7 @@ func (s *Server) postContainersRestart(eng *engine.Engine, version version.Versi
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) postContainerRename(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) postContainerRename(version version.Version, 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
|
|
}
|
|
}
|
|
@@ -978,7 +968,7 @@ func (s *Server) postContainerRename(eng *engine.Engine, version version.Version
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) deleteContainers(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) deleteContainers(version version.Version, 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
|
|
}
|
|
}
|
|
@@ -1006,7 +996,7 @@ func (s *Server) deleteContainers(eng *engine.Engine, version version.Version, w
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) deleteImages(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) deleteImages(version version.Version, 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
|
|
}
|
|
}
|
|
@@ -1026,7 +1016,7 @@ func (s *Server) deleteImages(eng *engine.Engine, version version.Version, w htt
|
|
return writeJSON(w, http.StatusOK, list)
|
|
return writeJSON(w, http.StatusOK, list)
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) postContainersStart(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) postContainersStart(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if vars == nil {
|
|
if vars == nil {
|
|
return fmt.Errorf("Missing parameter")
|
|
return fmt.Errorf("Missing parameter")
|
|
}
|
|
}
|
|
@@ -1062,7 +1052,7 @@ func (s *Server) postContainersStart(eng *engine.Engine, version version.Version
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) postContainersStop(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) postContainersStop(version version.Version, 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
|
|
}
|
|
}
|
|
@@ -1087,7 +1077,7 @@ func (s *Server) postContainersStop(eng *engine.Engine, version version.Version,
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) postContainersWait(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) postContainersWait(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if vars == nil {
|
|
if vars == nil {
|
|
return fmt.Errorf("Missing parameter")
|
|
return fmt.Errorf("Missing parameter")
|
|
}
|
|
}
|
|
@@ -1105,7 +1095,7 @@ func (s *Server) postContainersWait(eng *engine.Engine, version version.Version,
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) postContainersResize(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) postContainersResize(version version.Version, 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
|
|
}
|
|
}
|
|
@@ -1130,7 +1120,7 @@ func (s *Server) postContainersResize(eng *engine.Engine, version version.Versio
|
|
return cont.Resize(height, width)
|
|
return cont.Resize(height, width)
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) postContainersAttach(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) postContainersAttach(version version.Version, 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
|
|
}
|
|
}
|
|
@@ -1185,7 +1175,7 @@ func (s *Server) postContainersAttach(eng *engine.Engine, version version.Versio
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) wsContainersAttach(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) wsContainersAttach(version version.Version, 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
|
|
}
|
|
}
|
|
@@ -1211,7 +1201,7 @@ func (s *Server) wsContainersAttach(eng *engine.Engine, version version.Version,
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) getContainersByName(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) getContainersByName(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if vars == nil {
|
|
if vars == nil {
|
|
return fmt.Errorf("Missing parameter")
|
|
return fmt.Errorf("Missing parameter")
|
|
}
|
|
}
|
|
@@ -1232,7 +1222,7 @@ func (s *Server) getContainersByName(eng *engine.Engine, version version.Version
|
|
return writeJSON(w, http.StatusOK, containerJSON)
|
|
return writeJSON(w, http.StatusOK, containerJSON)
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) getExecByID(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) getExecByID(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if vars == nil {
|
|
if vars == nil {
|
|
return fmt.Errorf("Missing parameter 'id'")
|
|
return fmt.Errorf("Missing parameter 'id'")
|
|
}
|
|
}
|
|
@@ -1245,7 +1235,7 @@ func (s *Server) getExecByID(eng *engine.Engine, version version.Version, w http
|
|
return writeJSON(w, http.StatusOK, eConfig)
|
|
return writeJSON(w, http.StatusOK, eConfig)
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) getImagesByName(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) getImagesByName(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if vars == nil {
|
|
if vars == nil {
|
|
return fmt.Errorf("Missing parameter")
|
|
return fmt.Errorf("Missing parameter")
|
|
}
|
|
}
|
|
@@ -1268,7 +1258,7 @@ func (s *Server) getImagesByName(eng *engine.Engine, version version.Version, w
|
|
return writeJSON(w, http.StatusOK, imageInspect)
|
|
return writeJSON(w, http.StatusOK, imageInspect)
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) postBuild(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) postBuild(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if version.LessThan("1.3") {
|
|
if version.LessThan("1.3") {
|
|
return fmt.Errorf("Multipart upload for build is no longer supported. Please upgrade your docker client.")
|
|
return fmt.Errorf("Multipart upload for build is no longer supported. Please upgrade your docker client.")
|
|
}
|
|
}
|
|
@@ -1363,7 +1353,7 @@ func (s *Server) postBuild(eng *engine.Engine, version version.Version, w http.R
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) postContainersCopy(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) postContainersCopy(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if vars == nil {
|
|
if vars == nil {
|
|
return fmt.Errorf("Missing parameter")
|
|
return fmt.Errorf("Missing parameter")
|
|
}
|
|
}
|
|
@@ -1413,7 +1403,7 @@ func (s *Server) postContainersCopy(eng *engine.Engine, version version.Version,
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) postContainerExecCreate(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) postContainerExecCreate(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if err := parseForm(r); err != nil {
|
|
if err := parseForm(r); err != nil {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
@@ -1442,7 +1432,7 @@ func (s *Server) postContainerExecCreate(eng *engine.Engine, version version.Ver
|
|
}
|
|
}
|
|
|
|
|
|
// TODO(vishh): Refactor the code to avoid having to specify stream config as part of both create and start.
|
|
// TODO(vishh): Refactor the code to avoid having to specify stream config as part of both create and start.
|
|
-func (s *Server) postContainerExecStart(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) postContainerExecStart(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if err := parseForm(r); err != nil {
|
|
if err := parseForm(r); err != nil {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
@@ -1495,7 +1485,7 @@ func (s *Server) postContainerExecStart(eng *engine.Engine, version version.Vers
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) postContainerExecResize(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) postContainerExecResize(version version.Version, 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
|
|
}
|
|
}
|
|
@@ -1515,7 +1505,7 @@ func (s *Server) postContainerExecResize(eng *engine.Engine, version version.Ver
|
|
return s.daemon.ContainerExecResize(vars["name"], height, width)
|
|
return s.daemon.ContainerExecResize(vars["name"], height, width)
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) optionsHandler(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) optionsHandler(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
w.WriteHeader(http.StatusOK)
|
|
w.WriteHeader(http.StatusOK)
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
@@ -1526,12 +1516,12 @@ func writeCorsHeaders(w http.ResponseWriter, r *http.Request, corsHeaders string
|
|
w.Header().Add("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT, OPTIONS")
|
|
w.Header().Add("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT, OPTIONS")
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) ping(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
|
|
|
+func (s *Server) ping(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
_, err := w.Write([]byte{'O', 'K'})
|
|
_, err := w.Write([]byte{'O', 'K'})
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
-func makeHttpHandler(eng *engine.Engine, logging bool, localMethod string, localRoute string, handlerFunc HttpApiFunc, corsHeaders string, dockerVersion version.Version) http.HandlerFunc {
|
|
|
|
|
|
+func makeHttpHandler(logging bool, localMethod string, localRoute string, handlerFunc HttpApiFunc, corsHeaders string, dockerVersion version.Version) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
// log the request
|
|
// log the request
|
|
logrus.Debugf("Calling %s %s", localMethod, localRoute)
|
|
logrus.Debugf("Calling %s %s", localMethod, localRoute)
|
|
@@ -1559,7 +1549,7 @@ func makeHttpHandler(eng *engine.Engine, logging bool, localMethod string, local
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- if err := handlerFunc(eng, version, w, r, mux.Vars(r)); err != nil {
|
|
|
|
|
|
+ if err := handlerFunc(version, w, r, mux.Vars(r)); err != nil {
|
|
logrus.Errorf("Handler for %s %s returned error: %s", localMethod, localRoute, err)
|
|
logrus.Errorf("Handler for %s %s returned error: %s", localMethod, localRoute, err)
|
|
httpError(w, err)
|
|
httpError(w, err)
|
|
}
|
|
}
|
|
@@ -1567,7 +1557,7 @@ func makeHttpHandler(eng *engine.Engine, logging bool, localMethod string, local
|
|
}
|
|
}
|
|
|
|
|
|
// we keep enableCors just for legacy usage, need to be removed in the future
|
|
// we keep enableCors just for legacy usage, need to be removed in the future
|
|
-func createRouter(s *Server, eng *engine.Engine) *mux.Router {
|
|
|
|
|
|
+func createRouter(s *Server) *mux.Router {
|
|
r := mux.NewRouter()
|
|
r := mux.NewRouter()
|
|
if os.Getenv("DEBUG") != "" {
|
|
if os.Getenv("DEBUG") != "" {
|
|
ProfilerSetup(r, "/debug/")
|
|
ProfilerSetup(r, "/debug/")
|
|
@@ -1644,7 +1634,7 @@ func createRouter(s *Server, eng *engine.Engine) *mux.Router {
|
|
localMethod := method
|
|
localMethod := method
|
|
|
|
|
|
// build the handler function
|
|
// build the handler function
|
|
- f := makeHttpHandler(eng, s.cfg.Logging, localMethod, localRoute, localFct, corsHeaders, version.Version(s.cfg.Version))
|
|
|
|
|
|
+ f := makeHttpHandler(s.cfg.Logging, localMethod, localRoute, localFct, corsHeaders, version.Version(s.cfg.Version))
|
|
|
|
|
|
// add the new route
|
|
// add the new route
|
|
if localRoute == "" {
|
|
if localRoute == "" {
|
|
@@ -1659,23 +1649,6 @@ func createRouter(s *Server, eng *engine.Engine) *mux.Router {
|
|
return r
|
|
return r
|
|
}
|
|
}
|
|
|
|
|
|
-// ServeRequest processes a single http request to the docker remote api.
|
|
|
|
-// FIXME: refactor this to be part of Server and not require re-creating a new
|
|
|
|
-// router each time. This requires first moving ListenAndServe into Server.
|
|
|
|
-func ServeRequest(eng *engine.Engine, apiversion version.Version, w http.ResponseWriter, req *http.Request) {
|
|
|
|
- cfg := &ServerConfig{
|
|
|
|
- EnableCors: true,
|
|
|
|
- Version: string(apiversion),
|
|
|
|
- }
|
|
|
|
- api := New(cfg, eng)
|
|
|
|
- daemon, _ := eng.HackGetGlobalVar("httpapi.daemon").(*daemon.Daemon)
|
|
|
|
- api.AcceptConnections(daemon)
|
|
|
|
- router := createRouter(api, eng)
|
|
|
|
- // Insert APIVERSION into the request as a convenience
|
|
|
|
- req.URL.Path = fmt.Sprintf("/v%s%s", apiversion, req.URL.Path)
|
|
|
|
- router.ServeHTTP(w, req)
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
func allocateDaemonPort(addr string) error {
|
|
func allocateDaemonPort(addr string) error {
|
|
host, port, err := net.SplitHostPort(addr)
|
|
host, port, err := net.SplitHostPort(addr)
|
|
if err != nil {
|
|
if err != nil {
|