mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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:
parent
f806818154
commit
869a11bc93
2 changed files with 40 additions and 22 deletions
29
server.go
29
server.go
|
@ -144,27 +144,6 @@ func (v *simpleVersionInfo) Version() string {
|
||||||
return v.version
|
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
|
// ContainerKill send signal to the container
|
||||||
// If no signal is given (sig 0), then Kill with SIGKILL and wait
|
// If no signal is given (sig 0), then Kill with SIGKILL and wait
|
||||||
// for the container to exit.
|
// 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 {
|
func (srv *Server) HTTPRequestFactory(metaHeaders map[string][]string) *utils.HTTPRequestFactory {
|
||||||
srv.Lock()
|
srv.Lock()
|
||||||
defer srv.Unlock()
|
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{
|
md := &utils.HTTPMetaHeadersDecorator{
|
||||||
Headers: metaHeaders,
|
Headers: metaHeaders,
|
||||||
}
|
}
|
||||||
|
|
33
version.go
Normal file
33
version.go
Normal 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
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue