Files
weave-scope/vendor/github.com/fsouza/go-dockerclient/misc.go
Marc Carré a74f203668 Update fsouza/go-dockerclient to v1.2.0
```
gvt delete github.com/fsouza/go-dockerclient
gvt delete github.com/docker/docker/opts
gvt delete github.com/docker/docker/pkg/archive
gvt delete github.com/docker/docker/pkg/fileutils
gvt delete github.com/docker/docker/pkg/homedir
gvt delete github.com/docker/docker/pkg/idtools
gvt delete github.com/docker/docker/pkg/ioutils
gvt delete github.com/docker/docker/pkg/longpath
gvt delete github.com/docker/docker/pkg/mflag
gvt delete github.com/docker/docker/pkg/mount
gvt delete github.com/docker/docker/pkg/parsers
gvt delete github.com/docker/docker/pkg/pools
gvt delete github.com/docker/docker/pkg/promise
gvt delete github.com/docker/docker/pkg/stdcopy
gvt delete github.com/docker/docker/pkg/system
gvt delete github.com/docker/docker/pkg/term
gvt delete github.com/docker/docker/pkg/units
gvt delete github.com/docker/libcontainer/cgroups
gvt delete github.com/docker/distribution/digest
gvt delete github.com/docker/distribution/reference
gvt delete github.com/docker/distribution/vendor/github.com/stevvooe/resumable
gvt fetch --tag 1.2.0 github.com/fsouza/go-dockerclient
2018/07/23 17:03:36 Fetching: github.com/fsouza/go-dockerclient
2018/07/23 17:03:39 · Skipping (existing): github.com/docker/go-units
2018/07/23 17:03:39 · Fetching recursive dependency: github.com/docker/docker/pkg/jsonmessage
2018/07/23 17:03:51 ·· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/Nvveen/Gotty
2018/07/23 17:03:51 ·· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/docker/go-units
2018/07/23 17:03:51 ·· Fetching recursive dependency: github.com/docker/docker/pkg/term
2018/07/23 17:03:51 ··· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/Azure/go-ansiterm
2018/07/23 17:03:51 ··· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/sirupsen/logrus
2018/07/23 17:03:51 ···· Fetching recursive dependency: github.com/docker/docker/vendor/golang.org/x/sys/unix
2018/07/23 17:03:51 ···· Fetching recursive dependency: github.com/docker/docker/vendor/golang.org/x/crypto/ssh/terminal
2018/07/23 17:03:51 ····· Fetching recursive dependency: github.com/docker/docker/vendor/golang.org/x/sys/windows
2018/07/23 17:03:51 · Skipping (existing): github.com/gorilla/mux
2018/07/23 17:03:51 · Fetching recursive dependency: github.com/docker/docker/api/types/swarm
2018/07/23 17:03:51 ·· Fetching recursive dependency: github.com/docker/docker/api/types/network
2018/07/23 17:03:51 ··· Fetching recursive dependency: github.com/docker/docker/api/types/filters
2018/07/23 17:03:51 ···· Fetching recursive dependency: github.com/docker/docker/api/types/versions
2018/07/23 17:03:51 ····· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/docker/go-connections/nat
2018/07/23 17:03:51 ····· Fetching recursive dependency: github.com/docker/docker/api/types
2018/07/23 17:03:51 ······ Fetching recursive dependency: github.com/docker/docker/errdefs
2018/07/23 17:03:51 ······ Fetching recursive dependency: github.com/docker/docker/pkg/streamformatter
2018/07/23 17:03:51 ······· Fetching recursive dependency: github.com/docker/docker/pkg/progress
2018/07/23 17:03:51 ········ Fetching recursive dependency: github.com/docker/docker/vendor/golang.org/x/time/rate
2018/07/23 17:03:51 ········· Fetching recursive dependency: github.com/docker/docker/vendor/golang.org/x/net/context
2018/07/23 17:03:52 ······ Fetching recursive dependency: github.com/docker/docker/vendor/github.com/gogo/protobuf/proto
2018/07/23 17:03:52 ······ Fetching recursive dependency: github.com/docker/docker/vendor/github.com/opencontainers/image-spec/specs-go/v1
2018/07/23 17:03:52 ······· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/opencontainers/go-digest
2018/07/23 17:03:52 ······· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/opencontainers/image-spec/specs-go
2018/07/23 17:03:52 · Fetching recursive dependency: github.com/docker/docker/pkg/homedir
2018/07/23 17:03:52 ·· Fetching recursive dependency: github.com/docker/docker/pkg/idtools
2018/07/23 17:03:52 ··· Fetching recursive dependency: github.com/docker/docker/pkg/system
2018/07/23 17:03:52 ···· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/pkg/errors
2018/07/23 17:03:52 ···· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/Microsoft/go-winio
2018/07/23 17:03:52 ···· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/containerd/continuity/pathdriver
2018/07/23 17:03:52 ···· Fetching recursive dependency: github.com/docker/docker/pkg/mount
2018/07/23 17:03:52 ··· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/opencontainers/runc/libcontainer/user
2018/07/23 17:03:52 · Fetching recursive dependency: github.com/docker/docker/pkg/stdcopy
2018/07/23 17:03:52 · Fetching recursive dependency: github.com/docker/docker/pkg/archive
2018/07/23 17:03:52 ·· Fetching recursive dependency: github.com/docker/docker/pkg/pools
2018/07/23 17:03:52 ··· Fetching recursive dependency: github.com/docker/docker/pkg/ioutils
2018/07/23 17:03:52 ···· Fetching recursive dependency: github.com/docker/docker/pkg/longpath
2018/07/23 17:03:52 ·· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/opencontainers/runc/libcontainer/system
2018/07/23 17:03:52 ·· Fetching recursive dependency: github.com/docker/docker/pkg/fileutils
2018/07/23 17:03:52 ·· Fetching recursive dependency: github.com/docker/docker/vendor/archive/tar
2018/07/23 17:03:52 · Skipping (existing): golang.org/x/net/context
2018/07/23 17:03:52 · Fetching recursive dependency: github.com/docker/docker/opts
2018/07/23 17:03:53 ·· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/docker/libnetwork/ipamutils
2018/07/23 17:03:53 · Skipping (existing): golang.org/x/net/context/ctxhttp
2018/07/23 17:03:53 · Fetching recursive dependency: github.com/Microsoft/go-winio
2018/07/23 17:03:55 ·· Fetching recursive dependency: golang.org/x/sys/windows
```
2018-07-23 20:10:16 +02:00

183 lines
4.9 KiB
Go

// Copyright 2013 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
import (
"encoding/json"
"net"
"strings"
"github.com/docker/docker/api/types/swarm"
)
// Version returns version information about the docker server.
//
// See https://goo.gl/mU7yje 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
}
// 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
OomKillDisable bool
ExperimentalBuild bool
NFd int
NGoroutines int
SystemTime string
ExecutionDriver string
LoggingDriver string
CgroupDriver string
NEventsListener int
KernelVersion string
OperatingSystem string
OSType string
Architecture string
IndexServerAddress string
RegistryConfig *ServiceConfig
SecurityOptions []string
NCPU int
MemTotal int64
DockerRootDir string
HTTPProxy string `json:"HttpProxy"`
HTTPSProxy string `json:"HttpsProxy"`
NoProxy string
Name string
Labels []string
ServerVersion string
ClusterStore string
ClusterAdvertise string
Isolation string
InitBinary string
DefaultRuntime string
LiveRestoreEnabled bool
Swarm swarm.Info
}
// 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
}
// ServiceConfig stores daemon registry services configuration.
//
// for more information, see: https://goo.gl/7iFFDz
type ServiceConfig struct {
InsecureRegistryCIDRs []*NetIPNet
IndexConfigs map[string]*IndexInfo
Mirrors []string
}
// NetIPNet is the net.IPNet type, which can be marshalled and
// unmarshalled to JSON.
//
// for more information, see: https://goo.gl/7iFFDz
type NetIPNet net.IPNet
// MarshalJSON returns the JSON representation of the IPNet.
//
func (ipnet *NetIPNet) MarshalJSON() ([]byte, error) {
return json.Marshal((*net.IPNet)(ipnet).String())
}
// UnmarshalJSON sets the IPNet from a byte array of JSON.
//
func (ipnet *NetIPNet) UnmarshalJSON(b []byte) (err error) {
var ipnetStr string
if err = json.Unmarshal(b, &ipnetStr); err == nil {
var cidr *net.IPNet
if _, cidr, err = net.ParseCIDR(ipnetStr); err == nil {
*ipnet = NetIPNet(*cidr)
}
}
return
}
// IndexInfo contains information about a registry.
//
// for more information, see: https://goo.gl/7iFFDz
type IndexInfo struct {
Name string
Mirrors []string
Secure bool
Official bool
}
// Info returns system-wide information about the Docker server.
//
// See https://goo.gl/ElTHi2 for more details.
func (c *Client) Info() (*DockerInfo, error) {
resp, err := c.do("GET", "/info", doOptions{})
if err != nil {
return nil, err
}
defer resp.Body.Close()
var info DockerInfo
if err := json.NewDecoder(resp.Body).Decode(&info); err != nil {
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. It ignores the digest when it is
// present.
//
// Some examples:
//
// localhost.localdomain:5000/samalba/hipache:latest -> localhost.localdomain:5000/samalba/hipache, latest
// localhost.localdomain:5000/samalba/hipache -> localhost.localdomain:5000/samalba/hipache, ""
// busybox:latest@sha256:4a731fb46adc5cefe3ae374a8b6020fc1b6ad667a279647766e9a3cd89f6fa92 -> busybox, latest
func ParseRepositoryTag(repoTag string) (repository string, tag string) {
parts := strings.SplitN(repoTag, "@", 2)
repoTag = parts[0]
n := strings.LastIndex(repoTag, ":")
if n < 0 {
return repoTag, ""
}
if tag := repoTag[n+1:]; !strings.Contains(tag, "/") {
return repoTag[:n], tag
}
return repoTag, ""
}