podman

Форк
0
196 строк · 5.3 Кб
1
// Copyright 2013 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
	"context"
9
	"encoding/json"
10
	"net"
11
	"net/http"
12
	"strings"
13

14
	"github.com/docker/docker/api/types/swarm"
15
)
16

17
// Version returns version information about the docker server.
18
//
19
// See https://goo.gl/mU7yje for more details.
20
func (c *Client) Version() (*Env, error) {
21
	return c.VersionWithContext(context.TODO())
22
}
23

24
// VersionWithContext returns version information about the docker server.
25
func (c *Client) VersionWithContext(ctx context.Context) (*Env, error) {
26
	resp, err := c.do(http.MethodGet, "/version", doOptions{context: ctx})
27
	if err != nil {
28
		return nil, err
29
	}
30
	defer resp.Body.Close()
31
	var env Env
32
	if err := env.Decode(resp.Body); err != nil {
33
		return nil, err
34
	}
35
	return &env, nil
36
}
37

38
// DockerInfo contains information about the Docker server
39
//
40
// See https://goo.gl/bHUoz9 for more details.
41
type DockerInfo struct {
42
	ID                 string
43
	Containers         int
44
	ContainersRunning  int
45
	ContainersPaused   int
46
	ContainersStopped  int
47
	Images             int
48
	Driver             string
49
	DriverStatus       [][2]string
50
	SystemStatus       [][2]string
51
	Plugins            PluginsInfo
52
	NFd                int
53
	NGoroutines        int
54
	SystemTime         string
55
	ExecutionDriver    string
56
	LoggingDriver      string
57
	CgroupDriver       string
58
	NEventsListener    int
59
	KernelVersion      string
60
	OperatingSystem    string
61
	OSType             string
62
	Architecture       string
63
	IndexServerAddress string
64
	RegistryConfig     *ServiceConfig
65
	SecurityOptions    []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
	ServerVersion      string
75
	ClusterStore       string
76
	Runtimes           map[string]Runtime
77
	ClusterAdvertise   string
78
	Isolation          string
79
	InitBinary         string
80
	DefaultRuntime     string
81
	Swarm              swarm.Info
82
	LiveRestoreEnabled bool
83
	MemoryLimit        bool
84
	SwapLimit          bool
85
	KernelMemory       bool
86
	CPUCfsPeriod       bool `json:"CpuCfsPeriod"`
87
	CPUCfsQuota        bool `json:"CpuCfsQuota"`
88
	CPUShares          bool
89
	CPUSet             bool
90
	IPv4Forwarding     bool
91
	BridgeNfIptables   bool
92
	BridgeNfIP6tables  bool `json:"BridgeNfIp6tables"`
93
	Debug              bool
94
	OomKillDisable     bool
95
	ExperimentalBuild  bool
96
}
97

98
// Runtime describes an OCI runtime
99
//
100
// for more information, see: https://dockr.ly/2NKM8qq
101
type Runtime struct {
102
	Path string
103
	Args []string `json:"runtimeArgs"`
104
}
105

106
// PluginsInfo is a struct with the plugins registered with the docker daemon
107
//
108
// for more information, see: https://goo.gl/bHUoz9
109
type PluginsInfo struct {
110
	// List of Volume plugins registered
111
	Volume []string
112
	// List of Network plugins registered
113
	Network []string
114
	// List of Authorization plugins registered
115
	Authorization []string
116
}
117

118
// ServiceConfig stores daemon registry services configuration.
119
//
120
// for more information, see: https://goo.gl/7iFFDz
121
type ServiceConfig struct {
122
	InsecureRegistryCIDRs []*NetIPNet
123
	IndexConfigs          map[string]*IndexInfo
124
	Mirrors               []string
125
}
126

127
// NetIPNet is the net.IPNet type, which can be marshalled and
128
// unmarshalled to JSON.
129
//
130
// for more information, see: https://goo.gl/7iFFDz
131
type NetIPNet net.IPNet
132

133
// MarshalJSON returns the JSON representation of the IPNet.
134
func (ipnet *NetIPNet) MarshalJSON() ([]byte, error) {
135
	return json.Marshal((*net.IPNet)(ipnet).String())
136
}
137

138
// UnmarshalJSON sets the IPNet from a byte array of JSON.
139
func (ipnet *NetIPNet) UnmarshalJSON(b []byte) (err error) {
140
	var ipnetStr string
141
	if err = json.Unmarshal(b, &ipnetStr); err == nil {
142
		var cidr *net.IPNet
143
		if _, cidr, err = net.ParseCIDR(ipnetStr); err == nil {
144
			*ipnet = NetIPNet(*cidr)
145
		}
146
	}
147
	return
148
}
149

150
// IndexInfo contains information about a registry.
151
//
152
// for more information, see: https://goo.gl/7iFFDz
153
type IndexInfo struct {
154
	Name     string
155
	Mirrors  []string
156
	Secure   bool
157
	Official bool
158
}
159

160
// Info returns system-wide information about the Docker server.
161
//
162
// See https://goo.gl/ElTHi2 for more details.
163
func (c *Client) Info() (*DockerInfo, error) {
164
	resp, err := c.do(http.MethodGet, "/info", doOptions{})
165
	if err != nil {
166
		return nil, err
167
	}
168
	defer resp.Body.Close()
169
	var info DockerInfo
170
	if err := json.NewDecoder(resp.Body).Decode(&info); err != nil {
171
		return nil, err
172
	}
173
	return &info, nil
174
}
175

176
// ParseRepositoryTag gets the name of the repository and returns it splitted
177
// in two parts: the repository and the tag. It ignores the digest when it is
178
// present.
179
//
180
// Some examples:
181
//
182
//	localhost.localdomain:5000/samalba/hipache:latest -> localhost.localdomain:5000/samalba/hipache, latest
183
//	localhost.localdomain:5000/samalba/hipache -> localhost.localdomain:5000/samalba/hipache, ""
184
//	busybox:latest@sha256:4a731fb46adc5cefe3ae374a8b6020fc1b6ad667a279647766e9a3cd89f6fa92 -> busybox, latest
185
func ParseRepositoryTag(repoTag string) (repository string, tag string) {
186
	parts := strings.SplitN(repoTag, "@", 2)
187
	repoTag = parts[0]
188
	n := strings.LastIndex(repoTag, ":")
189
	if n < 0 {
190
		return repoTag, ""
191
	}
192
	if tag := repoTag[n+1:]; !strings.Contains(tag, "/") {
193
		return repoTag[:n], tag
194
	}
195
	return repoTag, ""
196
}
197

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.