interface.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. package client // import "github.com/docker/docker/client"
  2. import (
  3. "context"
  4. "io"
  5. "net"
  6. "net/http"
  7. "github.com/docker/docker/api/types"
  8. "github.com/docker/docker/api/types/container"
  9. "github.com/docker/docker/api/types/events"
  10. "github.com/docker/docker/api/types/filters"
  11. "github.com/docker/docker/api/types/image"
  12. "github.com/docker/docker/api/types/network"
  13. "github.com/docker/docker/api/types/registry"
  14. "github.com/docker/docker/api/types/swarm"
  15. "github.com/docker/docker/api/types/system"
  16. "github.com/docker/docker/api/types/volume"
  17. ocispec "github.com/opencontainers/image-spec/specs-go/v1"
  18. )
  19. // CommonAPIClient is the common methods between stable and experimental versions of APIClient.
  20. type CommonAPIClient interface {
  21. ConfigAPIClient
  22. ContainerAPIClient
  23. DistributionAPIClient
  24. ImageAPIClient
  25. NodeAPIClient
  26. NetworkAPIClient
  27. PluginAPIClient
  28. ServiceAPIClient
  29. SwarmAPIClient
  30. SecretAPIClient
  31. SystemAPIClient
  32. VolumeAPIClient
  33. ClientVersion() string
  34. DaemonHost() string
  35. HTTPClient() *http.Client
  36. ServerVersion(ctx context.Context) (types.Version, error)
  37. NegotiateAPIVersion(ctx context.Context)
  38. NegotiateAPIVersionPing(types.Ping)
  39. DialHijack(ctx context.Context, url, proto string, meta map[string][]string) (net.Conn, error)
  40. Dialer() func(context.Context) (net.Conn, error)
  41. Close() error
  42. }
  43. // ContainerAPIClient defines API client methods for the containers
  44. type ContainerAPIClient interface {
  45. ContainerAttach(ctx context.Context, container string, options container.AttachOptions) (types.HijackedResponse, error)
  46. ContainerCommit(ctx context.Context, container string, options container.CommitOptions) (types.IDResponse, error)
  47. ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *ocispec.Platform, containerName string) (container.CreateResponse, error)
  48. ContainerDiff(ctx context.Context, container string) ([]container.FilesystemChange, error)
  49. ContainerExecAttach(ctx context.Context, execID string, config types.ExecStartCheck) (types.HijackedResponse, error)
  50. ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error)
  51. ContainerExecInspect(ctx context.Context, execID string) (types.ContainerExecInspect, error)
  52. ContainerExecResize(ctx context.Context, execID string, options container.ResizeOptions) error
  53. ContainerExecStart(ctx context.Context, execID string, config types.ExecStartCheck) error
  54. ContainerExport(ctx context.Context, container string) (io.ReadCloser, error)
  55. ContainerInspect(ctx context.Context, container string) (types.ContainerJSON, error)
  56. ContainerInspectWithRaw(ctx context.Context, container string, getSize bool) (types.ContainerJSON, []byte, error)
  57. ContainerKill(ctx context.Context, container, signal string) error
  58. ContainerList(ctx context.Context, options container.ListOptions) ([]types.Container, error)
  59. ContainerLogs(ctx context.Context, container string, options container.LogsOptions) (io.ReadCloser, error)
  60. ContainerPause(ctx context.Context, container string) error
  61. ContainerRemove(ctx context.Context, container string, options container.RemoveOptions) error
  62. ContainerRename(ctx context.Context, container, newContainerName string) error
  63. ContainerResize(ctx context.Context, container string, options container.ResizeOptions) error
  64. ContainerRestart(ctx context.Context, container string, options container.StopOptions) error
  65. ContainerStatPath(ctx context.Context, container, path string) (types.ContainerPathStat, error)
  66. ContainerStats(ctx context.Context, container string, stream bool) (types.ContainerStats, error)
  67. ContainerStatsOneShot(ctx context.Context, container string) (types.ContainerStats, error)
  68. ContainerStart(ctx context.Context, container string, options container.StartOptions) error
  69. ContainerStop(ctx context.Context, container string, options container.StopOptions) error
  70. ContainerTop(ctx context.Context, container string, arguments []string) (container.ContainerTopOKBody, error)
  71. ContainerUnpause(ctx context.Context, container string) error
  72. ContainerUpdate(ctx context.Context, container string, updateConfig container.UpdateConfig) (container.ContainerUpdateOKBody, error)
  73. ContainerWait(ctx context.Context, container string, condition container.WaitCondition) (<-chan container.WaitResponse, <-chan error)
  74. CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)
  75. CopyToContainer(ctx context.Context, container, path string, content io.Reader, options types.CopyToContainerOptions) error
  76. ContainersPrune(ctx context.Context, pruneFilters filters.Args) (types.ContainersPruneReport, error)
  77. }
  78. // DistributionAPIClient defines API client methods for the registry
  79. type DistributionAPIClient interface {
  80. DistributionInspect(ctx context.Context, image, encodedRegistryAuth string) (registry.DistributionInspect, error)
  81. }
  82. // ImageAPIClient defines API client methods for the images
  83. type ImageAPIClient interface {
  84. ImageBuild(ctx context.Context, context io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error)
  85. BuildCachePrune(ctx context.Context, opts types.BuildCachePruneOptions) (*types.BuildCachePruneReport, error)
  86. BuildCancel(ctx context.Context, id string) error
  87. ImageCreate(ctx context.Context, parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error)
  88. ImageHistory(ctx context.Context, image string) ([]image.HistoryResponseItem, error)
  89. ImageImport(ctx context.Context, source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error)
  90. ImageInspectWithRaw(ctx context.Context, image string) (types.ImageInspect, []byte, error)
  91. ImageList(ctx context.Context, options types.ImageListOptions) ([]image.Summary, error)
  92. ImageLoad(ctx context.Context, input io.Reader, quiet bool) (types.ImageLoadResponse, error)
  93. ImagePull(ctx context.Context, ref string, options types.ImagePullOptions) (io.ReadCloser, error)
  94. ImagePush(ctx context.Context, ref string, options types.ImagePushOptions) (io.ReadCloser, error)
  95. ImageRemove(ctx context.Context, image string, options types.ImageRemoveOptions) ([]image.DeleteResponse, error)
  96. ImageSearch(ctx context.Context, term string, options types.ImageSearchOptions) ([]registry.SearchResult, error)
  97. ImageSave(ctx context.Context, images []string) (io.ReadCloser, error)
  98. ImageTag(ctx context.Context, image, ref string) error
  99. ImagesPrune(ctx context.Context, pruneFilter filters.Args) (types.ImagesPruneReport, error)
  100. }
  101. // NetworkAPIClient defines API client methods for the networks
  102. type NetworkAPIClient interface {
  103. NetworkConnect(ctx context.Context, network, container string, config *network.EndpointSettings) error
  104. NetworkCreate(ctx context.Context, name string, options types.NetworkCreate) (types.NetworkCreateResponse, error)
  105. NetworkDisconnect(ctx context.Context, network, container string, force bool) error
  106. NetworkInspect(ctx context.Context, network string, options types.NetworkInspectOptions) (types.NetworkResource, error)
  107. NetworkInspectWithRaw(ctx context.Context, network string, options types.NetworkInspectOptions) (types.NetworkResource, []byte, error)
  108. NetworkList(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error)
  109. NetworkRemove(ctx context.Context, network string) error
  110. NetworksPrune(ctx context.Context, pruneFilter filters.Args) (types.NetworksPruneReport, error)
  111. }
  112. // NodeAPIClient defines API client methods for the nodes
  113. type NodeAPIClient interface {
  114. NodeInspectWithRaw(ctx context.Context, nodeID string) (swarm.Node, []byte, error)
  115. NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error)
  116. NodeRemove(ctx context.Context, nodeID string, options types.NodeRemoveOptions) error
  117. NodeUpdate(ctx context.Context, nodeID string, version swarm.Version, node swarm.NodeSpec) error
  118. }
  119. // PluginAPIClient defines API client methods for the plugins
  120. type PluginAPIClient interface {
  121. PluginList(ctx context.Context, filter filters.Args) (types.PluginsListResponse, error)
  122. PluginRemove(ctx context.Context, name string, options types.PluginRemoveOptions) error
  123. PluginEnable(ctx context.Context, name string, options types.PluginEnableOptions) error
  124. PluginDisable(ctx context.Context, name string, options types.PluginDisableOptions) error
  125. PluginInstall(ctx context.Context, name string, options types.PluginInstallOptions) (io.ReadCloser, error)
  126. PluginUpgrade(ctx context.Context, name string, options types.PluginInstallOptions) (io.ReadCloser, error)
  127. PluginPush(ctx context.Context, name string, registryAuth string) (io.ReadCloser, error)
  128. PluginSet(ctx context.Context, name string, args []string) error
  129. PluginInspectWithRaw(ctx context.Context, name string) (*types.Plugin, []byte, error)
  130. PluginCreate(ctx context.Context, createContext io.Reader, options types.PluginCreateOptions) error
  131. }
  132. // ServiceAPIClient defines API client methods for the services
  133. type ServiceAPIClient interface {
  134. ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options types.ServiceCreateOptions) (swarm.ServiceCreateResponse, error)
  135. ServiceInspectWithRaw(ctx context.Context, serviceID string, options types.ServiceInspectOptions) (swarm.Service, []byte, error)
  136. ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error)
  137. ServiceRemove(ctx context.Context, serviceID string) error
  138. ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error)
  139. ServiceLogs(ctx context.Context, serviceID string, options container.LogsOptions) (io.ReadCloser, error)
  140. TaskLogs(ctx context.Context, taskID string, options container.LogsOptions) (io.ReadCloser, error)
  141. TaskInspectWithRaw(ctx context.Context, taskID string) (swarm.Task, []byte, error)
  142. TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error)
  143. }
  144. // SwarmAPIClient defines API client methods for the swarm
  145. type SwarmAPIClient interface {
  146. SwarmInit(ctx context.Context, req swarm.InitRequest) (string, error)
  147. SwarmJoin(ctx context.Context, req swarm.JoinRequest) error
  148. SwarmGetUnlockKey(ctx context.Context) (types.SwarmUnlockKeyResponse, error)
  149. SwarmUnlock(ctx context.Context, req swarm.UnlockRequest) error
  150. SwarmLeave(ctx context.Context, force bool) error
  151. SwarmInspect(ctx context.Context) (swarm.Swarm, error)
  152. SwarmUpdate(ctx context.Context, version swarm.Version, swarm swarm.Spec, flags swarm.UpdateFlags) error
  153. }
  154. // SystemAPIClient defines API client methods for the system
  155. type SystemAPIClient interface {
  156. Events(ctx context.Context, options types.EventsOptions) (<-chan events.Message, <-chan error)
  157. Info(ctx context.Context) (system.Info, error)
  158. RegistryLogin(ctx context.Context, auth registry.AuthConfig) (registry.AuthenticateOKBody, error)
  159. DiskUsage(ctx context.Context, options types.DiskUsageOptions) (types.DiskUsage, error)
  160. Ping(ctx context.Context) (types.Ping, error)
  161. }
  162. // VolumeAPIClient defines API client methods for the volumes
  163. type VolumeAPIClient interface {
  164. VolumeCreate(ctx context.Context, options volume.CreateOptions) (volume.Volume, error)
  165. VolumeInspect(ctx context.Context, volumeID string) (volume.Volume, error)
  166. VolumeInspectWithRaw(ctx context.Context, volumeID string) (volume.Volume, []byte, error)
  167. VolumeList(ctx context.Context, options volume.ListOptions) (volume.ListResponse, error)
  168. VolumeRemove(ctx context.Context, volumeID string, force bool) error
  169. VolumesPrune(ctx context.Context, pruneFilter filters.Args) (types.VolumesPruneReport, error)
  170. VolumeUpdate(ctx context.Context, volumeID string, version swarm.Version, options volume.UpdateOptions) error
  171. }
  172. // SecretAPIClient defines API client methods for secrets
  173. type SecretAPIClient interface {
  174. SecretList(ctx context.Context, options types.SecretListOptions) ([]swarm.Secret, error)
  175. SecretCreate(ctx context.Context, secret swarm.SecretSpec) (types.SecretCreateResponse, error)
  176. SecretRemove(ctx context.Context, id string) error
  177. SecretInspectWithRaw(ctx context.Context, name string) (swarm.Secret, []byte, error)
  178. SecretUpdate(ctx context.Context, id string, version swarm.Version, secret swarm.SecretSpec) error
  179. }
  180. // ConfigAPIClient defines API client methods for configs
  181. type ConfigAPIClient interface {
  182. ConfigList(ctx context.Context, options types.ConfigListOptions) ([]swarm.Config, error)
  183. ConfigCreate(ctx context.Context, config swarm.ConfigSpec) (types.ConfigCreateResponse, error)
  184. ConfigRemove(ctx context.Context, id string) error
  185. ConfigInspectWithRaw(ctx context.Context, name string) (swarm.Config, []byte, error)
  186. ConfigUpdate(ctx context.Context, id string, version swarm.Version, config swarm.ConfigSpec) error
  187. }