]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - vendor/github.com/fsouza/go-dockerclient/misc.go
provider: Ensured Go 1.11 in TravisCI and README
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / fsouza / go-dockerclient / misc.go
1 // Copyright 2015 go-dockerclient authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package docker
6
7 import (
8 "encoding/json"
9 "strings"
10 )
11
12 // Version returns version information about the docker server.
13 //
14 // See https://goo.gl/ND9R8L for more details.
15 func (c *Client) Version() (*Env, error) {
16 resp, err := c.do("GET", "/version", doOptions{})
17 if err != nil {
18 return nil, err
19 }
20 defer resp.Body.Close()
21 var env Env
22 if err := env.Decode(resp.Body); err != nil {
23 return nil, err
24 }
25 return &env, nil
26 }
27
28 // DockerInfo contains information about the Docker server
29 //
30 // See https://goo.gl/bHUoz9 for more details.
31 type DockerInfo struct {
32 ID string
33 Containers int
34 ContainersRunning int
35 ContainersPaused int
36 ContainersStopped int
37 Images int
38 Driver string
39 DriverStatus [][2]string
40 SystemStatus [][2]string
41 Plugins PluginsInfo
42 MemoryLimit bool
43 SwapLimit bool
44 KernelMemory bool
45 CPUCfsPeriod bool `json:"CpuCfsPeriod"`
46 CPUCfsQuota bool `json:"CpuCfsQuota"`
47 CPUShares bool
48 CPUSet bool
49 IPv4Forwarding bool
50 BridgeNfIptables bool
51 BridgeNfIP6tables bool `json:"BridgeNfIp6tables"`
52 Debug bool
53 NFd int
54 OomKillDisable bool
55 NGoroutines int
56 SystemTime string
57 ExecutionDriver string
58 LoggingDriver string
59 CgroupDriver string
60 NEventsListener int
61 KernelVersion string
62 OperatingSystem string
63 OSType string
64 Architecture string
65 IndexServerAddress string
66 NCPU int
67 MemTotal int64
68 DockerRootDir string
69 HTTPProxy string `json:"HttpProxy"`
70 HTTPSProxy string `json:"HttpsProxy"`
71 NoProxy string
72 Name string
73 Labels []string
74 ExperimentalBuild bool
75 ServerVersion string
76 ClusterStore string
77 ClusterAdvertise string
78 }
79
80 // PluginsInfo is a struct with the plugins registered with the docker daemon
81 //
82 // for more information, see: https://goo.gl/bHUoz9
83 type PluginsInfo struct {
84 // List of Volume plugins registered
85 Volume []string
86 // List of Network plugins registered
87 Network []string
88 // List of Authorization plugins registered
89 Authorization []string
90 }
91
92 // Info returns system-wide information about the Docker server.
93 //
94 // See https://goo.gl/ElTHi2 for more details.
95 func (c *Client) Info() (*DockerInfo, error) {
96 resp, err := c.do("GET", "/info", doOptions{})
97 if err != nil {
98 return nil, err
99 }
100 defer resp.Body.Close()
101 var info DockerInfo
102 if err := json.NewDecoder(resp.Body).Decode(&info); err != nil {
103 return nil, err
104 }
105 return &info, nil
106 }
107
108 // ParseRepositoryTag gets the name of the repository and returns it splitted
109 // in two parts: the repository and the tag.
110 //
111 // Some examples:
112 //
113 // localhost.localdomain:5000/samalba/hipache:latest -> localhost.localdomain:5000/samalba/hipache, latest
114 // localhost.localdomain:5000/samalba/hipache -> localhost.localdomain:5000/samalba/hipache, ""
115 func ParseRepositoryTag(repoTag string) (repository string, tag string) {
116 n := strings.LastIndex(repoTag, ":")
117 if n < 0 {
118 return repoTag, ""
119 }
120 if tag := repoTag[n+1:]; !strings.Contains(tag, "/") {
121 return repoTag[:n], tag
122 }
123 return repoTag, ""
124 }