11package client
22
33import (
4+ "encoding/json"
45 "fmt"
56 "os"
6- "time"
77
8- "github.com/Sirupsen/logrus"
9- "github.com/docker/docker/engine"
8+ "github.com/docker/docker/api/types"
109 flag "github.com/docker/docker/pkg/mflag"
1110 "github.com/docker/docker/pkg/units"
1211)
@@ -19,127 +18,75 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
1918 cmd .Require (flag .Exact , 0 )
2019 cmd .ParseFlags (args , false )
2120
22- body , _ , err := readBody ( cli .call ("GET" , "/info" , nil , nil ) )
21+ rdr , _ , err := cli .call ("GET" , "/info" , nil , nil )
2322 if err != nil {
2423 return err
2524 }
2625
27- out := engine .NewOutput ()
28- remoteInfo , err := out .AddEnv ()
29- if err != nil {
30- return err
26+ info := & types.Info {}
27+ if err := json .NewDecoder (rdr ).Decode (info ); err != nil {
28+ return fmt .Errorf ("Error reading remote info: %v" , err )
3129 }
3230
33- if _ , err := out .Write (body ); err != nil {
34- logrus .Errorf ("Error reading remote info: %s" , err )
35- return err
36- }
37- out .Close ()
38-
39- if remoteInfo .Exists ("Containers" ) {
40- fmt .Fprintf (cli .out , "Containers: %d\n " , remoteInfo .GetInt ("Containers" ))
41- }
42- if remoteInfo .Exists ("Images" ) {
43- fmt .Fprintf (cli .out , "Images: %d\n " , remoteInfo .GetInt ("Images" ))
44- }
45- if remoteInfo .Exists ("Driver" ) {
46- fmt .Fprintf (cli .out , "Storage Driver: %s\n " , remoteInfo .Get ("Driver" ))
47- }
48- if remoteInfo .Exists ("DriverStatus" ) {
49- var driverStatus [][2 ]string
50- if err := remoteInfo .GetJson ("DriverStatus" , & driverStatus ); err != nil {
51- return err
52- }
53- for _ , pair := range driverStatus {
31+ fmt .Fprintf (cli .out , "Containers: %d\n " , info .Containers )
32+ fmt .Fprintf (cli .out , "Images: %d\n " , info .Images )
33+ fmt .Fprintf (cli .out , "Storage Driver: %s\n " , info .Driver )
34+ if info .DriverStatus != nil {
35+ for _ , pair := range info .DriverStatus {
5436 fmt .Fprintf (cli .out , " %s: %s\n " , pair [0 ], pair [1 ])
5537 }
5638 }
57- if remoteInfo .Exists ("ExecutionDriver" ) {
58- fmt .Fprintf (cli .out , "Execution Driver: %s\n " , remoteInfo .Get ("ExecutionDriver" ))
59- }
60- if remoteInfo .Exists ("LoggingDriver" ) {
61- fmt .Fprintf (cli .out , "Logging Driver: %s\n " , remoteInfo .Get ("LoggingDriver" ))
62- }
63- if remoteInfo .Exists ("KernelVersion" ) {
64- fmt .Fprintf (cli .out , "Kernel Version: %s\n " , remoteInfo .Get ("KernelVersion" ))
65- }
66- if remoteInfo .Exists ("OperatingSystem" ) {
67- fmt .Fprintf (cli .out , "Operating System: %s\n " , remoteInfo .Get ("OperatingSystem" ))
68- }
69- if remoteInfo .Exists ("NCPU" ) {
70- fmt .Fprintf (cli .out , "CPUs: %d\n " , remoteInfo .GetInt ("NCPU" ))
71- }
72- if remoteInfo .Exists ("MemTotal" ) {
73- fmt .Fprintf (cli .out , "Total Memory: %s\n " , units .BytesSize (float64 (remoteInfo .GetInt64 ("MemTotal" ))))
74- }
75- if remoteInfo .Exists ("Name" ) {
76- fmt .Fprintf (cli .out , "Name: %s\n " , remoteInfo .Get ("Name" ))
77- }
78- if remoteInfo .Exists ("ID" ) {
79- fmt .Fprintf (cli .out , "ID: %s\n " , remoteInfo .Get ("ID" ))
80- }
39+ fmt .Fprintf (cli .out , "Execution Driver: %s\n " , info .ExecutionDriver )
40+ fmt .Fprintf (cli .out , "Logging Driver: %s\n " , info .LoggingDriver )
41+ fmt .Fprintf (cli .out , "Kernel Version: %s\n " , info .KernelVersion )
42+ fmt .Fprintf (cli .out , "Operating System: %s\n " , info .OperatingSystem )
43+ fmt .Fprintf (cli .out , "CPUs: %d\n " , info .NCPU )
44+ fmt .Fprintf (cli .out , "Total Memory: %s\n " , units .BytesSize (float64 (info .MemTotal )))
45+ fmt .Fprintf (cli .out , "Name: %s\n " , info .Name )
46+ fmt .Fprintf (cli .out , "ID: %s\n " , info .ID )
8147
82- if remoteInfo .GetBool ("Debug" ) || os .Getenv ("DEBUG" ) != "" {
83- if remoteInfo .Exists ("Debug" ) {
84- fmt .Fprintf (cli .out , "Debug mode (server): %v\n " , remoteInfo .GetBool ("Debug" ))
85- }
48+ if info .Debug || os .Getenv ("DEBUG" ) != "" {
49+ fmt .Fprintf (cli .out , "Debug mode (server): %v\n " , info .Debug )
8650 fmt .Fprintf (cli .out , "Debug mode (client): %v\n " , os .Getenv ("DEBUG" ) != "" )
87- if remoteInfo .Exists ("NFd" ) {
88- fmt .Fprintf (cli .out , "File Descriptors: %d\n " , remoteInfo .GetInt ("NFd" ))
89- }
90- if remoteInfo .Exists ("NGoroutines" ) {
91- fmt .Fprintf (cli .out , "Goroutines: %d\n " , remoteInfo .GetInt ("NGoroutines" ))
92- }
93- if remoteInfo .Exists ("SystemTime" ) {
94- t , err := remoteInfo .GetTime ("SystemTime" )
95- if err != nil {
96- logrus .Errorf ("Error reading system time: %v" , err )
97- } else {
98- fmt .Fprintf (cli .out , "System Time: %s\n " , t .Format (time .UnixDate ))
99- }
100- }
101- if remoteInfo .Exists ("NEventsListener" ) {
102- fmt .Fprintf (cli .out , "EventsListeners: %d\n " , remoteInfo .GetInt ("NEventsListener" ))
103- }
104- if initSha1 := remoteInfo .Get ("InitSha1" ); initSha1 != "" {
105- fmt .Fprintf (cli .out , "Init SHA1: %s\n " , initSha1 )
106- }
107- if initPath := remoteInfo .Get ("InitPath" ); initPath != "" {
108- fmt .Fprintf (cli .out , "Init Path: %s\n " , initPath )
109- }
110- if root := remoteInfo .Get ("DockerRootDir" ); root != "" {
111- fmt .Fprintf (cli .out , "Docker Root Dir: %s\n " , root )
112- }
51+ fmt .Fprintf (cli .out , "File Descriptors: %d\n " , info .NFd )
52+ fmt .Fprintf (cli .out , "Goroutines: %d\n " , info .NGoroutines )
53+ fmt .Fprintf (cli .out , "System Time: %s\n " , info .SystemTime )
54+ fmt .Fprintf (cli .out , "EventsListeners: %d\n " , info .NEventsListener )
55+ fmt .Fprintf (cli .out , "Init SHA1: %s\n " , info .InitSha1 )
56+ fmt .Fprintf (cli .out , "Init Path: %s\n " , info .InitPath )
57+ fmt .Fprintf (cli .out , "Docker Root Dir: %s\n " , info .DockerRootDir )
11358 }
114- if remoteInfo .Exists ("HttpProxy" ) {
115- fmt .Fprintf (cli .out , "Http Proxy: %s\n " , remoteInfo .Get ("HttpProxy" ))
59+
60+ if info .HttpProxy != "" {
61+ fmt .Fprintf (cli .out , "Http Proxy: %s\n " , info .HttpProxy )
11662 }
117- if remoteInfo . Exists ( " HttpsProxy" ) {
118- fmt .Fprintf (cli .out , "Https Proxy: %s\n " , remoteInfo . Get ( " HttpsProxy" ) )
63+ if info . HttpsProxy != "" {
64+ fmt .Fprintf (cli .out , "Https Proxy: %s\n " , info . HttpsProxy )
11965 }
120- if remoteInfo . Exists ( " NoProxy" ) {
121- fmt .Fprintf (cli .out , "No Proxy: %s\n " , remoteInfo . Get ( " NoProxy" ) )
66+ if info . NoProxy != "" {
67+ fmt .Fprintf (cli .out , "No Proxy: %s\n " , info . NoProxy )
12268 }
123- if len (remoteInfo .GetList ("IndexServerAddress" )) != 0 {
69+
70+ if info .IndexServerAddress != "" {
12471 cli .LoadConfigFile ()
125- u := cli .configFile .Configs [remoteInfo . Get ( " IndexServerAddress" ) ].Username
72+ u := cli .configFile .Configs [info . IndexServerAddress ].Username
12673 if len (u ) > 0 {
12774 fmt .Fprintf (cli .out , "Username: %v\n " , u )
128- fmt .Fprintf (cli .out , "Registry: %v\n " , remoteInfo . GetList ( " IndexServerAddress" ) )
75+ fmt .Fprintf (cli .out , "Registry: %v\n " , info . IndexServerAddress )
12976 }
13077 }
131- if remoteInfo . Exists ( "MemoryLimit" ) && ! remoteInfo . GetBool ( " MemoryLimit" ) {
78+ if ! info . MemoryLimit {
13279 fmt .Fprintf (cli .err , "WARNING: No memory limit support\n " )
13380 }
134- if remoteInfo . Exists ( "SwapLimit" ) && ! remoteInfo . GetBool ( " SwapLimit" ) {
81+ if ! info . SwapLimit {
13582 fmt .Fprintf (cli .err , "WARNING: No swap limit support\n " )
13683 }
137- if remoteInfo . Exists ( "IPv4Forwarding" ) && ! remoteInfo . GetBool ( " IPv4Forwarding" ) {
84+ if ! info . IPv4Forwarding {
13885 fmt .Fprintf (cli .err , "WARNING: IPv4 forwarding is disabled.\n " )
13986 }
140- if remoteInfo . Exists ( " Labels" ) {
87+ if info . Labels != nil {
14188 fmt .Fprintln (cli .out , "Labels:" )
142- for _ , attribute := range remoteInfo . GetList ( " Labels" ) {
89+ for _ , attribute := range info . Labels {
14390 fmt .Fprintf (cli .out , " %s\n " , attribute )
14491 }
14592 }
0 commit comments