mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Implement docker info with standalone client lib.
Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
parent
6bf757500b
commit
900ad2897f
2 changed files with 56 additions and 43 deletions
|
@ -1,12 +1,9 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
Cli "github.com/docker/docker/cli"
|
||||
"github.com/docker/docker/pkg/httputils"
|
||||
"github.com/docker/docker/pkg/ioutils"
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/pkg/units"
|
||||
|
@ -21,18 +18,11 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
|
|||
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
serverResp, err := cli.call("GET", "/info", nil, nil)
|
||||
info, err := cli.client.Info()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer serverResp.body.Close()
|
||||
|
||||
info := &types.Info{}
|
||||
if err := json.NewDecoder(serverResp.body).Decode(info); err != nil {
|
||||
return fmt.Errorf("Error reading remote info: %v", err)
|
||||
}
|
||||
|
||||
fmt.Fprintf(cli.out, "Containers: %d\n", info.Containers)
|
||||
fmt.Fprintf(cli.out, "Images: %d\n", info.Images)
|
||||
ioutils.FprintfIfNotEmpty(cli.out, "Server Version: %s\n", info.ServerVersion)
|
||||
|
@ -90,38 +80,36 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
|
|||
}
|
||||
|
||||
// Only output these warnings if the server does not support these features
|
||||
if h, err := httputils.ParseServerHeader(serverResp.header.Get("Server")); err == nil {
|
||||
if h.OS != "windows" {
|
||||
if !info.MemoryLimit {
|
||||
fmt.Fprintf(cli.err, "WARNING: No memory limit support\n")
|
||||
}
|
||||
if !info.SwapLimit {
|
||||
fmt.Fprintf(cli.err, "WARNING: No swap limit support\n")
|
||||
}
|
||||
if !info.OomKillDisable {
|
||||
fmt.Fprintf(cli.err, "WARNING: No oom kill disable support\n")
|
||||
}
|
||||
if !info.CPUCfsQuota {
|
||||
fmt.Fprintf(cli.err, "WARNING: No cpu cfs quota support\n")
|
||||
}
|
||||
if !info.CPUCfsPeriod {
|
||||
fmt.Fprintf(cli.err, "WARNING: No cpu cfs period support\n")
|
||||
}
|
||||
if !info.CPUShares {
|
||||
fmt.Fprintf(cli.err, "WARNING: No cpu shares support\n")
|
||||
}
|
||||
if !info.CPUSet {
|
||||
fmt.Fprintf(cli.err, "WARNING: No cpuset support\n")
|
||||
}
|
||||
if !info.IPv4Forwarding {
|
||||
fmt.Fprintf(cli.err, "WARNING: IPv4 forwarding is disabled\n")
|
||||
}
|
||||
if !info.BridgeNfIptables {
|
||||
fmt.Fprintf(cli.err, "WARNING: bridge-nf-call-iptables is disabled\n")
|
||||
}
|
||||
if !info.BridgeNfIP6tables {
|
||||
fmt.Fprintf(cli.err, "WARNING: bridge-nf-call-ip6tables is disabled\n")
|
||||
}
|
||||
if info.OSType != "windows" {
|
||||
if !info.MemoryLimit {
|
||||
fmt.Fprintf(cli.err, "WARNING: No memory limit support\n")
|
||||
}
|
||||
if !info.SwapLimit {
|
||||
fmt.Fprintf(cli.err, "WARNING: No swap limit support\n")
|
||||
}
|
||||
if !info.OomKillDisable {
|
||||
fmt.Fprintf(cli.err, "WARNING: No oom kill disable support\n")
|
||||
}
|
||||
if !info.CPUCfsQuota {
|
||||
fmt.Fprintf(cli.err, "WARNING: No cpu cfs quota support\n")
|
||||
}
|
||||
if !info.CPUCfsPeriod {
|
||||
fmt.Fprintf(cli.err, "WARNING: No cpu cfs period support\n")
|
||||
}
|
||||
if !info.CPUShares {
|
||||
fmt.Fprintf(cli.err, "WARNING: No cpu shares support\n")
|
||||
}
|
||||
if !info.CPUSet {
|
||||
fmt.Fprintf(cli.err, "WARNING: No cpuset support\n")
|
||||
}
|
||||
if !info.IPv4Forwarding {
|
||||
fmt.Fprintf(cli.err, "WARNING: IPv4 forwarding is disabled\n")
|
||||
}
|
||||
if !info.BridgeNfIptables {
|
||||
fmt.Fprintf(cli.err, "WARNING: bridge-nf-call-iptables is disabled\n")
|
||||
}
|
||||
if !info.BridgeNfIP6tables {
|
||||
fmt.Fprintf(cli.err, "WARNING: bridge-nf-call-ip6tables is disabled\n")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
25
api/client/lib/info.go
Normal file
25
api/client/lib/info.go
Normal file
|
@ -0,0 +1,25 @@
|
|||
package lib
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
)
|
||||
|
||||
// Info returns information about the docker server.
|
||||
func (cli *Client) Info() (types.Info, error) {
|
||||
var info types.Info
|
||||
serverResp, err := cli.GET("/info", url.Values{}, nil)
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
defer serverResp.body.Close()
|
||||
|
||||
if err := json.NewDecoder(serverResp.body).Decode(&info); err != nil {
|
||||
return info, fmt.Errorf("Error reading remote info: %v", err)
|
||||
}
|
||||
|
||||
return info, nil
|
||||
}
|
Loading…
Add table
Reference in a new issue