зеркало из https://github.com/docker/engine-api.git
Create interface that clients that talk to the api must fulfill.
Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
Родитель
e05f642f68
Коммит
9a40f025a5
|
@ -8,18 +8,6 @@ import (
|
|||
"github.com/docker/docker/runconfig"
|
||||
)
|
||||
|
||||
// ContainerCommitOptions hods parameters to commit changes into a container.
|
||||
type ContainerCommitOptions struct {
|
||||
ContainerID string
|
||||
RepositoryName string
|
||||
Tag string
|
||||
Comment string
|
||||
Author string
|
||||
Changes []string
|
||||
Pause bool
|
||||
JSONConfig string
|
||||
}
|
||||
|
||||
// ContainerCommit applies changes into a container and creates a new tagged image.
|
||||
func (cli *Client) ContainerCommit(options types.ContainerCommitOptions) (types.ContainerCommitResponse, error) {
|
||||
query := url.Values{}
|
||||
|
|
|
@ -9,20 +9,8 @@ import (
|
|||
"github.com/docker/docker/pkg/parsers/filters"
|
||||
)
|
||||
|
||||
// ContainerListOptions holds parameters to list containers with.
|
||||
type ContainerListOptions struct {
|
||||
Quiet bool
|
||||
Size bool
|
||||
All bool
|
||||
Latest bool
|
||||
Since string
|
||||
Before string
|
||||
Limit int
|
||||
Filter filters.Args
|
||||
}
|
||||
|
||||
// ContainerList returns the list of containers in the docker host.
|
||||
func (cli *Client) ContainerList(options ContainerListOptions) ([]types.Container, error) {
|
||||
func (cli *Client) ContainerList(options types.ContainerListOptions) ([]types.Container, error) {
|
||||
var query url.Values
|
||||
|
||||
if options.All {
|
||||
|
|
|
@ -1,17 +1,13 @@
|
|||
package lib
|
||||
|
||||
import "net/url"
|
||||
import (
|
||||
"net/url"
|
||||
|
||||
// ContainerRemoveOptions holds parameters to remove containers.
|
||||
type ContainerRemoveOptions struct {
|
||||
ContainerID string
|
||||
RemoveVolumes bool
|
||||
RemoveLinks bool
|
||||
Force bool
|
||||
}
|
||||
"github.com/docker/docker/api/types"
|
||||
)
|
||||
|
||||
// ContainerRemove kills and removes a container from the docker host.
|
||||
func (cli *Client) ContainerRemove(options ContainerRemoveOptions) error {
|
||||
func (cli *Client) ContainerRemove(options types.ContainerRemoveOptions) error {
|
||||
var query url.Values
|
||||
if options.RemoveVolumes {
|
||||
query.Set("v", "1")
|
||||
|
|
|
@ -13,17 +13,8 @@ import (
|
|||
"github.com/docker/docker/api/types"
|
||||
)
|
||||
|
||||
// CopyToContainerOptions holds information
|
||||
// about files to copy into a container
|
||||
type CopyToContainerOptions struct {
|
||||
ContainerID string
|
||||
Path string
|
||||
Content io.Reader
|
||||
AllowOverwriteDirWithFile bool
|
||||
}
|
||||
|
||||
// StatContainerPath returns Stat information about a path inside the container filesystem.
|
||||
func (cli *Client) StatContainerPath(containerID, path string) (types.ContainerPathStat, error) {
|
||||
// ContainerStatPath returns Stat information about a path inside the container filesystem.
|
||||
func (cli *Client) ContainerStatPath(containerID, path string) (types.ContainerPathStat, error) {
|
||||
query := make(url.Values, 1)
|
||||
query.Set("path", filepath.ToSlash(path)) // Normalize the paths used in the API.
|
||||
|
||||
|
@ -37,7 +28,7 @@ func (cli *Client) StatContainerPath(containerID, path string) (types.ContainerP
|
|||
}
|
||||
|
||||
// CopyToContainer copies content into the container filesystem.
|
||||
func (cli *Client) CopyToContainer(options CopyToContainerOptions) error {
|
||||
func (cli *Client) CopyToContainer(options types.CopyToContainerOptions) error {
|
||||
var query url.Values
|
||||
query.Set("path", filepath.ToSlash(options.Path)) // Normalize the paths used in the API.
|
||||
// Do not allow for an existing directory to be overwritten by a non-directory and vice versa.
|
||||
|
|
|
@ -5,20 +5,14 @@ import (
|
|||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/pkg/parsers/filters"
|
||||
"github.com/docker/docker/pkg/timeutils"
|
||||
)
|
||||
|
||||
// EventsOptions hold parameters to filter events with.
|
||||
type EventsOptions struct {
|
||||
Since string
|
||||
Until string
|
||||
Filters filters.Args
|
||||
}
|
||||
|
||||
// Events returns a stream of events in the daemon in a ReadCloser.
|
||||
// It's up to the caller to close the stream.
|
||||
func (cli *Client) Events(options EventsOptions) (io.ReadCloser, error) {
|
||||
func (cli *Client) Events(options types.EventsOptions) (io.ReadCloser, error) {
|
||||
var query url.Values
|
||||
ref := time.Now()
|
||||
|
||||
|
|
|
@ -3,73 +3,36 @@ package lib
|
|||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/docker/docker/cliconfig"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/pkg/httputils"
|
||||
"github.com/docker/docker/pkg/ulimit"
|
||||
"github.com/docker/docker/pkg/units"
|
||||
"github.com/docker/docker/runconfig"
|
||||
)
|
||||
|
||||
// ImageBuildOptions holds the information
|
||||
// necessary to build images.
|
||||
type ImageBuildOptions struct {
|
||||
Tags []string
|
||||
SuppressOutput bool
|
||||
RemoteContext string
|
||||
NoCache bool
|
||||
Remove bool
|
||||
ForceRemove bool
|
||||
PullParent bool
|
||||
Isolation string
|
||||
CPUSetCPUs string
|
||||
CPUSetMems string
|
||||
CPUShares int64
|
||||
CPUQuota int64
|
||||
CPUPeriod int64
|
||||
Memory int64
|
||||
MemorySwap int64
|
||||
CgroupParent string
|
||||
ShmSize string
|
||||
Dockerfile string
|
||||
Ulimits []*ulimit.Ulimit
|
||||
BuildArgs []string
|
||||
AuthConfigs map[string]cliconfig.AuthConfig
|
||||
Context io.Reader
|
||||
}
|
||||
|
||||
// ImageBuildResponse holds information
|
||||
// returned by a server after building
|
||||
// an image.
|
||||
type ImageBuildResponse struct {
|
||||
Body io.ReadCloser
|
||||
OSType string
|
||||
}
|
||||
|
||||
// ImageBuild sends request to the daemon to build images.
|
||||
// The Body in the response implement an io.ReadCloser and it's up to the caller to
|
||||
// close it.
|
||||
func (cli *Client) ImageBuild(options ImageBuildOptions) (ImageBuildResponse, error) {
|
||||
func (cli *Client) ImageBuild(options types.ImageBuildOptions) (types.ImageBuildResponse, error) {
|
||||
query, err := imageBuildOptionsToQuery(options)
|
||||
if err != nil {
|
||||
return ImageBuildResponse{}, err
|
||||
return types.ImageBuildResponse{}, err
|
||||
}
|
||||
|
||||
headers := http.Header(make(map[string][]string))
|
||||
buf, err := json.Marshal(options.AuthConfigs)
|
||||
if err != nil {
|
||||
return ImageBuildResponse{}, err
|
||||
return types.ImageBuildResponse{}, err
|
||||
}
|
||||
headers.Add("X-Registry-Config", base64.URLEncoding.EncodeToString(buf))
|
||||
headers.Set("Content-Type", "application/tar")
|
||||
|
||||
serverResp, err := cli.POSTRaw("/build", query, options.Context, headers)
|
||||
if err != nil {
|
||||
return ImageBuildResponse{}, err
|
||||
return types.ImageBuildResponse{}, err
|
||||
}
|
||||
|
||||
var osType string
|
||||
|
@ -77,13 +40,13 @@ func (cli *Client) ImageBuild(options ImageBuildOptions) (ImageBuildResponse, er
|
|||
osType = h.OS
|
||||
}
|
||||
|
||||
return ImageBuildResponse{
|
||||
return types.ImageBuildResponse{
|
||||
Body: serverResp.body,
|
||||
OSType: osType,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func imageBuildOptionsToQuery(options ImageBuildOptions) (url.Values, error) {
|
||||
func imageBuildOptionsToQuery(options types.ImageBuildOptions) (url.Values, error) {
|
||||
query := url.Values{
|
||||
"t": options.Tags,
|
||||
}
|
||||
|
|
|
@ -3,21 +3,13 @@ package lib
|
|||
import (
|
||||
"io"
|
||||
"net/url"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
)
|
||||
|
||||
// CreateImageOptions holds information to create images.
|
||||
type CreateImageOptions struct {
|
||||
// Parent is the image to create this image from
|
||||
Parent string
|
||||
// Tag is the name to tag this image
|
||||
Tag string
|
||||
// RegistryAuth is the base64 encoded credentials for this server
|
||||
RegistryAuth string
|
||||
}
|
||||
|
||||
// CreateImage creates a new image based in the parent options.
|
||||
// ImageCreate creates a new image based in the parent options.
|
||||
// It returns the JSON content in the response body.
|
||||
func (cli *Client) CreateImage(options CreateImageOptions) (io.ReadCloser, error) {
|
||||
func (cli *Client) ImageCreate(options types.ImageCreateOptions) (io.ReadCloser, error) {
|
||||
var query url.Values
|
||||
query.Set("fromImage", options.Parent)
|
||||
query.Set("tag", options.Tag)
|
||||
|
|
|
@ -3,27 +3,13 @@ package lib
|
|||
import (
|
||||
"io"
|
||||
"net/url"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
)
|
||||
|
||||
// ImportImageOptions holds information to import images from the client host.
|
||||
type ImportImageOptions struct {
|
||||
// Source is the data to send to the server to create this image from
|
||||
Source io.Reader
|
||||
// Source is the name of the source to import this image from
|
||||
SourceName string
|
||||
// RepositoryName is the name of the repository to import this image
|
||||
RepositoryName string
|
||||
// Message is the message to tag the image with
|
||||
Message string
|
||||
// Tag is the name to tag this image
|
||||
Tag string
|
||||
// Changes are the raw changes to apply to the image
|
||||
Changes []string
|
||||
}
|
||||
|
||||
// ImportImage creates a new image based in the source options.
|
||||
// ImageImport creates a new image based in the source options.
|
||||
// It returns the JSON content in the response body.
|
||||
func (cli *Client) ImportImage(options ImportImageOptions) (io.ReadCloser, error) {
|
||||
func (cli *Client) ImageImport(options types.ImageImportOptions) (io.ReadCloser, error) {
|
||||
var query url.Values
|
||||
query.Set("fromSrc", options.SourceName)
|
||||
query.Set("repo", options.RepositoryName)
|
||||
|
|
|
@ -8,15 +8,8 @@ import (
|
|||
"github.com/docker/docker/pkg/parsers/filters"
|
||||
)
|
||||
|
||||
// ImageListOptions holds parameters to filter the list of images with.
|
||||
type ImageListOptions struct {
|
||||
MatchName string
|
||||
All bool
|
||||
Filters filters.Args
|
||||
}
|
||||
|
||||
// ImageList returns a list of images in the docker host.
|
||||
func (cli *Client) ImageList(options ImageListOptions) ([]types.Image, error) {
|
||||
func (cli *Client) ImageList(options types.ImageListOptions) ([]types.Image, error) {
|
||||
var (
|
||||
images []types.Image
|
||||
query url.Values
|
||||
|
|
|
@ -7,15 +7,8 @@ import (
|
|||
"github.com/docker/docker/api/types"
|
||||
)
|
||||
|
||||
// ImageRemoveOptions holds parameters to remove images.
|
||||
type ImageRemoveOptions struct {
|
||||
ImageID string
|
||||
Force bool
|
||||
PruneChildren bool
|
||||
}
|
||||
|
||||
// ImageRemove removes an image from the docker host.
|
||||
func (cli *Client) ImageRemove(options ImageRemoveOptions) ([]types.ImageDelete, error) {
|
||||
func (cli *Client) ImageRemove(options types.ImageRemoveOptions) ([]types.ImageDelete, error) {
|
||||
var query url.Values
|
||||
|
||||
if options.Force {
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
package lib
|
||||
|
||||
import "net/url"
|
||||
import (
|
||||
"net/url"
|
||||
|
||||
// ImageTagOptions hold parameters to tag an image
|
||||
type ImageTagOptions struct {
|
||||
ImageID string
|
||||
RepositoryName string
|
||||
Tag string
|
||||
Force bool
|
||||
}
|
||||
"github.com/docker/docker/api/types"
|
||||
)
|
||||
|
||||
// ImageTag tags an image in the docker host
|
||||
func (cli *Client) ImageTag(options types.ImageTagOptions) error {
|
||||
|
|
|
@ -5,23 +5,13 @@ import (
|
|||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/pkg/timeutils"
|
||||
)
|
||||
|
||||
// ContainerLogsOptions holds parameters to filter logs with.
|
||||
type ContainerLogsOptions struct {
|
||||
ContainerID string
|
||||
ShowStdout bool
|
||||
ShowStderr bool
|
||||
Since string
|
||||
Timestamps bool
|
||||
Follow bool
|
||||
Tail string
|
||||
}
|
||||
|
||||
// ContainerLogs returns the logs generated by a container in an io.ReadCloser.
|
||||
// It's up to the caller to close the stream.
|
||||
func (cli *Client) ContainerLogs(options ContainerLogsOptions) (io.ReadCloser, error) {
|
||||
func (cli *Client) ContainerLogs(options types.ContainerLogsOptions) (io.ReadCloser, error) {
|
||||
var query url.Values
|
||||
if options.ShowStdout {
|
||||
query.Set("stdout", "1")
|
||||
|
|
|
@ -10,20 +10,8 @@ import (
|
|||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// VersionResponse holds version information for the client and the server
|
||||
type VersionResponse struct {
|
||||
Client *types.Version
|
||||
Server *types.Version
|
||||
}
|
||||
|
||||
// ServerOK return true when the client could connect to the docker server
|
||||
// and parse the information received. It returns false otherwise.
|
||||
func (v VersionResponse) ServerOK() bool {
|
||||
return v.Server == nil
|
||||
}
|
||||
|
||||
// SystemVersion returns information of the docker client and server host.
|
||||
func (cli *Client) SystemVersion() (VersionResponse, error) {
|
||||
func (cli *Client) SystemVersion() (types.VersionResponse, error) {
|
||||
client := &types.Version{
|
||||
Version: dockerversion.Version,
|
||||
APIVersion: api.Version,
|
||||
|
@ -37,14 +25,14 @@ func (cli *Client) SystemVersion() (VersionResponse, error) {
|
|||
|
||||
resp, err := cli.GET("/version", nil, nil)
|
||||
if err != nil {
|
||||
return VersionResponse{Client: client}, err
|
||||
return types.VersionResponse{Client: client}, err
|
||||
}
|
||||
defer ensureReaderClosed(resp)
|
||||
|
||||
var server types.Version
|
||||
err = json.NewDecoder(resp.body).Decode(&server)
|
||||
if err != nil {
|
||||
return VersionResponse{Client: client}, err
|
||||
return types.VersionResponse{Client: client}, err
|
||||
}
|
||||
return types.VersionResponse{Client: client, Server: &server}, nil
|
||||
}
|
||||
|
|
|
@ -0,0 +1,163 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/docker/docker/cliconfig"
|
||||
"github.com/docker/docker/pkg/parsers/filters"
|
||||
"github.com/docker/docker/pkg/ulimit"
|
||||
)
|
||||
|
||||
// ContainerCommitOptions hods parameters to commit changes into a container.
|
||||
type ContainerCommitOptions struct {
|
||||
ContainerID string
|
||||
RepositoryName string
|
||||
Tag string
|
||||
Comment string
|
||||
Author string
|
||||
Changes []string
|
||||
Pause bool
|
||||
JSONConfig string
|
||||
}
|
||||
|
||||
// ContainerListOptions holds parameters to list containers with.
|
||||
type ContainerListOptions struct {
|
||||
Quiet bool
|
||||
Size bool
|
||||
All bool
|
||||
Latest bool
|
||||
Since string
|
||||
Before string
|
||||
Limit int
|
||||
Filter filters.Args
|
||||
}
|
||||
|
||||
// ContainerLogsOptions holds parameters to filter logs with.
|
||||
type ContainerLogsOptions struct {
|
||||
ContainerID string
|
||||
ShowStdout bool
|
||||
ShowStderr bool
|
||||
Since string
|
||||
Timestamps bool
|
||||
Follow bool
|
||||
Tail string
|
||||
}
|
||||
|
||||
// ContainerRemoveOptions holds parameters to remove containers.
|
||||
type ContainerRemoveOptions struct {
|
||||
ContainerID string
|
||||
RemoveVolumes bool
|
||||
RemoveLinks bool
|
||||
Force bool
|
||||
}
|
||||
|
||||
// CopyToContainerOptions holds information
|
||||
// about files to copy into a container
|
||||
type CopyToContainerOptions struct {
|
||||
ContainerID string
|
||||
Path string
|
||||
Content io.Reader
|
||||
AllowOverwriteDirWithFile bool
|
||||
}
|
||||
|
||||
// EventsOptions hold parameters to filter events with.
|
||||
type EventsOptions struct {
|
||||
Since string
|
||||
Until string
|
||||
Filters filters.Args
|
||||
}
|
||||
|
||||
// ImageBuildOptions holds the information
|
||||
// necessary to build images.
|
||||
type ImageBuildOptions struct {
|
||||
Tags []string
|
||||
SuppressOutput bool
|
||||
RemoteContext string
|
||||
NoCache bool
|
||||
Remove bool
|
||||
ForceRemove bool
|
||||
PullParent bool
|
||||
Isolation string
|
||||
CPUSetCPUs string
|
||||
CPUSetMems string
|
||||
CPUShares int64
|
||||
CPUQuota int64
|
||||
CPUPeriod int64
|
||||
Memory int64
|
||||
MemorySwap int64
|
||||
CgroupParent string
|
||||
ShmSize string
|
||||
Dockerfile string
|
||||
Ulimits []*ulimit.Ulimit
|
||||
BuildArgs []string
|
||||
AuthConfigs map[string]cliconfig.AuthConfig
|
||||
Context io.Reader
|
||||
}
|
||||
|
||||
// ImageBuildResponse holds information
|
||||
// returned by a server after building
|
||||
// an image.
|
||||
type ImageBuildResponse struct {
|
||||
Body io.ReadCloser
|
||||
OSType string
|
||||
}
|
||||
|
||||
// ImageCreateOptions holds information to create images.
|
||||
type ImageCreateOptions struct {
|
||||
// Parent is the image to create this image from
|
||||
Parent string
|
||||
// Tag is the name to tag this image
|
||||
Tag string
|
||||
// RegistryAuth is the base64 encoded credentials for this server
|
||||
RegistryAuth string
|
||||
}
|
||||
|
||||
// ImageImportOptions holds information to import images from the client host.
|
||||
type ImageImportOptions struct {
|
||||
// Source is the data to send to the server to create this image from
|
||||
Source io.Reader
|
||||
// Source is the name of the source to import this image from
|
||||
SourceName string
|
||||
// RepositoryName is the name of the repository to import this image
|
||||
RepositoryName string
|
||||
// Message is the message to tag the image with
|
||||
Message string
|
||||
// Tag is the name to tag this image
|
||||
Tag string
|
||||
// Changes are the raw changes to apply to the image
|
||||
Changes []string
|
||||
}
|
||||
|
||||
// ImageListOptions holds parameters to filter the list of images with.
|
||||
type ImageListOptions struct {
|
||||
MatchName string
|
||||
All bool
|
||||
Filters filters.Args
|
||||
}
|
||||
|
||||
// ImageRemoveOptions holds parameters to remove images.
|
||||
type ImageRemoveOptions struct {
|
||||
ImageID string
|
||||
Force bool
|
||||
PruneChildren bool
|
||||
}
|
||||
|
||||
// ImageTagOptions hold parameters to tag an image
|
||||
type ImageTagOptions struct {
|
||||
ImageID string
|
||||
RepositoryName string
|
||||
Tag string
|
||||
Force bool
|
||||
}
|
||||
|
||||
// VersionResponse holds version information for the client and the server
|
||||
type VersionResponse struct {
|
||||
Client *Version
|
||||
Server *Version
|
||||
}
|
||||
|
||||
// ServerOK return true when the client could connect to the docker server
|
||||
// and parse the information received. It returns false otherwise.
|
||||
func (v VersionResponse) ServerOK() bool {
|
||||
return v.Server != nil
|
||||
}
|
Загрузка…
Ссылка в новой задаче