Cleanup version introspection

* Unify version checking code into version.go
* Make 'version' available as a job in the engine
* Use simplified version checking code when setting user agent for registry client.
This commit is contained in:
Solomon Hykes 2013-12-08 07:35:24 +00:00
parent f806818154
commit 869a11bc93
2 changed files with 40 additions and 22 deletions

View file

@ -144,27 +144,6 @@ func (v *simpleVersionInfo) Version() string {
return v.version
}
// versionCheckers() returns version informations of:
// docker, go, git-commit (of the docker) and the host's kernel.
//
// Such information will be used on call to NewRegistry().
func (srv *Server) versionInfos() []utils.VersionInfo {
v := srv.DockerVersion()
ret := append(make([]utils.VersionInfo, 0, 4), &simpleVersionInfo{"docker", v.Version})
if len(v.GoVersion) > 0 {
ret = append(ret, &simpleVersionInfo{"go", v.GoVersion})
}
if len(v.GitCommit) > 0 {
ret = append(ret, &simpleVersionInfo{"git-commit", v.GitCommit})
}
if kernelVersion, err := utils.GetKernelVersion(); err == nil {
ret = append(ret, &simpleVersionInfo{"kernel", kernelVersion.String()})
}
return ret
}
// ContainerKill send signal to the container
// If no signal is given (sig 0), then Kill with SIGKILL and wait
// for the container to exit.
@ -1874,7 +1853,13 @@ func NewServer(eng *engine.Engine, config *DaemonConfig) (*Server, error) {
func (srv *Server) HTTPRequestFactory(metaHeaders map[string][]string) *utils.HTTPRequestFactory {
srv.Lock()
defer srv.Unlock()
ud := utils.NewHTTPUserAgentDecorator(srv.versionInfos()...)
v := dockerVersion()
httpVersion := make([]utils.VersionInfo, 0, 4)
httpVersion = append(httpVersion, &simpleVersionInfo{"docker", v.Get("Version")})
httpVersion = append(httpVersion, &simpleVersionInfo{"go", v.Get("GoVersion")})
httpVersion = append(httpVersion, &simpleVersionInfo{"git-commit", v.Get("GitCommit")})
httpVersion = append(httpVersion, &simpleVersionInfo{"kernel", v.Get("KernelVersion")})
ud := utils.NewHTTPUserAgentDecorator(httpVersion...)
md := &utils.HTTPMetaHeadersDecorator{
Headers: metaHeaders,
}

33
version.go Normal file
View file

@ -0,0 +1,33 @@
package docker
import (
"github.com/dotcloud/docker/engine"
"github.com/dotcloud/docker/utils"
"runtime"
)
func init() {
engine.Register("version", jobVersion)
}
func jobVersion(job *engine.Job) engine.Status {
if _, err := dockerVersion().WriteTo(job.Stdout); err != nil {
job.Errorf("%s", err)
return engine.StatusErr
}
return engine.StatusOK
}
// dockerVersion returns detailed version information in the form of a queriable
// environment.
func dockerVersion() *engine.Env {
v := &engine.Env{}
v.Set("Version", VERSION)
v.Set("GitCommit", GITCOMMIT)
v.Set("GoVersion", runtime.Version())
// FIXME:utils.GetKernelVersion should only be needed here
if kernelVersion, err := utils.GetKernelVersion(); err == nil {
v.Set("KernelVersion", kernelVersion.String())
}
return v
}