2016-01-29 20:53:56 +01:00
|
|
|
// Copyright 2015 go-dockerclient authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package docker
|
|
|
|
|
2016-04-11 00:16:10 +02:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"strings"
|
|
|
|
)
|
2016-01-29 20:53:56 +01:00
|
|
|
|
|
|
|
// Version returns version information about the docker server.
|
|
|
|
//
|
|
|
|
// See https://goo.gl/ND9R8L for more details.
|
|
|
|
func (c *Client) Version() (*Env, error) {
|
|
|
|
resp, err := c.do("GET", "/version", doOptions{})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
var env Env
|
|
|
|
if err := env.Decode(resp.Body); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &env, nil
|
|
|
|
}
|
|
|
|
|
2016-04-11 00:16:10 +02:00
|
|
|
// DockerInfo contains information about the Docker server
|
|
|
|
//
|
|
|
|
// See https://goo.gl/bHUoz9 for more details.
|
|
|
|
type DockerInfo struct {
|
|
|
|
ID string
|
|
|
|
Containers int
|
|
|
|
ContainersRunning int
|
|
|
|
ContainersPaused int
|
|
|
|
ContainersStopped int
|
|
|
|
Images int
|
|
|
|
Driver string
|
|
|
|
DriverStatus [][2]string
|
|
|
|
SystemStatus [][2]string
|
|
|
|
Plugins PluginsInfo
|
|
|
|
MemoryLimit bool
|
|
|
|
SwapLimit bool
|
|
|
|
KernelMemory bool
|
|
|
|
CPUCfsPeriod bool `json:"CpuCfsPeriod"`
|
|
|
|
CPUCfsQuota bool `json:"CpuCfsQuota"`
|
|
|
|
CPUShares bool
|
|
|
|
CPUSet bool
|
|
|
|
IPv4Forwarding bool
|
|
|
|
BridgeNfIptables bool
|
|
|
|
BridgeNfIP6tables bool `json:"BridgeNfIp6tables"`
|
|
|
|
Debug bool
|
|
|
|
NFd int
|
|
|
|
OomKillDisable bool
|
|
|
|
NGoroutines int
|
|
|
|
SystemTime string
|
|
|
|
ExecutionDriver string
|
|
|
|
LoggingDriver string
|
|
|
|
CgroupDriver string
|
|
|
|
NEventsListener int
|
|
|
|
KernelVersion string
|
|
|
|
OperatingSystem string
|
|
|
|
OSType string
|
|
|
|
Architecture string
|
|
|
|
IndexServerAddress string
|
|
|
|
NCPU int
|
|
|
|
MemTotal int64
|
|
|
|
DockerRootDir string
|
|
|
|
HTTPProxy string `json:"HttpProxy"`
|
|
|
|
HTTPSProxy string `json:"HttpsProxy"`
|
|
|
|
NoProxy string
|
|
|
|
Name string
|
|
|
|
Labels []string
|
|
|
|
ExperimentalBuild bool
|
|
|
|
ServerVersion string
|
|
|
|
ClusterStore string
|
|
|
|
ClusterAdvertise string
|
|
|
|
}
|
|
|
|
|
|
|
|
// PluginsInfo is a struct with the plugins registered with the docker daemon
|
|
|
|
//
|
|
|
|
// for more information, see: https://goo.gl/bHUoz9
|
|
|
|
type PluginsInfo struct {
|
|
|
|
// List of Volume plugins registered
|
|
|
|
Volume []string
|
|
|
|
// List of Network plugins registered
|
|
|
|
Network []string
|
|
|
|
// List of Authorization plugins registered
|
|
|
|
Authorization []string
|
|
|
|
}
|
|
|
|
|
2016-01-29 20:53:56 +01:00
|
|
|
// Info returns system-wide information about the Docker server.
|
|
|
|
//
|
|
|
|
// See https://goo.gl/ElTHi2 for more details.
|
2016-04-11 00:16:10 +02:00
|
|
|
func (c *Client) Info() (*DockerInfo, error) {
|
2016-01-29 20:53:56 +01:00
|
|
|
resp, err := c.do("GET", "/info", doOptions{})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
2016-04-11 00:16:10 +02:00
|
|
|
var info DockerInfo
|
|
|
|
if err := json.NewDecoder(resp.Body).Decode(&info); err != nil {
|
2016-01-29 20:53:56 +01:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &info, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParseRepositoryTag gets the name of the repository and returns it splitted
|
|
|
|
// in two parts: the repository and the tag.
|
|
|
|
//
|
|
|
|
// Some examples:
|
|
|
|
//
|
|
|
|
// localhost.localdomain:5000/samalba/hipache:latest -> localhost.localdomain:5000/samalba/hipache, latest
|
|
|
|
// localhost.localdomain:5000/samalba/hipache -> localhost.localdomain:5000/samalba/hipache, ""
|
|
|
|
func ParseRepositoryTag(repoTag string) (repository string, tag string) {
|
|
|
|
n := strings.LastIndex(repoTag, ":")
|
|
|
|
if n < 0 {
|
|
|
|
return repoTag, ""
|
|
|
|
}
|
|
|
|
if tag := repoTag[n+1:]; !strings.Contains(tag, "/") {
|
|
|
|
return repoTag[:n], tag
|
|
|
|
}
|
|
|
|
return repoTag, ""
|
|
|
|
}
|