client.go 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. package types
  2. import (
  3. "bufio"
  4. "io"
  5. "net"
  6. "github.com/docker/docker/api/types/container"
  7. "github.com/docker/docker/api/types/filters"
  8. "github.com/docker/go-units"
  9. )
  10. // CheckpointCreateOptions holds parameters to create a checkpoint from a container
  11. type CheckpointCreateOptions struct {
  12. CheckpointID string
  13. Exit bool
  14. }
  15. // ContainerAttachOptions holds parameters to attach to a container.
  16. type ContainerAttachOptions struct {
  17. Stream bool
  18. Stdin bool
  19. Stdout bool
  20. Stderr bool
  21. DetachKeys string
  22. }
  23. // ContainerCommitOptions holds parameters to commit changes into a container.
  24. type ContainerCommitOptions struct {
  25. Reference string
  26. Comment string
  27. Author string
  28. Changes []string
  29. Pause bool
  30. Config *container.Config
  31. }
  32. // ContainerExecInspect holds information returned by exec inspect.
  33. type ContainerExecInspect struct {
  34. ExecID string
  35. ContainerID string
  36. Running bool
  37. ExitCode int
  38. Pid int
  39. }
  40. // ContainerListOptions holds parameters to list containers with.
  41. type ContainerListOptions struct {
  42. Quiet bool
  43. Size bool
  44. All bool
  45. Latest bool
  46. Since string
  47. Before string
  48. Limit int
  49. Filter filters.Args
  50. }
  51. // ContainerLogsOptions holds parameters to filter logs with.
  52. type ContainerLogsOptions struct {
  53. ShowStdout bool
  54. ShowStderr bool
  55. Since string
  56. Timestamps bool
  57. Follow bool
  58. Tail string
  59. Details bool
  60. }
  61. // ContainerRemoveOptions holds parameters to remove containers.
  62. type ContainerRemoveOptions struct {
  63. RemoveVolumes bool
  64. RemoveLinks bool
  65. Force bool
  66. }
  67. // ContainerStartOptions holds parameters to start containers.
  68. type ContainerStartOptions struct {
  69. CheckpointID string
  70. }
  71. // CopyToContainerOptions holds information
  72. // about files to copy into a container
  73. type CopyToContainerOptions struct {
  74. AllowOverwriteDirWithFile bool
  75. }
  76. // EventsOptions holds parameters to filter events with.
  77. type EventsOptions struct {
  78. Since string
  79. Until string
  80. Filters filters.Args
  81. }
  82. // NetworkListOptions holds parameters to filter the list of networks with.
  83. type NetworkListOptions struct {
  84. Filters filters.Args
  85. }
  86. // HijackedResponse holds connection information for a hijacked request.
  87. type HijackedResponse struct {
  88. Conn net.Conn
  89. Reader *bufio.Reader
  90. }
  91. // Close closes the hijacked connection and reader.
  92. func (h *HijackedResponse) Close() {
  93. h.Conn.Close()
  94. }
  95. // CloseWriter is an interface that implements structs
  96. // that close input streams to prevent from writing.
  97. type CloseWriter interface {
  98. CloseWrite() error
  99. }
  100. // CloseWrite closes a readWriter for writing.
  101. func (h *HijackedResponse) CloseWrite() error {
  102. if conn, ok := h.Conn.(CloseWriter); ok {
  103. return conn.CloseWrite()
  104. }
  105. return nil
  106. }
  107. // ImageBuildOptions holds the information
  108. // necessary to build images.
  109. type ImageBuildOptions struct {
  110. Tags []string
  111. SuppressOutput bool
  112. RemoteContext string
  113. NoCache bool
  114. Remove bool
  115. ForceRemove bool
  116. PullParent bool
  117. Isolation container.Isolation
  118. CPUSetCPUs string
  119. CPUSetMems string
  120. CPUShares int64
  121. CPUQuota int64
  122. CPUPeriod int64
  123. Memory int64
  124. MemorySwap int64
  125. CgroupParent string
  126. ShmSize int64
  127. Dockerfile string
  128. Ulimits []*units.Ulimit
  129. BuildArgs map[string]string
  130. AuthConfigs map[string]AuthConfig
  131. Context io.Reader
  132. Labels map[string]string
  133. // squash the resulting image's layers to the parent
  134. // preserves the original image and creates a new one from the parent with all
  135. // the changes applied to a single layer
  136. Squash bool
  137. // CacheFrom specifies images that are used for matching cache. Images
  138. // specified here do not need to have a valid parent chain to match cache.
  139. CacheFrom []string
  140. SecurityOpt []string
  141. }
  142. // ImageBuildResponse holds information
  143. // returned by a server after building
  144. // an image.
  145. type ImageBuildResponse struct {
  146. Body io.ReadCloser
  147. OSType string
  148. }
  149. // ImageCreateOptions holds information to create images.
  150. type ImageCreateOptions struct {
  151. RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry
  152. }
  153. // ImageImportSource holds source information for ImageImport
  154. type ImageImportSource struct {
  155. Source io.Reader // Source is the data to send to the server to create this image from (mutually exclusive with SourceName)
  156. SourceName string // SourceName is the name of the image to pull (mutually exclusive with Source)
  157. }
  158. // ImageImportOptions holds information to import images from the client host.
  159. type ImageImportOptions struct {
  160. Tag string // Tag is the name to tag this image with. This attribute is deprecated.
  161. Message string // Message is the message to tag the image with
  162. Changes []string // Changes are the raw changes to apply to this image
  163. }
  164. // ImageListOptions holds parameters to filter the list of images with.
  165. type ImageListOptions struct {
  166. MatchName string
  167. All bool
  168. Filters filters.Args
  169. }
  170. // ImageLoadResponse returns information to the client about a load process.
  171. type ImageLoadResponse struct {
  172. // Body must be closed to avoid a resource leak
  173. Body io.ReadCloser
  174. JSON bool
  175. }
  176. // ImagePullOptions holds information to pull images.
  177. type ImagePullOptions struct {
  178. All bool
  179. RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry
  180. PrivilegeFunc RequestPrivilegeFunc
  181. }
  182. // RequestPrivilegeFunc is a function interface that
  183. // clients can supply to retry operations after
  184. // getting an authorization error.
  185. // This function returns the registry authentication
  186. // header value in base 64 format, or an error
  187. // if the privilege request fails.
  188. type RequestPrivilegeFunc func() (string, error)
  189. //ImagePushOptions holds information to push images.
  190. type ImagePushOptions ImagePullOptions
  191. // ImageRemoveOptions holds parameters to remove images.
  192. type ImageRemoveOptions struct {
  193. Force bool
  194. PruneChildren bool
  195. }
  196. // ImageSearchOptions holds parameters to search images with.
  197. type ImageSearchOptions struct {
  198. RegistryAuth string
  199. PrivilegeFunc RequestPrivilegeFunc
  200. Filters filters.Args
  201. Limit int
  202. }
  203. // ResizeOptions holds parameters to resize a tty.
  204. // It can be used to resize container ttys and
  205. // exec process ttys too.
  206. type ResizeOptions struct {
  207. Height uint
  208. Width uint
  209. }
  210. // VersionResponse holds version information for the client and the server
  211. type VersionResponse struct {
  212. Client *Version
  213. Server *Version
  214. }
  215. // ServerOK returns true when the client could connect to the docker server
  216. // and parse the information received. It returns false otherwise.
  217. func (v VersionResponse) ServerOK() bool {
  218. return v.Server != nil
  219. }
  220. // NodeListOptions holds parameters to list nodes with.
  221. type NodeListOptions struct {
  222. Filter filters.Args
  223. }
  224. // NodeRemoveOptions holds parameters to remove nodes with.
  225. type NodeRemoveOptions struct {
  226. Force bool
  227. }
  228. // ServiceCreateOptions contains the options to use when creating a service.
  229. type ServiceCreateOptions struct {
  230. // EncodedRegistryAuth is the encoded registry authorization credentials to
  231. // use when updating the service.
  232. //
  233. // This field follows the format of the X-Registry-Auth header.
  234. EncodedRegistryAuth string
  235. }
  236. // ServiceCreateResponse contains the information returned to a client
  237. // on the creation of a new service.
  238. type ServiceCreateResponse struct {
  239. // ID is the ID of the created service.
  240. ID string
  241. }
  242. // Values for RegistryAuthFrom in ServiceUpdateOptions
  243. const (
  244. RegistryAuthFromSpec = "spec"
  245. RegistryAuthFromPreviousSpec = "previous-spec"
  246. )
  247. // ServiceUpdateOptions contains the options to be used for updating services.
  248. type ServiceUpdateOptions struct {
  249. // EncodedRegistryAuth is the encoded registry authorization credentials to
  250. // use when updating the service.
  251. //
  252. // This field follows the format of the X-Registry-Auth header.
  253. EncodedRegistryAuth string
  254. // TODO(stevvooe): Consider moving the version parameter of ServiceUpdate
  255. // into this field. While it does open API users up to racy writes, most
  256. // users may not need that level of consistency in practice.
  257. // RegistryAuthFrom specifies where to find the registry authorization
  258. // credentials if they are not given in EncodedRegistryAuth. Valid
  259. // values are "spec" and "previous-spec".
  260. RegistryAuthFrom string
  261. }
  262. // ServiceListOptions holds parameters to list services with.
  263. type ServiceListOptions struct {
  264. Filter filters.Args
  265. }
  266. // TaskListOptions holds parameters to list tasks with.
  267. type TaskListOptions struct {
  268. Filter filters.Args
  269. }
  270. // PluginRemoveOptions holds parameters to remove plugins.
  271. type PluginRemoveOptions struct {
  272. Force bool
  273. }
  274. // PluginInstallOptions holds parameters to install a plugin.
  275. type PluginInstallOptions struct {
  276. Disabled bool
  277. AcceptAllPermissions bool
  278. RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry
  279. PrivilegeFunc RequestPrivilegeFunc
  280. AcceptPermissionsFunc func(PluginPrivileges) (bool, error)
  281. }