|
@@ -8,6 +8,7 @@ import (
|
|
|
"strings"
|
|
|
"time"
|
|
|
|
|
|
+ "golang.org/x/net/context"
|
|
|
"golang.org/x/net/websocket"
|
|
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
@@ -19,7 +20,7 @@ import (
|
|
|
"github.com/docker/docker/runconfig"
|
|
|
)
|
|
|
|
|
|
-func (s *Server) getContainersJSON(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
+func (s *Server) getContainersJSON(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
if err := parseForm(r); err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -48,7 +49,7 @@ func (s *Server) getContainersJSON(version version.Version, w http.ResponseWrite
|
|
|
return writeJSON(w, http.StatusOK, containers)
|
|
|
}
|
|
|
|
|
|
-func (s *Server) getContainersStats(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
+func (s *Server) getContainersStats(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
if err := parseForm(r); err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -89,7 +90,7 @@ func (s *Server) getContainersStats(version version.Version, w http.ResponseWrit
|
|
|
return s.daemon.ContainerStats(container, config)
|
|
|
}
|
|
|
|
|
|
-func (s *Server) getContainersLogs(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
+func (s *Server) getContainersLogs(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
if err := parseForm(r); err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -146,7 +147,7 @@ func (s *Server) getContainersLogs(version version.Version, w http.ResponseWrite
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (s *Server) getContainersExport(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
+func (s *Server) getContainersExport(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
if vars == nil {
|
|
|
return fmt.Errorf("Missing parameter")
|
|
|
}
|
|
@@ -154,7 +155,7 @@ func (s *Server) getContainersExport(version version.Version, w http.ResponseWri
|
|
|
return s.daemon.ContainerExport(vars["name"], w)
|
|
|
}
|
|
|
|
|
|
-func (s *Server) postContainersStart(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
+func (s *Server) postContainersStart(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
if vars == nil {
|
|
|
return fmt.Errorf("Missing parameter")
|
|
|
}
|
|
@@ -190,7 +191,7 @@ func (s *Server) postContainersStart(version version.Version, w http.ResponseWri
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (s *Server) postContainersStop(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
+func (s *Server) postContainersStop(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
if err := parseForm(r); err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -212,7 +213,7 @@ func (s *Server) postContainersStop(version version.Version, w http.ResponseWrit
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (s *Server) postContainersKill(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
+func (s *Server) postContainersKill(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
if vars == nil {
|
|
|
return fmt.Errorf("Missing parameter")
|
|
|
}
|
|
@@ -250,6 +251,7 @@ func (s *Server) postContainersKill(version version.Version, w http.ResponseWrit
|
|
|
// Return error that's not caused because the container is stopped.
|
|
|
// Return error if the container is not running and the api is >= 1.20
|
|
|
// to keep backwards compatibility.
|
|
|
+ version, _ := ctx.Value("api-version").(version.Version)
|
|
|
if version.GreaterThanOrEqualTo("1.20") || !isStopped {
|
|
|
return fmt.Errorf("Cannot kill container %s: %v", name, err)
|
|
|
}
|
|
@@ -259,7 +261,7 @@ func (s *Server) postContainersKill(version version.Version, w http.ResponseWrit
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (s *Server) postContainersRestart(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
+func (s *Server) postContainersRestart(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
if err := parseForm(r); err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -278,7 +280,7 @@ func (s *Server) postContainersRestart(version version.Version, w http.ResponseW
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (s *Server) postContainersPause(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
+func (s *Server) postContainersPause(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
if vars == nil {
|
|
|
return fmt.Errorf("Missing parameter")
|
|
|
}
|
|
@@ -295,7 +297,7 @@ func (s *Server) postContainersPause(version version.Version, w http.ResponseWri
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (s *Server) postContainersUnpause(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
+func (s *Server) postContainersUnpause(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
if vars == nil {
|
|
|
return fmt.Errorf("Missing parameter")
|
|
|
}
|
|
@@ -312,7 +314,7 @@ func (s *Server) postContainersUnpause(version version.Version, w http.ResponseW
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (s *Server) postContainersWait(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
+func (s *Server) postContainersWait(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
if vars == nil {
|
|
|
return fmt.Errorf("Missing parameter")
|
|
|
}
|
|
@@ -327,7 +329,7 @@ func (s *Server) postContainersWait(version version.Version, w http.ResponseWrit
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-func (s *Server) getContainersChanges(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
+func (s *Server) getContainersChanges(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
if vars == nil {
|
|
|
return fmt.Errorf("Missing parameter")
|
|
|
}
|
|
@@ -340,7 +342,7 @@ func (s *Server) getContainersChanges(version version.Version, w http.ResponseWr
|
|
|
return writeJSON(w, http.StatusOK, changes)
|
|
|
}
|
|
|
|
|
|
-func (s *Server) getContainersTop(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
+func (s *Server) getContainersTop(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
if vars == nil {
|
|
|
return fmt.Errorf("Missing parameter")
|
|
|
}
|
|
@@ -357,7 +359,7 @@ func (s *Server) getContainersTop(version version.Version, w http.ResponseWriter
|
|
|
return writeJSON(w, http.StatusOK, procList)
|
|
|
}
|
|
|
|
|
|
-func (s *Server) postContainerRename(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
+func (s *Server) postContainerRename(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
if err := parseForm(r); err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -374,7 +376,7 @@ func (s *Server) postContainerRename(version version.Version, w http.ResponseWri
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (s *Server) postContainersCreate(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
+func (s *Server) postContainersCreate(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
if err := parseForm(r); err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -390,6 +392,7 @@ func (s *Server) postContainersCreate(version version.Version, w http.ResponseWr
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
+ version, _ := ctx.Value("api-version").(version.Version)
|
|
|
adjustCPUShares := version.LessThan("1.19")
|
|
|
|
|
|
container, warnings, err := s.daemon.ContainerCreate(name, config, hostConfig, adjustCPUShares)
|
|
@@ -403,7 +406,7 @@ func (s *Server) postContainersCreate(version version.Version, w http.ResponseWr
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-func (s *Server) deleteContainers(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
+func (s *Server) deleteContainers(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
if err := parseForm(r); err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -431,7 +434,7 @@ func (s *Server) deleteContainers(version version.Version, w http.ResponseWriter
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (s *Server) postContainersResize(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
+func (s *Server) postContainersResize(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
if err := parseForm(r); err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -451,7 +454,7 @@ func (s *Server) postContainersResize(version version.Version, w http.ResponseWr
|
|
|
return s.daemon.ContainerResize(vars["name"], height, width)
|
|
|
}
|
|
|
|
|
|
-func (s *Server) postContainersAttach(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
+func (s *Server) postContainersAttach(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
if err := parseForm(r); err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -493,7 +496,7 @@ func (s *Server) postContainersAttach(version version.Version, w http.ResponseWr
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (s *Server) wsContainersAttach(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
+func (s *Server) wsContainersAttach(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
|
if err := parseForm(r); err != nil {
|
|
|
return err
|
|
|
}
|