From 8b15839ee85b291266d07f97d9ad6ca0326d1339 Mon Sep 17 00:00:00 2001 From: David Calavera Date: Fri, 4 Dec 2015 17:02:06 -0500 Subject: [PATCH] Create interface that clients that talk to the api must fulfill. Signed-off-by: David Calavera --- api/client/build.go | 4 +- api/client/cli.go | 2 +- api/client/client.go | 55 ++++++++++ api/client/commit.go | 4 +- api/client/cp.go | 5 +- api/client/create.go | 4 +- api/client/events.go | 4 +- api/client/images.go | 4 +- api/client/import.go | 6 +- api/client/lib/container_commit.go | 12 --- api/client/lib/container_list.go | 14 +-- api/client/lib/container_remove.go | 14 +-- api/client/lib/copy.go | 15 +-- api/client/lib/events.go | 10 +- api/client/lib/image_build.go | 51 ++------- api/client/lib/image_create.go | 16 +-- api/client/lib/image_import.go | 22 +--- api/client/lib/image_list.go | 9 +- api/client/lib/image_remove.go | 9 +- api/client/lib/image_tag.go | 12 +-- api/client/lib/logs.go | 14 +-- api/client/lib/version.go | 18 +--- api/client/logs.go | 4 +- api/client/ps.go | 4 +- api/client/rm.go | 4 +- api/client/rmi.go | 4 +- api/client/tag.go | 4 +- api/client/trust.go | 4 +- api/types/client.go | 163 +++++++++++++++++++++++++++++ 29 files changed, 283 insertions(+), 208 deletions(-) create mode 100644 api/types/client.go diff --git a/api/client/build.go b/api/client/build.go index 6268464c72..8af15b2465 100644 --- a/api/client/build.go +++ b/api/client/build.go @@ -15,7 +15,7 @@ import ( "github.com/docker/distribution/reference" "github.com/docker/docker/api" - "github.com/docker/docker/api/client/lib" + "github.com/docker/docker/api/types" Cli "github.com/docker/docker/cli" "github.com/docker/docker/opts" "github.com/docker/docker/pkg/archive" @@ -207,7 +207,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error { remoteContext = cmd.Arg(0) } - options := lib.ImageBuildOptions{ + options := types.ImageBuildOptions{ Context: body, Memory: memory, MemorySwap: memorySwap, diff --git a/api/client/cli.go b/api/client/cli.go index 7848fd9228..d7cf4f56b3 100644 --- a/api/client/cli.go +++ b/api/client/cli.go @@ -43,7 +43,7 @@ type DockerCli struct { // isTerminalOut indicates whether the client's STDOUT is a TTY isTerminalOut bool // client is the http client that performs all API operations - client *lib.Client + client apiClient // DEPRECATED OPTIONS TO MAKE THE CLIENT COMPILE // TODO: Remove diff --git a/api/client/client.go b/api/client/client.go index 4cfce5f684..8f9efa8374 100644 --- a/api/client/client.go +++ b/api/client/client.go @@ -3,3 +3,58 @@ // 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. package client + +import ( + "io" + + "github.com/docker/docker/api/types" + "github.com/docker/docker/cliconfig" + "github.com/docker/docker/pkg/parsers/filters" + "github.com/docker/docker/runconfig" +) + +// apiClient is an interface that clients that talk with a docker server must implement. +type apiClient interface { + ContainerCommit(options types.ContainerCommitOptions) (types.ContainerCommitResponse, error) + ContainerCreate(config *runconfig.ContainerConfigWrapper, containerName string) (types.ContainerCreateResponse, error) + ContainerDiff(containerID string) ([]types.ContainerChange, error) + ContainerExport(containerID string) (io.ReadCloser, error) + ContainerInspect(containerID string) (types.ContainerJSON, 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 + ContainerRestart(containerID string, timeout int) error + ContainerStatPath(containerID, path string) (types.ContainerPathStat, error) + ContainerStop(containerID string, timeout int) error + ContainerTop(containerID string, arguments []string) (types.ContainerProcessList, error) + ContainerUnpause(containerID string) 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) + ImageList(options types.ImageListOptions) ([]types.Image, error) + ImageLoad(input io.Reader) (io.ReadCloser, error) + ImageRemove(options types.ImageRemoveOptions) ([]types.ImageDelete, 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() ([]types.NetworkResource, error) + NetworkRemove(networkID string) error + RegistryLogin(auth cliconfig.AuthConfig) (types.AuthResponse, error) + SystemVersion() (types.VersionResponse, 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 +} diff --git a/api/client/commit.go b/api/client/commit.go index fb9cfe2820..100a985f5c 100644 --- a/api/client/commit.go +++ b/api/client/commit.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/docker/distribution/reference" - "github.com/docker/docker/api/client/lib" + "github.com/docker/docker/api/types" Cli "github.com/docker/docker/cli" "github.com/docker/docker/opts" flag "github.com/docker/docker/pkg/mflag" @@ -56,7 +56,7 @@ func (cli *DockerCli) CmdCommit(args ...string) error { } } - options := lib.ContainerCommitOptions{ + options := types.ContainerCommitOptions{ ContainerID: name, RepositoryName: repositoryName, Tag: tag, diff --git a/api/client/cp.go b/api/client/cp.go index 16e2cf471e..ab92689710 100644 --- a/api/client/cp.go +++ b/api/client/cp.go @@ -7,7 +7,6 @@ import ( "path/filepath" "strings" - "github.com/docker/docker/api/client/lib" "github.com/docker/docker/api/types" Cli "github.com/docker/docker/cli" "github.com/docker/docker/pkg/archive" @@ -126,7 +125,7 @@ func splitCpArg(arg string) (container, path string) { } func (cli *DockerCli) statContainerPath(containerName, path string) (types.ContainerPathStat, error) { - return cli.client.StatContainerPath(containerName, path) + return cli.client.ContainerStatPath(containerName, path) } func resolveLocalPath(localPath string) (absPath string, err error) { @@ -286,7 +285,7 @@ func (cli *DockerCli) copyToContainer(srcPath, dstContainer, dstPath string, cpP content = preparedArchive } - options := lib.CopyToContainerOptions{ + options := types.CopyToContainerOptions{ ContainerID: dstContainer, Path: resolvedDstPath, Content: content, diff --git a/api/client/create.go b/api/client/create.go index 25189fa14a..a5430eb3cb 100644 --- a/api/client/create.go +++ b/api/client/create.go @@ -51,13 +51,13 @@ func (cli *DockerCli) pullImageCustomOut(image string, out io.Writer) error { return err } - options := lib.CreateImageOptions{ + options := types.ImageCreateOptions{ Parent: ref.Name(), Tag: tag, RegistryAuth: base64.URLEncoding.EncodeToString(buf), } - responseBody, err := cli.client.CreateImage(options) + responseBody, err := cli.client.ImageCreate(options) if err != nil { return err } diff --git a/api/client/events.go b/api/client/events.go index 568be41fad..a6702e130d 100644 --- a/api/client/events.go +++ b/api/client/events.go @@ -1,7 +1,7 @@ package client import ( - "github.com/docker/docker/api/client/lib" + "github.com/docker/docker/api/types" Cli "github.com/docker/docker/cli" "github.com/docker/docker/opts" "github.com/docker/docker/pkg/jsonmessage" @@ -34,7 +34,7 @@ func (cli *DockerCli) CmdEvents(args ...string) error { } } - options := lib.EventsOptions{ + options := types.EventsOptions{ Since: *since, Until: *until, Filters: eventFilterArgs, diff --git a/api/client/images.go b/api/client/images.go index 02c59fdf42..895f1b0d56 100644 --- a/api/client/images.go +++ b/api/client/images.go @@ -7,7 +7,7 @@ import ( "time" "github.com/docker/distribution/reference" - "github.com/docker/docker/api/client/lib" + "github.com/docker/docker/api/types" Cli "github.com/docker/docker/cli" "github.com/docker/docker/opts" flag "github.com/docker/docker/pkg/mflag" @@ -48,7 +48,7 @@ func (cli *DockerCli) CmdImages(args ...string) error { matchName = cmd.Arg(0) } - options := lib.ImageListOptions{ + options := types.ImageListOptions{ MatchName: matchName, All: *all, Filters: imageFilterArgs, diff --git a/api/client/import.go b/api/client/import.go index 1a5887a020..2e9be55f57 100644 --- a/api/client/import.go +++ b/api/client/import.go @@ -6,7 +6,7 @@ import ( "os" "github.com/docker/distribution/reference" - "github.com/docker/docker/api/client/lib" + "github.com/docker/docker/api/types" Cli "github.com/docker/docker/cli" "github.com/docker/docker/opts" "github.com/docker/docker/pkg/jsonmessage" @@ -67,7 +67,7 @@ func (cli *DockerCli) CmdImport(args ...string) error { } - options := lib.ImportImageOptions{ + options := types.ImageImportOptions{ Source: in, SourceName: srcName, RepositoryName: repository, @@ -76,7 +76,7 @@ func (cli *DockerCli) CmdImport(args ...string) error { Changes: changes, } - responseBody, err := cli.client.ImportImage(options) + responseBody, err := cli.client.ImageImport(options) if err != nil { return err } diff --git a/api/client/lib/container_commit.go b/api/client/lib/container_commit.go index c097e65902..308add49f0 100644 --- a/api/client/lib/container_commit.go +++ b/api/client/lib/container_commit.go @@ -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{} diff --git a/api/client/lib/container_list.go b/api/client/lib/container_list.go index 51451f6618..fbb91a6e6b 100644 --- a/api/client/lib/container_list.go +++ b/api/client/lib/container_list.go @@ -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 { diff --git a/api/client/lib/container_remove.go b/api/client/lib/container_remove.go index 3c2b0a24b4..68072a5c96 100644 --- a/api/client/lib/container_remove.go +++ b/api/client/lib/container_remove.go @@ -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") diff --git a/api/client/lib/copy.go b/api/client/lib/copy.go index c1b8593a98..458896e69f 100644 --- a/api/client/lib/copy.go +++ b/api/client/lib/copy.go @@ -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. diff --git a/api/client/lib/events.go b/api/client/lib/events.go index 1d50cb5f3e..ff514af509 100644 --- a/api/client/lib/events.go +++ b/api/client/lib/events.go @@ -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() diff --git a/api/client/lib/image_build.go b/api/client/lib/image_build.go index 0b89b05ff6..1f3c1f8222 100644 --- a/api/client/lib/image_build.go +++ b/api/client/lib/image_build.go @@ -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, } diff --git a/api/client/lib/image_create.go b/api/client/lib/image_create.go index d56bfa647c..f7e5bc97fb 100644 --- a/api/client/lib/image_create.go +++ b/api/client/lib/image_create.go @@ -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) diff --git a/api/client/lib/image_import.go b/api/client/lib/image_import.go index ebc7130e0e..9495036469 100644 --- a/api/client/lib/image_import.go +++ b/api/client/lib/image_import.go @@ -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) diff --git a/api/client/lib/image_list.go b/api/client/lib/image_list.go index e34cc0026f..5e27112944 100644 --- a/api/client/lib/image_list.go +++ b/api/client/lib/image_list.go @@ -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 diff --git a/api/client/lib/image_remove.go b/api/client/lib/image_remove.go index 00d1bada83..ebf352dbb8 100644 --- a/api/client/lib/image_remove.go +++ b/api/client/lib/image_remove.go @@ -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 { diff --git a/api/client/lib/image_tag.go b/api/client/lib/image_tag.go index 6ef5269cb0..23097501ed 100644 --- a/api/client/lib/image_tag.go +++ b/api/client/lib/image_tag.go @@ -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 { diff --git a/api/client/lib/logs.go b/api/client/lib/logs.go index a464de7c0b..677d29124d 100644 --- a/api/client/lib/logs.go +++ b/api/client/lib/logs.go @@ -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") diff --git a/api/client/lib/version.go b/api/client/lib/version.go index 0164a05007..b460e4b886 100644 --- a/api/client/lib/version.go +++ b/api/client/lib/version.go @@ -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 } diff --git a/api/client/logs.go b/api/client/logs.go index 52465683a0..77c754f4da 100644 --- a/api/client/logs.go +++ b/api/client/logs.go @@ -4,7 +4,7 @@ import ( "fmt" "io" - "github.com/docker/docker/api/client/lib" + "github.com/docker/docker/api/types" Cli "github.com/docker/docker/cli" flag "github.com/docker/docker/pkg/mflag" "github.com/docker/docker/pkg/stdcopy" @@ -39,7 +39,7 @@ func (cli *DockerCli) CmdLogs(args ...string) error { return fmt.Errorf("\"logs\" command is supported only for \"json-file\" and \"journald\" logging drivers (got: %s)", c.HostConfig.LogConfig.Type) } - options := lib.ContainerLogsOptions{ + options := types.ContainerLogsOptions{ ContainerID: name, ShowStdout: true, ShowStderr: true, diff --git a/api/client/ps.go b/api/client/ps.go index 7810cfeaaf..a39bc5c0a9 100644 --- a/api/client/ps.go +++ b/api/client/ps.go @@ -1,8 +1,8 @@ package client import ( - "github.com/docker/docker/api/client/lib" "github.com/docker/docker/api/client/ps" + "github.com/docker/docker/api/types" Cli "github.com/docker/docker/cli" "github.com/docker/docker/opts" flag "github.com/docker/docker/pkg/mflag" @@ -47,7 +47,7 @@ func (cli *DockerCli) CmdPs(args ...string) error { } } - options := lib.ContainerListOptions{ + options := types.ContainerListOptions{ All: *all, Limit: *last, Since: *since, diff --git a/api/client/rm.go b/api/client/rm.go index cf92e889b7..b26cb53d02 100644 --- a/api/client/rm.go +++ b/api/client/rm.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/docker/docker/api/client/lib" + "github.com/docker/docker/api/types" Cli "github.com/docker/docker/cli" flag "github.com/docker/docker/pkg/mflag" ) @@ -28,7 +28,7 @@ func (cli *DockerCli) CmdRm(args ...string) error { } name = strings.Trim(name, "/") - options := lib.ContainerRemoveOptions{ + options := types.ContainerRemoveOptions{ ContainerID: name, RemoveVolumes: *v, RemoveLinks: *link, diff --git a/api/client/rmi.go b/api/client/rmi.go index a618031831..9569370ea2 100644 --- a/api/client/rmi.go +++ b/api/client/rmi.go @@ -4,7 +4,7 @@ import ( "fmt" "net/url" - "github.com/docker/docker/api/client/lib" + "github.com/docker/docker/api/types" Cli "github.com/docker/docker/cli" flag "github.com/docker/docker/pkg/mflag" ) @@ -30,7 +30,7 @@ func (cli *DockerCli) CmdRmi(args ...string) error { var errNames []string for _, name := range cmd.Args() { - options := lib.ImageRemoveOptions{ + options := types.ImageRemoveOptions{ ImageID: name, Force: *force, PruneChildren: !*noprune, diff --git a/api/client/tag.go b/api/client/tag.go index 27bf80cff8..385a155c58 100644 --- a/api/client/tag.go +++ b/api/client/tag.go @@ -4,7 +4,7 @@ import ( "errors" "github.com/docker/distribution/reference" - "github.com/docker/docker/api/client/lib" + "github.com/docker/docker/api/types" Cli "github.com/docker/docker/cli" flag "github.com/docker/docker/pkg/mflag" "github.com/docker/docker/registry" @@ -41,7 +41,7 @@ func (cli *DockerCli) CmdTag(args ...string) error { return err } - options := lib.ImageTagOptions{ + options := types.ImageTagOptions{ ImageID: cmd.Arg(0), RepositoryName: ref.Name(), Tag: tag, diff --git a/api/client/trust.go b/api/client/trust.go index f41cf02c7c..4a550a381a 100644 --- a/api/client/trust.go +++ b/api/client/trust.go @@ -22,7 +22,7 @@ import ( "github.com/docker/distribution/reference" "github.com/docker/distribution/registry/client/auth" "github.com/docker/distribution/registry/client/transport" - "github.com/docker/docker/api/client/lib" + "github.com/docker/docker/api/types" "github.com/docker/docker/cliconfig" "github.com/docker/docker/pkg/ansiescape" "github.com/docker/docker/pkg/ioutils" @@ -252,7 +252,7 @@ func (cli *DockerCli) trustedReference(ref reference.NamedTagged) (reference.Can func (cli *DockerCli) tagTrusted(trustedRef reference.Canonical, ref reference.NamedTagged) error { fmt.Fprintf(cli.out, "Tagging %s as %s\n", trustedRef.String(), ref.String()) - options := lib.ImageTagOptions{ + options := types.ImageTagOptions{ ImageID: trustedRef.String(), RepositoryName: trustedRef.Name(), Tag: ref.Tag(), diff --git a/api/types/client.go b/api/types/client.go new file mode 100644 index 0000000000..b528999f25 --- /dev/null +++ b/api/types/client.go @@ -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 +}