mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-08-14 04:39:33 +00:00
This was implemented by containers/netavark #1369; this commit completes the process by wiring it into Podman. We now respect the CLI order for configured networks - if a user passes `--net net1,net2` we guarantee that net1 will be configured before net2. For containers created before this patch, we don't retain enough information to configure networks in CLI order, so we use alphabetical order instead to still guarantee consistency. No breaking API changes have been made, but we do add a new field to supplement the existing map to (optionally) provide ordering information. The Podman CLI will always pass this. Existing applications that do not will, again, receive] deterministic ordering based on an alphabetical sort of network names. This requires the latest version of Netavark to work properly. Signed-off-by: Matthew Heon <matthew.heon@pm.me>
213 lines
5.9 KiB
Go
213 lines
5.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 (
|
|
"context"
|
|
"encoding/json"
|
|
"net"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
// Version returns version information about the docker server.
|
|
//
|
|
// See https://goo.gl/mU7yje for more details.
|
|
func (c *Client) Version() (*Env, error) {
|
|
return c.VersionWithContext(context.TODO())
|
|
}
|
|
|
|
// VersionWithContext returns version information about the docker server.
|
|
func (c *Client) VersionWithContext(ctx context.Context) (*Env, error) {
|
|
resp, err := c.do(http.MethodGet, "/version", doOptions{context: ctx})
|
|
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
|
|
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
|
|
Runtimes map[string]Runtime
|
|
ClusterAdvertise string
|
|
Isolation string
|
|
InitBinary string
|
|
DefaultRuntime string
|
|
Swarm SwarmInfo
|
|
LiveRestoreEnabled bool
|
|
MemoryLimit bool
|
|
SwapLimit bool
|
|
// Deprecated: KernelMemory is deprecated as of API 1.42 and removed in API 1.52.
|
|
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
|
|
CDISpecDirs []string `json:"CDISpecDirs,omitempty"`
|
|
Containerd *ContainerdInfo `json:"Containerd,omitempty"`
|
|
}
|
|
|
|
// Runtime describes an OCI runtime
|
|
//
|
|
// for more information, see: https://dockr.ly/2NKM8qq
|
|
type Runtime struct {
|
|
Path string
|
|
Args []string `json:"runtimeArgs"`
|
|
}
|
|
|
|
// ContainerdInfo contains information about the containerd instance.
|
|
type ContainerdInfo struct {
|
|
Address string `json:"Address,omitempty"`
|
|
Namespaces struct {
|
|
Containers string `json:"Containers,omitempty"`
|
|
Plugins string `json:"Plugins,omitempty"`
|
|
} `json:"Namespaces"`
|
|
}
|
|
|
|
// SwarmInfo contains basic swarm information from docker info.
|
|
// Deprecated: Docker Swarm is deprecated.
|
|
type SwarmInfo struct {
|
|
NodeID string
|
|
NodeAddr 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
|
|
}
|
|
|
|
// 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 err
|
|
}
|
|
|
|
// 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(http.MethodGet, "/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, ""
|
|
}
|