display warning on the server in debug in version don't match

This commit is contained in:
Victor Vieux 2013-05-09 20:24:49 +02:00
Родитель 4576e11121
Коммит 7c7619ecf8
2 изменённых файлов: 11 добавлений и 23 удалений

7
api.go
Просмотреть файл

@ -564,6 +564,13 @@ func ListenAndServe(addr string, srv *Server) error {
r.Path(localRoute).Methods(localMethod).HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Debugf("Calling %s %s", localMethod, localRoute)
log.Println(r.Method, r.RequestURI)
if strings.Contains(r.Header.Get("User-Agent"), "Docker-Client/") {
userAgent := strings.Split(r.Header.Get("User-Agent"), "/")
if len(userAgent) == 2 && userAgent[1] != VERSION {
Debugf("Warning: client and server don't have the same version (client: %s, server: %s)", userAgent[1], VERSION)
}
}
json, err := localFct(srv, w, r)
if err != nil {
httpError(w, err)

Просмотреть файл

@ -28,31 +28,8 @@ var (
GIT_COMMIT string
)
func checkRemoteVersion() error {
body, _, err := call("GET", "/version", nil)
if err != nil {
return fmt.Errorf("Can't connect to docker daemon. Is 'docker -d' running on this host?")
}
var out ApiVersion
err = json.Unmarshal(body, &out)
if err != nil {
Debugf("Error unmarshal: body: %s, err: %s\n", body, err)
return err
}
if out.Version != VERSION {
fmt.Fprintf(os.Stderr, "Warning: client and server don't have the same version (client: %s, server: %)", VERSION, out.Version)
}
return nil
}
func ParseCommands(args ...string) error {
if err := checkRemoteVersion(); err != nil {
return err
}
cmds := map[string]func(args ...string) error{
"attach": CmdAttach,
"build": CmdBuild,
@ -1177,6 +1154,7 @@ func call(method, path string, data interface{}) ([]byte, int, error) {
if err != nil {
return nil, -1, err
}
req.Header.Set("User-Agent", "Docker-Client/"+VERSION)
if data != nil {
req.Header.Set("Content-Type", "application/json")
} else if method == "POST" {
@ -1184,6 +1162,9 @@ func call(method, path string, data interface{}) ([]byte, int, error) {
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
if strings.Contains(err.Error(), "connection refused") {
return nil, -1, fmt.Errorf("Can't connect to docker daemon. Is 'docker -d' running on this host?")
}
return nil, -1, err
}
defer resp.Body.Close()