Really upgrade fsouza/go-dockerclient pkg to latest revision, so that we can have

Error and OOMKilled from docker ContainerStatus.
This commit is contained in:
Dawn Chen
2014-12-18 11:02:09 -08:00
parent b489757b5a
commit 95e3efdad8
30 changed files with 1041 additions and 155 deletions

View File

@@ -18,15 +18,17 @@ import (
// ListContainersOptions specify parameters to the ListContainers function.
//
// See http://goo.gl/XqtcyU for more details.
// See http://goo.gl/6Y4Gz7 for more details.
type ListContainersOptions struct {
All bool
Size bool
Limit int
Since string
Before string
All bool
Size bool
Limit int
Since string
Before string
Filters map[string][]string
}
// APIPort is a type that represents a port mapping returned by the Docker API
type APIPort struct {
PrivatePort int64 `json:"PrivatePort,omitempty" yaml:"PrivatePort,omitempty"`
PublicPort int64 `json:"PublicPort,omitempty" yaml:"PublicPort,omitempty"`
@@ -51,7 +53,7 @@ type APIContainers struct {
// ListContainers returns a slice of containers matching the given criteria.
//
// See http://goo.gl/XqtcyU for more details.
// See http://goo.gl/6Y4Gz7 for more details.
func (c *Client) ListContainers(opts ListContainersOptions) ([]APIContainers, error) {
path := "/containers/json?" + queryString(opts)
body, _, err := c.do("GET", path, nil)
@@ -88,8 +90,10 @@ func (p Port) Proto() string {
type State struct {
Running bool `json:"Running,omitempty" yaml:"Running,omitempty"`
Paused bool `json:"Paused,omitempty" yaml:"Paused,omitempty"`
OOMKilled bool `json:"OOMKilled,omitempty" yaml:"OOMKilled,omitempty"`
Pid int `json:"Pid,omitempty" yaml:"Pid,omitempty"`
ExitCode int `json:"ExitCode,omitempty" yaml:"ExitCode,omitempty"`
Error string `json:"Error,omitempty" yaml:"Error,omitempty"`
StartedAt time.Time `json:"StartedAt,omitempty" yaml:"StartedAt,omitempty"`
FinishedAt time.Time `json:"FinishedAt,omitempty" yaml:"FinishedAt,omitempty"`
}
@@ -105,13 +109,18 @@ func (s *State) String() string {
return fmt.Sprintf("Exit %d", s.ExitCode)
}
// PortBinding represents the host/container port mapping as returned in the
// `docker inspect` json
type PortBinding struct {
HostIp string `json:"HostIP,omitempty" yaml:"HostIP,omitempty"`
HostIP string `json:"HostIP,omitempty" yaml:"HostIP,omitempty"`
HostPort string `json:"HostPort,omitempty" yaml:"HostPort,omitempty"`
}
// PortMapping represents a deprecated field in the `docker inspect` output,
// and its value as found in NetworkSettings should always be nil
type PortMapping map[string]string
// NetworkSettings contains network-related information about a container
type NetworkSettings struct {
IPAddress string `json:"IPAddress,omitempty" yaml:"IPAddress,omitempty"`
IPPrefixLen int `json:"IPPrefixLen,omitempty" yaml:"IPPrefixLen,omitempty"`
@@ -121,6 +130,8 @@ type NetworkSettings struct {
Ports map[Port][]PortBinding `json:"Ports,omitempty" yaml:"Ports,omitempty"`
}
// PortMappingAPI translates the port mappings as contained in NetworkSettings
// into the format in which they would appear when returned by the API
func (settings *NetworkSettings) PortMappingAPI() []APIPort {
var mapping []APIPort
for port, bindings := range settings.Ports {
@@ -139,7 +150,7 @@ func (settings *NetworkSettings) PortMappingAPI() []APIPort {
PrivatePort: int64(p),
PublicPort: int64(h),
Type: port.Proto(),
IP: binding.HostIp,
IP: binding.HostIP,
})
}
}
@@ -154,14 +165,17 @@ func parsePort(rawPort string) (int, error) {
return int(port), nil
}
// Config is the list of configuration options used when creating a container.
// Config does not the options that are specific to starting a container on a
// given host. Those are contained in HostConfig
type Config struct {
Hostname string `json:"Hostname,omitempty" yaml:"Hostname,omitempty"`
Domainname string `json:"Domainname,omitempty" yaml:"Domainname,omitempty"`
User string `json:"User,omitempty" yaml:"User,omitempty"`
Memory int64 `json:"Memory,omitempty" yaml:"Memory,omitempty"`
MemorySwap int64 `json:"MemorySwap,omitempty" yaml:"MemorySwap,omitempty"`
CpuShares int64 `json:"CpuShares,omitempty" yaml:"CpuShares,omitempty"`
CpuSet string `json:"CpuSet,omitempty" yaml:"CpuSet,omitempty"`
CPUShares int64 `json:"CpuShares,omitempty" yaml:"CpuShares,omitempty"`
CPUSet string `json:"Cpuset,omitempty" yaml:"Cpuset,omitempty"`
AttachStdin bool `json:"AttachStdin,omitempty" yaml:"AttachStdin,omitempty"`
AttachStdout bool `json:"AttachStdout,omitempty" yaml:"AttachStdout,omitempty"`
AttachStderr bool `json:"AttachStderr,omitempty" yaml:"AttachStderr,omitempty"`
@@ -172,7 +186,7 @@ type Config struct {
StdinOnce bool `json:"StdinOnce,omitempty" yaml:"StdinOnce,omitempty"`
Env []string `json:"Env,omitempty" yaml:"Env,omitempty"`
Cmd []string `json:"Cmd,omitempty" yaml:"Cmd,omitempty"`
Dns []string `json:"Dns,omitempty" yaml:"Dns,omitempty"` // For Docker API v1.9 and below only
DNS []string `json:"Dns,omitempty" yaml:"Dns,omitempty"` // For Docker API v1.9 and below only
Image string `json:"Image,omitempty" yaml:"Image,omitempty"`
Volumes map[string]struct{} `json:"Volumes,omitempty" yaml:"Volumes,omitempty"`
VolumesFrom string `json:"VolumesFrom,omitempty" yaml:"VolumesFrom,omitempty"`
@@ -181,6 +195,8 @@ type Config struct {
NetworkDisabled bool `json:"NetworkDisabled,omitempty" yaml:"NetworkDisabled,omitempty"`
}
// Container is the type encompasing everything about a container - its config,
// hostconfig, etc.
type Container struct {
ID string `json:"Id" yaml:"Id"`
@@ -249,10 +265,11 @@ func (c *Client) ContainerChanges(id string) ([]Change, error) {
// CreateContainerOptions specify parameters to the CreateContainer function.
//
// See http://goo.gl/mErxNp for more details.
// See http://goo.gl/2xxQQK for more details.
type CreateContainerOptions struct {
Name string
Config *Config `qs:"-"`
Name string
Config *Config `qs:"-"`
HostConfig *HostConfig
}
// CreateContainer creates a new container, returning the container instance,
@@ -261,7 +278,14 @@ type CreateContainerOptions struct {
// See http://goo.gl/mErxNp for more details.
func (c *Client) CreateContainer(opts CreateContainerOptions) (*Container, error) {
path := "/containers/create?" + queryString(opts)
body, status, err := c.do("POST", path, opts.Config)
body, status, err := c.do("POST", path, struct {
*Config
HostConfig *HostConfig `json:"HostConfig,omitempty" yaml:"HostConfig,omitempty"`
}{
opts.Config,
opts.HostConfig,
})
if status == http.StatusNotFound {
return nil, ErrNoSuchImage
}
@@ -279,6 +303,8 @@ func (c *Client) CreateContainer(opts CreateContainerOptions) (*Container, error
return &container, nil
}
// KeyValuePair is a type for generic key/value pairs as used in the Lxc
// configuration
type KeyValuePair struct {
Key string `json:"Key,omitempty" yaml:"Key,omitempty"`
Value string `json:"Value,omitempty" yaml:"Value,omitempty"`
@@ -315,6 +341,8 @@ func NeverRestart() RestartPolicy {
return RestartPolicy{Name: "no"}
}
// HostConfig contains the container options related to starting a container on
// a given host
type HostConfig struct {
Binds []string `json:"Binds,omitempty" yaml:"Binds,omitempty"`
CapAdd []string `json:"CapAdd,omitempty" yaml:"CapAdd,omitempty"`
@@ -325,8 +353,9 @@ type HostConfig struct {
PortBindings map[Port][]PortBinding `json:"PortBindings,omitempty" yaml:"PortBindings,omitempty"`
Links []string `json:"Links,omitempty" yaml:"Links,omitempty"`
PublishAllPorts bool `json:"PublishAllPorts,omitempty" yaml:"PublishAllPorts,omitempty"`
Dns []string `json:"Dns,omitempty" yaml:"Dns,omitempty"` // For Docker API v1.10 and above only
DnsSearch []string `json:"DnsSearch,omitempty" yaml:"DnsSearch,omitempty"`
DNS []string `json:"Dns,omitempty" yaml:"Dns,omitempty"` // For Docker API v1.10 and above only
DNSSearch []string `json:"DnsSearch,omitempty" yaml:"DnsSearch,omitempty"`
ExtraHosts []string `json:"ExtraHosts,omitempty" yaml:"ExtraHosts,omitempty"`
VolumesFrom []string `json:"VolumesFrom,omitempty" yaml:"VolumesFrom,omitempty"`
NetworkMode string `json:"NetworkMode,omitempty" yaml:"NetworkMode,omitempty"`
RestartPolicy RestartPolicy `json:"RestartPolicy,omitempty" yaml:"RestartPolicy,omitempty"`