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
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
|
||||||
Cli "github.com/docker/docker/cli"
|
Cli "github.com/docker/docker/cli"
|
||||||
"github.com/docker/docker/pkg/httputils"
|
|
||||||
"github.com/docker/docker/pkg/ioutils"
|
"github.com/docker/docker/pkg/ioutils"
|
||||||
flag "github.com/docker/docker/pkg/mflag"
|
flag "github.com/docker/docker/pkg/mflag"
|
||||||
"github.com/docker/docker/pkg/units"
|
"github.com/docker/docker/pkg/units"
|
||||||
|
@ -21,18 +18,11 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
|
||||||
|
|
||||||
cmd.ParseFlags(args, true)
|
cmd.ParseFlags(args, true)
|
||||||
|
|
||||||
serverResp, err := cli.call("GET", "/info", nil, nil)
|
info, err := cli.client.Info()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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, "Containers: %d\n", info.Containers)
|
||||||
fmt.Fprintf(cli.out, "Images: %d\n", info.Images)
|
fmt.Fprintf(cli.out, "Images: %d\n", info.Images)
|
||||||
ioutils.FprintfIfNotEmpty(cli.out, "Server Version: %s\n", info.ServerVersion)
|
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
|
// Only output these warnings if the server does not support these features
|
||||||
if h, err := httputils.ParseServerHeader(serverResp.header.Get("Server")); err == nil {
|
if info.OSType != "windows" {
|
||||||
if h.OS != "windows" {
|
if !info.MemoryLimit {
|
||||||
if !info.MemoryLimit {
|
fmt.Fprintf(cli.err, "WARNING: No memory limit support\n")
|
||||||
fmt.Fprintf(cli.err, "WARNING: No memory limit support\n")
|
}
|
||||||
}
|
if !info.SwapLimit {
|
||||||
if !info.SwapLimit {
|
fmt.Fprintf(cli.err, "WARNING: No swap limit support\n")
|
||||||
fmt.Fprintf(cli.err, "WARNING: No swap limit support\n")
|
}
|
||||||
}
|
if !info.OomKillDisable {
|
||||||
if !info.OomKillDisable {
|
fmt.Fprintf(cli.err, "WARNING: No oom kill disable support\n")
|
||||||
fmt.Fprintf(cli.err, "WARNING: No oom kill disable support\n")
|
}
|
||||||
}
|
if !info.CPUCfsQuota {
|
||||||
if !info.CPUCfsQuota {
|
fmt.Fprintf(cli.err, "WARNING: No cpu cfs quota support\n")
|
||||||
fmt.Fprintf(cli.err, "WARNING: No cpu cfs quota support\n")
|
}
|
||||||
}
|
if !info.CPUCfsPeriod {
|
||||||
if !info.CPUCfsPeriod {
|
fmt.Fprintf(cli.err, "WARNING: No cpu cfs period support\n")
|
||||||
fmt.Fprintf(cli.err, "WARNING: No cpu cfs period support\n")
|
}
|
||||||
}
|
if !info.CPUShares {
|
||||||
if !info.CPUShares {
|
fmt.Fprintf(cli.err, "WARNING: No cpu shares support\n")
|
||||||
fmt.Fprintf(cli.err, "WARNING: No cpu shares support\n")
|
}
|
||||||
}
|
if !info.CPUSet {
|
||||||
if !info.CPUSet {
|
fmt.Fprintf(cli.err, "WARNING: No cpuset support\n")
|
||||||
fmt.Fprintf(cli.err, "WARNING: No cpuset support\n")
|
}
|
||||||
}
|
if !info.IPv4Forwarding {
|
||||||
if !info.IPv4Forwarding {
|
fmt.Fprintf(cli.err, "WARNING: IPv4 forwarding is disabled\n")
|
||||||
fmt.Fprintf(cli.err, "WARNING: IPv4 forwarding is disabled\n")
|
}
|
||||||
}
|
if !info.BridgeNfIptables {
|
||||||
if !info.BridgeNfIptables {
|
fmt.Fprintf(cli.err, "WARNING: bridge-nf-call-iptables is disabled\n")
|
||||||
fmt.Fprintf(cli.err, "WARNING: bridge-nf-call-iptables is disabled\n")
|
}
|
||||||
}
|
if !info.BridgeNfIP6tables {
|
||||||
if !info.BridgeNfIP6tables {
|
fmt.Fprintf(cli.err, "WARNING: bridge-nf-call-ip6tables is disabled\n")
|
||||||
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