| ... | ... |
@@ -216,7 +216,8 @@ func getImagesViz(srv *Server, version float64, w http.ResponseWriter, r *http.R |
| 216 | 216 |
} |
| 217 | 217 |
|
| 218 | 218 |
func getInfo(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
| 219 |
- return writeJSON(w, http.StatusOK, srv.DockerInfo()) |
|
| 219 |
+ srv.Eng.ServeHTTP(w, r) |
|
| 220 |
+ return nil |
|
| 220 | 221 |
} |
| 221 | 222 |
|
| 222 | 223 |
func getEvents(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
| ... | ... |
@@ -29,23 +29,6 @@ type ( |
| 29 | 29 |
VirtualSize int64 |
| 30 | 30 |
} |
| 31 | 31 |
|
| 32 |
- APIInfo struct {
|
|
| 33 |
- Debug bool |
|
| 34 |
- Containers int |
|
| 35 |
- Images int |
|
| 36 |
- Driver string `json:",omitempty"` |
|
| 37 |
- DriverStatus [][2]string `json:",omitempty"` |
|
| 38 |
- NFd int `json:",omitempty"` |
|
| 39 |
- NGoroutines int `json:",omitempty"` |
|
| 40 |
- MemoryLimit bool `json:",omitempty"` |
|
| 41 |
- SwapLimit bool `json:",omitempty"` |
|
| 42 |
- IPv4Forwarding bool `json:",omitempty"` |
|
| 43 |
- LXCVersion string `json:",omitempty"` |
|
| 44 |
- NEventsListener int `json:",omitempty"` |
|
| 45 |
- KernelVersion string `json:",omitempty"` |
|
| 46 |
- IndexServerAddress string `json:",omitempty"` |
|
| 47 |
- } |
|
| 48 |
- |
|
| 49 | 32 |
APITop struct {
|
| 50 | 33 |
Titles []string |
| 51 | 34 |
Processes [][]string |
| ... | ... |
@@ -433,42 +433,58 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
|
| 433 | 433 |
return err |
| 434 | 434 |
} |
| 435 | 435 |
|
| 436 |
- var out APIInfo |
|
| 437 |
- if err := json.Unmarshal(body, &out); err != nil {
|
|
| 436 |
+ out := engine.NewOutput() |
|
| 437 |
+ remoteInfo, err := out.AddEnv() |
|
| 438 |
+ if err != nil {
|
|
| 438 | 439 |
return err |
| 439 | 440 |
} |
| 440 | 441 |
|
| 441 |
- fmt.Fprintf(cli.out, "Containers: %d\n", out.Containers) |
|
| 442 |
- fmt.Fprintf(cli.out, "Images: %d\n", out.Images) |
|
| 443 |
- fmt.Fprintf(cli.out, "Driver: %s\n", out.Driver) |
|
| 444 |
- for _, pair := range out.DriverStatus {
|
|
| 445 |
- fmt.Fprintf(cli.out, " %s: %s\n", pair[0], pair[1]) |
|
| 442 |
+ if _, err := out.Write(body); err != nil {
|
|
| 443 |
+ utils.Errorf("Error reading remote info: %s\n", err)
|
|
| 444 |
+ return err |
|
| 445 |
+ } |
|
| 446 |
+ out.Close() |
|
| 447 |
+ |
|
| 448 |
+ fmt.Fprintf(cli.out, "Containers: %d\n", remoteInfo.GetInt("Containers"))
|
|
| 449 |
+ fmt.Fprintf(cli.out, "Images: %d\n", remoteInfo.GetInt("Images"))
|
|
| 450 |
+ fmt.Fprintf(cli.out, "Driver: %s\n", remoteInfo.Get("Driver"))
|
|
| 451 |
+ |
|
| 452 |
+ //FIXME:Cleanup this mess |
|
| 453 |
+ DriverStatus := remoteInfo.GetJson("DriverStatus")
|
|
| 454 |
+ if DriverStatus != nil {
|
|
| 455 |
+ if tab, ok := DriverStatus.([]interface{}); ok {
|
|
| 456 |
+ for _, line := range tab {
|
|
| 457 |
+ if pair, ok := line.([]interface{}); ok {
|
|
| 458 |
+ fmt.Fprintf(cli.out, " %s: %s\n", pair[0], pair[1]) |
|
| 459 |
+ } |
|
| 460 |
+ } |
|
| 461 |
+ } |
|
| 446 | 462 |
} |
| 447 |
- if out.Debug || os.Getenv("DEBUG") != "" {
|
|
| 448 |
- fmt.Fprintf(cli.out, "Debug mode (server): %v\n", out.Debug) |
|
| 463 |
+ if remoteInfo.GetBool("Debug") || os.Getenv("DEBUG") != "" {
|
|
| 464 |
+ fmt.Fprintf(cli.out, "Debug mode (server): %v\n", remoteInfo.GetBool("Debug"))
|
|
| 449 | 465 |
fmt.Fprintf(cli.out, "Debug mode (client): %v\n", os.Getenv("DEBUG") != "")
|
| 450 |
- fmt.Fprintf(cli.out, "Fds: %d\n", out.NFd) |
|
| 451 |
- fmt.Fprintf(cli.out, "Goroutines: %d\n", out.NGoroutines) |
|
| 452 |
- fmt.Fprintf(cli.out, "LXC Version: %s\n", out.LXCVersion) |
|
| 453 |
- fmt.Fprintf(cli.out, "EventsListeners: %d\n", out.NEventsListener) |
|
| 454 |
- fmt.Fprintf(cli.out, "Kernel Version: %s\n", out.KernelVersion) |
|
| 466 |
+ fmt.Fprintf(cli.out, "Fds: %d\n", remoteInfo.GetInt("NFd"))
|
|
| 467 |
+ fmt.Fprintf(cli.out, "Goroutines: %d\n", remoteInfo.GetInt("NGoroutines"))
|
|
| 468 |
+ fmt.Fprintf(cli.out, "LXC Version: %s\n", remoteInfo.Get("LXCVersion"))
|
|
| 469 |
+ fmt.Fprintf(cli.out, "EventsListeners: %d\n", remoteInfo.GetInt("NEventsListener"))
|
|
| 470 |
+ fmt.Fprintf(cli.out, "Kernel Version: %s\n", remoteInfo.Get("KernelVersion"))
|
|
| 455 | 471 |
} |
| 456 | 472 |
|
| 457 |
- if len(out.IndexServerAddress) != 0 {
|
|
| 473 |
+ if len(remoteInfo.GetList("IndexServerAddress")) != 0 {
|
|
| 458 | 474 |
cli.LoadConfigFile() |
| 459 |
- u := cli.configFile.Configs[out.IndexServerAddress].Username |
|
| 475 |
+ u := cli.configFile.Configs[remoteInfo.Get("IndexServerAddress")].Username
|
|
| 460 | 476 |
if len(u) > 0 {
|
| 461 | 477 |
fmt.Fprintf(cli.out, "Username: %v\n", u) |
| 462 |
- fmt.Fprintf(cli.out, "Registry: %v\n", out.IndexServerAddress) |
|
| 478 |
+ fmt.Fprintf(cli.out, "Registry: %v\n", remoteInfo.GetList("IndexServerAddress"))
|
|
| 463 | 479 |
} |
| 464 | 480 |
} |
| 465 |
- if !out.MemoryLimit {
|
|
| 481 |
+ if !remoteInfo.GetBool("MemoryLimit") {
|
|
| 466 | 482 |
fmt.Fprintf(cli.err, "WARNING: No memory limit support\n") |
| 467 | 483 |
} |
| 468 |
- if !out.SwapLimit {
|
|
| 484 |
+ if !remoteInfo.GetBool("SwapLimit") {
|
|
| 469 | 485 |
fmt.Fprintf(cli.err, "WARNING: No swap limit support\n") |
| 470 | 486 |
} |
| 471 |
- if !out.IPv4Forwarding {
|
|
| 487 |
+ if !remoteInfo.GetBool("IPv4Forwarding") {
|
|
| 472 | 488 |
fmt.Fprintf(cli.err, "WARNING: IPv4 forwarding is disabled.\n") |
| 473 | 489 |
} |
| 474 | 490 |
return nil |
| ... | ... |
@@ -72,13 +72,17 @@ func TestGetInfo(t *testing.T) {
|
| 72 | 72 |
} |
| 73 | 73 |
assertHttpNotError(r, t) |
| 74 | 74 |
|
| 75 |
- infos := &docker.APIInfo{}
|
|
| 76 |
- err = json.Unmarshal(r.Body.Bytes(), infos) |
|
| 75 |
+ out := engine.NewOutput() |
|
| 76 |
+ i, err := out.AddEnv() |
|
| 77 | 77 |
if err != nil {
|
| 78 | 78 |
t.Fatal(err) |
| 79 | 79 |
} |
| 80 |
- if infos.Images != len(initialImages) {
|
|
| 81 |
- t.Errorf("Expected images: %d, %d found", len(initialImages), infos.Images)
|
|
| 80 |
+ if _, err := io.Copy(out, r.Body); err != nil {
|
|
| 81 |
+ t.Fatal(err) |
|
| 82 |
+ } |
|
| 83 |
+ out.Close() |
|
| 84 |
+ if images := i.GetInt("Images"); images != int64(len(initialImages)) {
|
|
| 85 |
+ t.Errorf("Expected images: %d, %d found", len(initialImages), images)
|
|
| 82 | 86 |
} |
| 83 | 87 |
} |
| 84 | 88 |
|
| ... | ... |
@@ -111,6 +111,10 @@ func jobInitApi(job *engine.Job) engine.Status {
|
| 111 | 111 |
job.Error(err) |
| 112 | 112 |
return engine.StatusErr |
| 113 | 113 |
} |
| 114 |
+ if err := job.Eng.Register("info", srv.DockerInfo); err != nil {
|
|
| 115 |
+ job.Error(err) |
|
| 116 |
+ return engine.StatusErr |
|
| 117 |
+ } |
|
| 114 | 118 |
return engine.StatusOK |
| 115 | 119 |
} |
| 116 | 120 |
|
| ... | ... |
@@ -610,13 +614,13 @@ func (srv *Server) Images(all bool, filter string) ([]APIImages, error) {
|
| 610 | 610 |
return outs, nil |
| 611 | 611 |
} |
| 612 | 612 |
|
| 613 |
-func (srv *Server) DockerInfo() *APIInfo {
|
|
| 613 |
+func (srv *Server) DockerInfo(job *engine.Job) engine.Status {
|
|
| 614 | 614 |
images, _ := srv.runtime.graph.Map() |
| 615 |
- var imgcount int |
|
| 615 |
+ var imgcount int64 |
|
| 616 | 616 |
if images == nil {
|
| 617 | 617 |
imgcount = 0 |
| 618 | 618 |
} else {
|
| 619 |
- imgcount = len(images) |
|
| 619 |
+ imgcount = int64(len(images)) |
|
| 620 | 620 |
} |
| 621 | 621 |
lxcVersion := "" |
| 622 | 622 |
if output, err := exec.Command("lxc-version").CombinedOutput(); err == nil {
|
| ... | ... |
@@ -630,22 +634,26 @@ func (srv *Server) DockerInfo() *APIInfo {
|
| 630 | 630 |
kernelVersion = kv.String() |
| 631 | 631 |
} |
| 632 | 632 |
|
| 633 |
- return &APIInfo{
|
|
| 634 |
- Containers: len(srv.runtime.List()), |
|
| 635 |
- Images: imgcount, |
|
| 636 |
- Driver: srv.runtime.driver.String(), |
|
| 637 |
- DriverStatus: srv.runtime.driver.Status(), |
|
| 638 |
- MemoryLimit: srv.runtime.capabilities.MemoryLimit, |
|
| 639 |
- SwapLimit: srv.runtime.capabilities.SwapLimit, |
|
| 640 |
- IPv4Forwarding: !srv.runtime.capabilities.IPv4ForwardingDisabled, |
|
| 641 |
- Debug: os.Getenv("DEBUG") != "",
|
|
| 642 |
- NFd: utils.GetTotalUsedFds(), |
|
| 643 |
- NGoroutines: runtime.NumGoroutine(), |
|
| 644 |
- LXCVersion: lxcVersion, |
|
| 645 |
- NEventsListener: len(srv.events), |
|
| 646 |
- KernelVersion: kernelVersion, |
|
| 647 |
- IndexServerAddress: auth.IndexServerAddress(), |
|
| 633 |
+ v := &engine.Env{}
|
|
| 634 |
+ v.SetInt("Containers", int64(len(srv.runtime.List())))
|
|
| 635 |
+ v.SetInt("Images", imgcount)
|
|
| 636 |
+ v.Set("Driver", srv.runtime.driver.String())
|
|
| 637 |
+ v.SetJson("DriverStatus", srv.runtime.driver.Status())
|
|
| 638 |
+ v.SetBool("MemoryLimit", srv.runtime.capabilities.MemoryLimit)
|
|
| 639 |
+ v.SetBool("SwapLimit", srv.runtime.capabilities.SwapLimit)
|
|
| 640 |
+ v.SetBool("IPv4Forwarding", !srv.runtime.capabilities.IPv4ForwardingDisabled)
|
|
| 641 |
+ v.SetBool("Debug", os.Getenv("DEBUG") != "")
|
|
| 642 |
+ v.SetInt("NFd", int64(utils.GetTotalUsedFds()))
|
|
| 643 |
+ v.SetInt("NGoroutines", int64(runtime.NumGoroutine()))
|
|
| 644 |
+ v.Set("LXCVersion", lxcVersion)
|
|
| 645 |
+ v.SetInt("NEventsListener", int64(len(srv.events)))
|
|
| 646 |
+ v.Set("KernelVersion", kernelVersion)
|
|
| 647 |
+ v.Set("IndexServerAddress", auth.IndexServerAddress())
|
|
| 648 |
+ if _, err := v.WriteTo(job.Stdout); err != nil {
|
|
| 649 |
+ job.Error(err) |
|
| 650 |
+ return engine.StatusErr |
|
| 648 | 651 |
} |
| 652 |
+ return engine.StatusOK |
|
| 649 | 653 |
} |
| 650 | 654 |
|
| 651 | 655 |
func (srv *Server) ImageHistory(name string) ([]APIHistory, error) {
|