Merge pull request #19173 from calavera/vendor_engine_api_0_1_2

Vendor engine-api 0.1.3
This commit is contained in:
Jess Frazelle 2016-01-07 19:19:19 -08:00
commit 611d5e4eeb
16 changed files with 150 additions and 93 deletions

View file

@ -43,7 +43,7 @@ type DockerCli struct {
// isTerminalOut indicates whether the client's STDOUT is a TTY // isTerminalOut indicates whether the client's STDOUT is a TTY
isTerminalOut bool isTerminalOut bool
// client is the http client that performs all API operations // client is the http client that performs all API operations
client apiClient client client.APIClient
} }
// Initialize calls the init function that will setup the configuration for the client // Initialize calls the init function that will setup the configuration for the client

View file

@ -3,75 +3,3 @@
// Run "docker help SUBCOMMAND" or "docker SUBCOMMAND --help" to see more information on any Docker subcommand, including the full list of options supported for the subcommand. // Run "docker help SUBCOMMAND" or "docker SUBCOMMAND --help" to see more information on any Docker subcommand, including the full list of options supported for the subcommand.
// See https://docs.docker.com/installation/ for instructions on installing Docker. // See https://docs.docker.com/installation/ for instructions on installing Docker.
package client package client
import (
"io"
"github.com/docker/engine-api/client"
"github.com/docker/engine-api/types"
"github.com/docker/engine-api/types/container"
"github.com/docker/engine-api/types/filters"
"github.com/docker/engine-api/types/registry"
)
// apiClient is an interface that clients that talk with a docker server must implement.
type apiClient interface {
ClientVersion() string
ContainerAttach(options types.ContainerAttachOptions) (types.HijackedResponse, error)
ContainerCommit(options types.ContainerCommitOptions) (types.ContainerCommitResponse, error)
ContainerCreate(config *container.Config, hostConfig *container.HostConfig, containerName string) (types.ContainerCreateResponse, error)
ContainerDiff(containerID string) ([]types.ContainerChange, error)
ContainerExecAttach(execID string, config types.ExecConfig) (types.HijackedResponse, error)
ContainerExecCreate(config types.ExecConfig) (types.ContainerExecCreateResponse, error)
ContainerExecInspect(execID string) (types.ContainerExecInspect, error)
ContainerExecResize(options types.ResizeOptions) error
ContainerExecStart(execID string, config types.ExecStartCheck) error
ContainerExport(containerID string) (io.ReadCloser, error)
ContainerInspect(containerID string) (types.ContainerJSON, error)
ContainerInspectWithRaw(containerID string, getSize bool) (types.ContainerJSON, []byte, error)
ContainerKill(containerID, signal string) error
ContainerList(options types.ContainerListOptions) ([]types.Container, error)
ContainerLogs(options types.ContainerLogsOptions) (io.ReadCloser, error)
ContainerPause(containerID string) error
ContainerRemove(options types.ContainerRemoveOptions) error
ContainerRename(containerID, newContainerName string) error
ContainerResize(options types.ResizeOptions) error
ContainerRestart(containerID string, timeout int) error
ContainerStatPath(containerID, path string) (types.ContainerPathStat, error)
ContainerStats(containerID string, stream bool) (io.ReadCloser, error)
ContainerStart(containerID string) error
ContainerStop(containerID string, timeout int) error
ContainerTop(containerID string, arguments []string) (types.ContainerProcessList, error)
ContainerUnpause(containerID string) error
ContainerUpdate(containerID string, hostConfig container.HostConfig) error
ContainerWait(containerID string) (int, error)
CopyFromContainer(containerID, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)
CopyToContainer(options types.CopyToContainerOptions) error
Events(options types.EventsOptions) (io.ReadCloser, error)
ImageBuild(options types.ImageBuildOptions) (types.ImageBuildResponse, error)
ImageCreate(options types.ImageCreateOptions) (io.ReadCloser, error)
ImageHistory(imageID string) ([]types.ImageHistory, error)
ImageImport(options types.ImageImportOptions) (io.ReadCloser, error)
ImageInspectWithRaw(imageID string, getSize bool) (types.ImageInspect, []byte, error)
ImageList(options types.ImageListOptions) ([]types.Image, error)
ImageLoad(input io.Reader) (types.ImageLoadResponse, error)
ImagePull(options types.ImagePullOptions, privilegeFunc client.RequestPrivilegeFunc) (io.ReadCloser, error)
ImagePush(options types.ImagePushOptions, privilegeFunc client.RequestPrivilegeFunc) (io.ReadCloser, error)
ImageRemove(options types.ImageRemoveOptions) ([]types.ImageDelete, error)
ImageSearch(options types.ImageSearchOptions, privilegeFunc client.RequestPrivilegeFunc) ([]registry.SearchResult, error)
ImageSave(imageIDs []string) (io.ReadCloser, error)
ImageTag(options types.ImageTagOptions) error
Info() (types.Info, error)
NetworkConnect(networkID, containerID string) error
NetworkCreate(options types.NetworkCreate) (types.NetworkCreateResponse, error)
NetworkDisconnect(networkID, containerID string) error
NetworkInspect(networkID string) (types.NetworkResource, error)
NetworkList(options types.NetworkListOptions) ([]types.NetworkResource, error)
NetworkRemove(networkID string) error
RegistryLogin(auth types.AuthConfig) (types.AuthResponse, error)
ServerVersion() (types.Version, error)
VolumeCreate(options types.VolumeCreateRequest) (types.Volume, error)
VolumeInspect(volumeID string) (types.Volume, error)
VolumeList(filter filters.Args) (types.VolumesListResponse, error)
VolumeRemove(volumeID string) error
}

View file

@ -107,7 +107,7 @@ func (cli *DockerCli) createContainer(config *container.Config, hostConfig *cont
} }
//create the container //create the container
response, err := cli.client.ContainerCreate(config, hostConfig, name) response, err := cli.client.ContainerCreate(config, hostConfig, nil, name)
//if image not found try to pull it //if image not found try to pull it
if err != nil { if err != nil {
if client.IsErrImageNotFound(err) { if client.IsErrImageNotFound(err) {
@ -124,7 +124,7 @@ func (cli *DockerCli) createContainer(config *container.Config, hostConfig *cont
} }
// Retry // Retry
var retryErr error var retryErr error
response, retryErr = cli.client.ContainerCreate(config, hostConfig, name) response, retryErr = cli.client.ContainerCreate(config, hostConfig, nil, name)
if retryErr != nil { if retryErr != nil {
return nil, retryErr return nil, retryErr
} }

View file

@ -115,7 +115,7 @@ func (cli *DockerCli) CmdNetworkConnect(args ...string) error {
return err return err
} }
return cli.client.NetworkConnect(cmd.Arg(0), cmd.Arg(1)) return cli.client.NetworkConnect(cmd.Arg(0), cmd.Arg(1), nil)
} }
// CmdNetworkDisconnect disconnects a container from a network // CmdNetworkDisconnect disconnects a container from a network

View file

@ -82,14 +82,14 @@ func (cli *DockerCli) CmdUpdate(args ...string) error {
CPUQuota: *flCPUQuota, CPUQuota: *flCPUQuota,
} }
hostConfig := container.HostConfig{ updateConfig := container.UpdateConfig{
Resources: resources, Resources: resources,
} }
names := cmd.Args() names := cmd.Args()
var errs []string var errs []string
for _, name := range names { for _, name := range names {
if err := cli.client.ContainerUpdate(name, hostConfig); err != nil { if err := cli.client.ContainerUpdate(name, updateConfig); err != nil {
errs = append(errs, fmt.Sprintf("Failed to update container (%s): %s", name, err)) errs = append(errs, fmt.Sprintf("Failed to update container (%s): %s", name, err))
} else { } else {
fmt.Fprintf(cli.out, "%s\n", name) fmt.Fprintf(cli.out, "%s\n", name)

View file

@ -22,7 +22,7 @@ clone git github.com/vdemeester/shakers 3c10293ce22b900c27acad7b28656196fcc2f73b
clone git golang.org/x/net 47990a1ba55743e6ef1affd3a14e5bac8553615d https://github.com/golang/net.git clone git golang.org/x/net 47990a1ba55743e6ef1affd3a14e5bac8553615d https://github.com/golang/net.git
clone git github.com/docker/go-units 651fc226e7441360384da338d0fd37f2440ffbe3 clone git github.com/docker/go-units 651fc226e7441360384da338d0fd37f2440ffbe3
clone git github.com/docker/go-connections v0.1.2 clone git github.com/docker/go-connections v0.1.2
clone git github.com/docker/engine-api v0.1.1 clone git github.com/docker/engine-api v0.1.3
#get libnetwork packages #get libnetwork packages
clone git github.com/docker/libnetwork 9f0563ea8f430d8828553aac97161cbff4056436 clone git github.com/docker/libnetwork 9f0563ea8f430d8828553aac97161cbff4056436

View file

@ -7,16 +7,18 @@ import (
"github.com/docker/engine-api/types" "github.com/docker/engine-api/types"
"github.com/docker/engine-api/types/container" "github.com/docker/engine-api/types/container"
"github.com/docker/engine-api/types/network"
) )
type configWrapper struct { type configWrapper struct {
*container.Config *container.Config
HostConfig *container.HostConfig HostConfig *container.HostConfig
NetworkingConfig *network.NetworkingConfig
} }
// ContainerCreate creates a new container based in the given configuration. // ContainerCreate creates a new container based in the given configuration.
// It can be associated with a name, but it's not mandatory. // It can be associated with a name, but it's not mandatory.
func (cli *Client) ContainerCreate(config *container.Config, hostConfig *container.HostConfig, containerName string) (types.ContainerCreateResponse, error) { func (cli *Client) ContainerCreate(config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (types.ContainerCreateResponse, error) {
var response types.ContainerCreateResponse var response types.ContainerCreateResponse
query := url.Values{} query := url.Values{}
if containerName != "" { if containerName != "" {
@ -24,8 +26,9 @@ func (cli *Client) ContainerCreate(config *container.Config, hostConfig *contain
} }
body := configWrapper{ body := configWrapper{
Config: config, Config: config,
HostConfig: hostConfig, HostConfig: hostConfig,
NetworkingConfig: networkingConfig,
} }
serverResp, err := cli.post("/containers/create", query, body, nil) serverResp, err := cli.post("/containers/create", query, body, nil)

View file

@ -5,8 +5,8 @@ import (
) )
// ContainerUpdate updates resources of a container // ContainerUpdate updates resources of a container
func (cli *Client) ContainerUpdate(containerID string, hostConfig container.HostConfig) error { func (cli *Client) ContainerUpdate(containerID string, updateConfig container.UpdateConfig) error {
resp, err := cli.post("/containers/"+containerID+"/update", nil, hostConfig, nil) resp, err := cli.post("/containers/"+containerID+"/update", nil, updateConfig, nil)
ensureReaderClosed(resp) ensureReaderClosed(resp)
return err return err
} }

View file

@ -0,0 +1,76 @@
package client
import (
"io"
"github.com/docker/engine-api/types"
"github.com/docker/engine-api/types/container"
"github.com/docker/engine-api/types/filters"
"github.com/docker/engine-api/types/network"
"github.com/docker/engine-api/types/registry"
)
// APIClient is an interface that clients that talk with a docker server must implement.
type APIClient interface {
ClientVersion() string
ContainerAttach(options types.ContainerAttachOptions) (types.HijackedResponse, error)
ContainerCommit(options types.ContainerCommitOptions) (types.ContainerCommitResponse, error)
ContainerCreate(config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (types.ContainerCreateResponse, error)
ContainerDiff(containerID string) ([]types.ContainerChange, error)
ContainerExecAttach(execID string, config types.ExecConfig) (types.HijackedResponse, error)
ContainerExecCreate(config types.ExecConfig) (types.ContainerExecCreateResponse, error)
ContainerExecInspect(execID string) (types.ContainerExecInspect, error)
ContainerExecResize(options types.ResizeOptions) error
ContainerExecStart(execID string, config types.ExecStartCheck) error
ContainerExport(containerID string) (io.ReadCloser, error)
ContainerInspect(containerID string) (types.ContainerJSON, error)
ContainerInspectWithRaw(containerID string, getSize bool) (types.ContainerJSON, []byte, error)
ContainerKill(containerID, signal string) error
ContainerList(options types.ContainerListOptions) ([]types.Container, error)
ContainerLogs(options types.ContainerLogsOptions) (io.ReadCloser, error)
ContainerPause(containerID string) error
ContainerRemove(options types.ContainerRemoveOptions) error
ContainerRename(containerID, newContainerName string) error
ContainerResize(options types.ResizeOptions) error
ContainerRestart(containerID string, timeout int) error
ContainerStatPath(containerID, path string) (types.ContainerPathStat, error)
ContainerStats(containerID string, stream bool) (io.ReadCloser, error)
ContainerStart(containerID string) error
ContainerStop(containerID string, timeout int) error
ContainerTop(containerID string, arguments []string) (types.ContainerProcessList, error)
ContainerUnpause(containerID string) error
ContainerUpdate(containerID string, updateConfig container.UpdateConfig) error
ContainerWait(containerID string) (int, error)
CopyFromContainer(containerID, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)
CopyToContainer(options types.CopyToContainerOptions) error
Events(options types.EventsOptions) (io.ReadCloser, error)
ImageBuild(options types.ImageBuildOptions) (types.ImageBuildResponse, error)
ImageCreate(options types.ImageCreateOptions) (io.ReadCloser, error)
ImageHistory(imageID string) ([]types.ImageHistory, error)
ImageImport(options types.ImageImportOptions) (io.ReadCloser, error)
ImageInspectWithRaw(imageID string, getSize bool) (types.ImageInspect, []byte, error)
ImageList(options types.ImageListOptions) ([]types.Image, error)
ImageLoad(input io.Reader) (types.ImageLoadResponse, error)
ImagePull(options types.ImagePullOptions, privilegeFunc RequestPrivilegeFunc) (io.ReadCloser, error)
ImagePush(options types.ImagePushOptions, privilegeFunc RequestPrivilegeFunc) (io.ReadCloser, error)
ImageRemove(options types.ImageRemoveOptions) ([]types.ImageDelete, error)
ImageSearch(options types.ImageSearchOptions, privilegeFunc RequestPrivilegeFunc) ([]registry.SearchResult, error)
ImageSave(imageIDs []string) (io.ReadCloser, error)
ImageTag(options types.ImageTagOptions) error
Info() (types.Info, error)
NetworkConnect(networkID, containerID string, config *network.EndpointSettings) error
NetworkCreate(options types.NetworkCreate) (types.NetworkCreateResponse, error)
NetworkDisconnect(networkID, containerID string) error
NetworkInspect(networkID string) (types.NetworkResource, error)
NetworkList(options types.NetworkListOptions) ([]types.NetworkResource, error)
NetworkRemove(networkID string) error
RegistryLogin(auth types.AuthConfig) (types.AuthResponse, error)
ServerVersion() (types.Version, error)
VolumeCreate(options types.VolumeCreateRequest) (types.Volume, error)
VolumeInspect(volumeID string) (types.Volume, error)
VolumeList(filter filters.Args) (types.VolumesListResponse, error)
VolumeRemove(volumeID string) error
}
// Ensure that Client always implements APIClient.
var _ APIClient = &Client{}

View file

@ -7,6 +7,7 @@ import (
"github.com/docker/engine-api/types" "github.com/docker/engine-api/types"
"github.com/docker/engine-api/types/filters" "github.com/docker/engine-api/types/filters"
"github.com/docker/engine-api/types/network"
) )
// NetworkCreate creates a new network in the docker host. // NetworkCreate creates a new network in the docker host.
@ -30,8 +31,11 @@ func (cli *Client) NetworkRemove(networkID string) error {
} }
// NetworkConnect connects a container to an existent network in the docker host. // NetworkConnect connects a container to an existent network in the docker host.
func (cli *Client) NetworkConnect(networkID, containerID string) error { func (cli *Client) NetworkConnect(networkID, containerID string, config *network.EndpointSettings) error {
nc := types.NetworkConnect{Container: containerID} nc := types.NetworkConnect{
Container: containerID,
EndpointConfig: config,
}
resp, err := cli.post("/networks/"+networkID+"/connect", nil, nc, nil) resp, err := cli.post("/networks/"+networkID+"/connect", nil, nc, nil)
ensureReaderClosed(resp) ensureReaderClosed(resp)
return err return err

View file

@ -1,6 +1,9 @@
package types package types
import "github.com/docker/engine-api/types/container" import (
"github.com/docker/engine-api/types/container"
"github.com/docker/engine-api/types/network"
)
// configs holds structs used for internal communication between the // configs holds structs used for internal communication between the
// frontend (such as an http server) and the backend (such as the // frontend (such as an http server) and the backend (such as the
@ -8,10 +11,11 @@ import "github.com/docker/engine-api/types/container"
// ContainerCreateConfig is the parameter set to ContainerCreate() // ContainerCreateConfig is the parameter set to ContainerCreate()
type ContainerCreateConfig struct { type ContainerCreateConfig struct {
Name string Name string
Config *container.Config Config *container.Config
HostConfig *container.HostConfig HostConfig *container.HostConfig
AdjustCPUShares bool NetworkingConfig *network.NetworkingConfig
AdjustCPUShares bool
} }
// ContainerRmConfig holds arguments for the container remove // ContainerRmConfig holds arguments for the container remove

View file

@ -181,9 +181,17 @@ type Resources struct {
MemorySwap int64 // Total memory usage (memory + swap); set `-1` to disable swap MemorySwap int64 // Total memory usage (memory + swap); set `-1` to disable swap
MemorySwappiness *int64 // Tuning container memory swappiness behaviour MemorySwappiness *int64 // Tuning container memory swappiness behaviour
OomKillDisable bool // Whether to disable OOM Killer or not OomKillDisable bool // Whether to disable OOM Killer or not
PidsLimit int64 // Setting pids limit for a container
Ulimits []*units.Ulimit // List of ulimits to be set in the container Ulimits []*units.Ulimit // List of ulimits to be set in the container
} }
// UpdateConfig holds the mutable attributes of a Container.
// Those attributes can be updated at runtime.
type UpdateConfig struct {
// Contains container's resources (cgroups, ulimits)
Resources
}
// HostConfig the non-portable Config structure of a container. // HostConfig the non-portable Config structure of a container.
// Here, "non-portable" means "dependent of the host we are running on". // Here, "non-portable" means "dependent of the host we are running on".
// Portable information *should* appear in Config. // Portable information *should* appear in Config.
@ -214,6 +222,7 @@ type HostConfig struct {
PublishAllPorts bool // Should docker publish all exposed port for the container PublishAllPorts bool // Should docker publish all exposed port for the container
ReadonlyRootfs bool // Is the container root filesystem in read-only ReadonlyRootfs bool // Is the container root filesystem in read-only
SecurityOpt []string // List of string values to customize labels for MLS systems, such as SELinux. SecurityOpt []string // List of string values to customize labels for MLS systems, such as SELinux.
StorageOpt []string // Graph storage options per container
Tmpfs map[string]string `json:",omitempty"` // List of tmpfs (mounts) used for the container Tmpfs map[string]string `json:",omitempty"` // List of tmpfs (mounts) used for the container
UTSMode UTSMode // UTS namespace to use for the container UTSMode UTSMode // UTS namespace to use for the container
ShmSize int64 // Total shm memory usage ShmSize int64 // Total shm memory usage

View file

@ -10,6 +10,16 @@ func (n NetworkMode) IsDefault() bool {
return n == "default" return n == "default"
} }
// IsNone indicates whether container isn't using a network stack.
func (n NetworkMode) IsNone() bool {
return n == "none"
}
// IsUserDefined indicates user-created network
func (n NetworkMode) IsUserDefined() bool {
return !n.IsDefault() && !n.IsNone()
}
// IsHyperV indicates the use of a Hyper-V partition for isolation // IsHyperV indicates the use of a Hyper-V partition for isolation
func (i IsolationLevel) IsHyperV() bool { func (i IsolationLevel) IsHyperV() bool {
return strings.ToLower(string(i)) == "hyperv" return strings.ToLower(string(i)) == "hyperv"

View file

@ -20,8 +20,17 @@ type IPAMConfig struct {
AuxAddress map[string]string `json:"AuxiliaryAddresses,omitempty"` AuxAddress map[string]string `json:"AuxiliaryAddresses,omitempty"`
} }
// EndpointIPAMConfig represents IPAM configurations for the endpoint
type EndpointIPAMConfig struct {
IPv4Address string `json:",omitempty"`
IPv6Address string `json:",omitempty"`
}
// EndpointSettings stores the network endpoint details // EndpointSettings stores the network endpoint details
type EndpointSettings struct { type EndpointSettings struct {
// Configurations
IPAMConfig *EndpointIPAMConfig
// Operational data
EndpointID string EndpointID string
Gateway string Gateway string
IPAddress string IPAddress string
@ -31,3 +40,9 @@ type EndpointSettings struct {
GlobalIPv6PrefixLen int GlobalIPv6PrefixLen int
MacAddress string MacAddress string
} }
// NetworkingConfig represents the container's networking configuration for each of its interfaces
// Carries the networink configs specified in the `docker run` and `docker network connect` commands
type NetworkingConfig struct {
EndpointsConfig map[string]*EndpointSettings // Endpoint configs for each conencting network
}

View file

@ -87,6 +87,12 @@ type NetworkStats struct {
TxDropped uint64 `json:"tx_dropped"` TxDropped uint64 `json:"tx_dropped"`
} }
// PidsStats contains the stats of a container's pids
type PidsStats struct {
// Current is the number of pids in the cgroup
Current uint64 `json:"current,omitempty"`
}
// Stats is Ultimate struct aggregating all types of stats of one container // Stats is Ultimate struct aggregating all types of stats of one container
type Stats struct { type Stats struct {
Read time.Time `json:"read"` Read time.Time `json:"read"`
@ -94,6 +100,7 @@ type Stats struct {
CPUStats CPUStats `json:"cpu_stats,omitempty"` CPUStats CPUStats `json:"cpu_stats,omitempty"`
MemoryStats MemoryStats `json:"memory_stats,omitempty"` MemoryStats MemoryStats `json:"memory_stats,omitempty"`
BlkioStats BlkioStats `json:"blkio_stats,omitempty"` BlkioStats BlkioStats `json:"blkio_stats,omitempty"`
PidsStats PidsStats `json:"pids_stats,omitempty"`
} }
// StatsJSON is newly used Networks // StatsJSON is newly used Networks

View file

@ -415,7 +415,8 @@ type NetworkCreateResponse struct {
// NetworkConnect represents the data to be used to connect a container to the network // NetworkConnect represents the data to be used to connect a container to the network
type NetworkConnect struct { type NetworkConnect struct {
Container string Container string
EndpointConfig *network.EndpointSettings `json:"endpoint_config"`
} }
// NetworkDisconnect represents the data to be used to disconnect a container from the network // NetworkDisconnect represents the data to be used to disconnect a container from the network