client.go 8.9 KB

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