Ver Fonte

Implement getExitCode with standalone client lib.

Signed-off-by: David Calavera <david.calavera@gmail.com>
David Calavera há 9 anos atrás
pai
commit
7df71ca31d
3 ficheiros alterados com 10 adições e 16 exclusões
  1. 6 1
      api/client/lib/errors.go
  2. 1 5
      api/client/lib/request.go
  3. 3 10
      api/client/utils.go

+ 6 - 1
api/client/lib/errors.go

@@ -1,6 +1,11 @@
 package lib
 package lib
 
 
-import "fmt"
+import (
+	"errors"
+	"fmt"
+)
+
+var ErrConnectionFailed = errors.New("Cannot connect to the Docker daemon. Is the docker daemon running on this host?")
 
 
 // imageNotFoundError implements an error returned when an image is not in the docker host.
 // imageNotFoundError implements an error returned when an image is not in the docker host.
 type imageNotFoundError struct {
 type imageNotFoundError struct {

+ 1 - 5
api/client/lib/request.go

@@ -109,7 +109,7 @@ func (cli *Client) sendClientRequest(method, path string, query url.Values, in i
 
 
 	if err != nil {
 	if err != nil {
 		if utils.IsTimeout(err) || strings.Contains(err.Error(), "connection refused") || strings.Contains(err.Error(), "dial unix") {
 		if utils.IsTimeout(err) || strings.Contains(err.Error(), "connection refused") || strings.Contains(err.Error(), "dial unix") {
-			return serverResp, errConnectionFailed
+			return serverResp, ErrConnectionFailed
 		}
 		}
 
 
 		if cli.Scheme == "http" && strings.Contains(err.Error(), "malformed HTTP response") {
 		if cli.Scheme == "http" && strings.Contains(err.Error(), "malformed HTTP response") {
@@ -148,11 +148,7 @@ func encodeData(data interface{}) (*bytes.Buffer, error) {
 	return params, nil
 	return params, nil
 }
 }
 
 
-<<<<<<< HEAD
 func ensureReaderClosed(response *ServerResponse) {
 func ensureReaderClosed(response *ServerResponse) {
-=======
-func ensureReaderClosed(response *serverResponse) {
->>>>>>> 9c13063... Implement docker network with standalone client lib.
 	if response != nil && response.body != nil {
 	if response != nil && response.body != nil {
 		response.body.Close()
 		response.body.Close()
 	}
 	}

+ 3 - 10
api/client/utils.go

@@ -19,7 +19,7 @@ import (
 
 
 	"github.com/Sirupsen/logrus"
 	"github.com/Sirupsen/logrus"
 	"github.com/docker/docker/api"
 	"github.com/docker/docker/api"
-	"github.com/docker/docker/api/types"
+	"github.com/docker/docker/api/client/lib"
 	"github.com/docker/docker/cliconfig"
 	"github.com/docker/docker/cliconfig"
 	"github.com/docker/docker/dockerversion"
 	"github.com/docker/docker/dockerversion"
 	"github.com/docker/docker/pkg/jsonmessage"
 	"github.com/docker/docker/pkg/jsonmessage"
@@ -263,22 +263,15 @@ func (cli *DockerCli) resizeTty(id string, isExec bool) {
 // getExitCode perform an inspect on the container. It returns
 // getExitCode perform an inspect on the container. It returns
 // the running state and the exit code.
 // the running state and the exit code.
 func getExitCode(cli *DockerCli, containerID string) (bool, int, error) {
 func getExitCode(cli *DockerCli, containerID string) (bool, int, error) {
-	serverResp, err := cli.call("GET", "/containers/"+containerID+"/json", nil, nil)
+	c, err := cli.client.ContainerInspect(containerID)
 	if err != nil {
 	if err != nil {
 		// If we can't connect, then the daemon probably died.
 		// If we can't connect, then the daemon probably died.
-		if err != errConnectionFailed {
+		if err != lib.ErrConnectionFailed {
 			return false, -1, err
 			return false, -1, err
 		}
 		}
 		return false, -1, nil
 		return false, -1, nil
 	}
 	}
 
 
-	defer serverResp.body.Close()
-
-	var c types.ContainerJSON
-	if err := json.NewDecoder(serverResp.body).Decode(&c); err != nil {
-		return false, -1, err
-	}
-
 	return c.State.Running, c.State.ExitCode, nil
 	return c.State.Running, c.State.ExitCode, nil
 }
 }