client.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. package types // import "github.com/docker/docker/api/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. CheckpointDir string
  14. Exit bool
  15. }
  16. // CheckpointListOptions holds parameters to list checkpoints for a container
  17. type CheckpointListOptions struct {
  18. CheckpointDir string
  19. }
  20. // CheckpointDeleteOptions holds parameters to delete a checkpoint from a container
  21. type CheckpointDeleteOptions struct {
  22. CheckpointID string
  23. CheckpointDir string
  24. }
  25. // ContainerAttachOptions holds parameters to attach to a container.
  26. type ContainerAttachOptions struct {
  27. Stream bool
  28. Stdin bool
  29. Stdout bool
  30. Stderr bool
  31. DetachKeys string
  32. Logs bool
  33. }
  34. // ContainerCommitOptions holds parameters to commit changes into a container.
  35. type ContainerCommitOptions struct {
  36. Reference string
  37. Comment string
  38. Author string
  39. Changes []string
  40. Pause bool
  41. Config *container.Config
  42. }
  43. // ContainerExecInspect holds information returned by exec inspect.
  44. type ContainerExecInspect struct {
  45. ExecID string
  46. ContainerID string
  47. Running bool
  48. ExitCode int
  49. Pid int
  50. }
  51. // ContainerListOptions holds parameters to list containers with.
  52. type ContainerListOptions struct {
  53. Quiet bool
  54. Size bool
  55. All bool
  56. Latest bool
  57. Since string
  58. Before string
  59. Limit int
  60. Filters filters.Args
  61. }
  62. // ContainerLogsOptions holds parameters to filter logs with.
  63. type ContainerLogsOptions struct {
  64. ShowStdout bool
  65. ShowStderr bool
  66. Since string
  67. Until string
  68. Timestamps bool
  69. Follow bool
  70. Tail string
  71. Details bool
  72. }
  73. // ContainerRemoveOptions holds parameters to remove containers.
  74. type ContainerRemoveOptions struct {
  75. RemoveVolumes bool
  76. RemoveLinks bool
  77. Force bool
  78. }
  79. // ContainerStartOptions holds parameters to start containers.
  80. type ContainerStartOptions struct {
  81. CheckpointID string
  82. CheckpointDir string
  83. }
  84. // CopyToContainerOptions holds information
  85. // about files to copy into a container
  86. type CopyToContainerOptions struct {
  87. AllowOverwriteDirWithFile bool
  88. CopyUIDGID bool
  89. }
  90. // EventsOptions holds parameters to filter events with.
  91. type EventsOptions struct {
  92. Since string
  93. Until string
  94. Filters filters.Args
  95. }
  96. // NetworkListOptions holds parameters to filter the list of networks with.
  97. type NetworkListOptions struct {
  98. Filters filters.Args
  99. }
  100. // HijackedResponse holds connection information for a hijacked request.
  101. type HijackedResponse struct {
  102. Conn net.Conn
  103. Reader *bufio.Reader
  104. }
  105. // Close closes the hijacked connection and reader.
  106. func (h *HijackedResponse) Close() {
  107. h.Conn.Close()
  108. }
  109. // CloseWriter is an interface that implements structs
  110. // that close input streams to prevent from writing.
  111. type CloseWriter interface {
  112. CloseWrite() error
  113. }
  114. // CloseWrite closes a readWriter for writing.
  115. func (h *HijackedResponse) CloseWrite() error {
  116. if conn, ok := h.Conn.(CloseWriter); ok {
  117. return conn.CloseWrite()
  118. }
  119. return nil
  120. }
  121. // ImageBuildOptions holds the information
  122. // necessary to build images.
  123. type ImageBuildOptions struct {
  124. Tags []string
  125. SuppressOutput bool
  126. RemoteContext string
  127. NoCache bool
  128. Remove bool
  129. ForceRemove bool
  130. PullParent bool
  131. Isolation container.Isolation
  132. CPUSetCPUs string
  133. CPUSetMems string
  134. CPUShares int64
  135. CPUQuota int64
  136. CPUPeriod int64
  137. Memory int64
  138. MemorySwap int64
  139. CgroupParent string
  140. NetworkMode string
  141. ShmSize int64
  142. Dockerfile string
  143. Ulimits []*units.Ulimit
  144. // BuildArgs needs to be a *string instead of just a string so that
  145. // we can tell the difference between "" (empty string) and no value
  146. // at all (nil). See the parsing of buildArgs in
  147. // api/server/router/build/build_routes.go for even more info.
  148. BuildArgs map[string]*string
  149. AuthConfigs map[string]AuthConfig
  150. Context io.Reader
  151. Labels map[string]string
  152. // squash the resulting image's layers to the parent
  153. // preserves the original image and creates a new one from the parent with all
  154. // the changes applied to a single layer
  155. Squash bool
  156. // CacheFrom specifies images that are used for matching cache. Images
  157. // specified here do not need to have a valid parent chain to match cache.
  158. CacheFrom []string
  159. SecurityOpt []string
  160. ExtraHosts []string // List of extra hosts
  161. Target string
  162. SessionID string
  163. Platform string
  164. }
  165. // ImageBuildResponse holds information
  166. // returned by a server after building
  167. // an image.
  168. type ImageBuildResponse struct {
  169. Body io.ReadCloser
  170. OSType string
  171. }
  172. // ImageCreateOptions holds information to create images.
  173. type ImageCreateOptions struct {
  174. RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry.
  175. Platform string // Platform is the target platform of the image if it needs to be pulled from the registry.
  176. }
  177. // ImageImportSource holds source information for ImageImport
  178. type ImageImportSource struct {
  179. Source io.Reader // Source is the data to send to the server to create this image from. You must set SourceName to "-" to leverage this.
  180. SourceName string // SourceName is the name of the image to pull. Set to "-" to leverage the Source attribute.
  181. }
  182. // ImageImportOptions holds information to import images from the client host.
  183. type ImageImportOptions struct {
  184. Tag string // Tag is the name to tag this image with. This attribute is deprecated.
  185. Message string // Message is the message to tag the image with
  186. Changes []string // Changes are the raw changes to apply to this image
  187. Platform string // Platform is the target platform of the image
  188. }
  189. // ImageListOptions holds parameters to filter the list of images with.
  190. type ImageListOptions struct {
  191. All bool
  192. Filters filters.Args
  193. }
  194. // ImageLoadResponse returns information to the client about a load process.
  195. type ImageLoadResponse struct {
  196. // Body must be closed to avoid a resource leak
  197. Body io.ReadCloser
  198. JSON bool
  199. }
  200. // ImagePullOptions holds information to pull images.
  201. type ImagePullOptions struct {
  202. All bool
  203. RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry
  204. PrivilegeFunc RequestPrivilegeFunc
  205. Platform string
  206. }
  207. // RequestPrivilegeFunc is a function interface that
  208. // clients can supply to retry operations after
  209. // getting an authorization error.
  210. // This function returns the registry authentication
  211. // header value in base 64 format, or an error
  212. // if the privilege request fails.
  213. type RequestPrivilegeFunc func() (string, error)
  214. //ImagePushOptions holds information to push images.
  215. type ImagePushOptions ImagePullOptions
  216. // ImageRemoveOptions holds parameters to remove images.
  217. type ImageRemoveOptions struct {
  218. Force bool
  219. PruneChildren bool
  220. }
  221. // ImageSearchOptions holds parameters to search images with.
  222. type ImageSearchOptions struct {
  223. RegistryAuth string
  224. PrivilegeFunc RequestPrivilegeFunc
  225. Filters filters.Args
  226. Limit int
  227. }
  228. // ResizeOptions holds parameters to resize a tty.
  229. // It can be used to resize container ttys and
  230. // exec process ttys too.
  231. type ResizeOptions struct {
  232. Height uint
  233. Width uint
  234. }
  235. // NodeListOptions holds parameters to list nodes with.
  236. type NodeListOptions struct {
  237. Filters filters.Args
  238. }
  239. // NodeRemoveOptions holds parameters to remove nodes with.
  240. type NodeRemoveOptions struct {
  241. Force bool
  242. }
  243. // ServiceCreateOptions contains the options to use when creating a service.
  244. type ServiceCreateOptions struct {
  245. // EncodedRegistryAuth is the encoded registry authorization credentials to
  246. // use when updating the service.
  247. //
  248. // This field follows the format of the X-Registry-Auth header.
  249. EncodedRegistryAuth string
  250. // QueryRegistry indicates whether the service update requires
  251. // contacting a registry. A registry may be contacted to retrieve
  252. // the image digest and manifest, which in turn can be used to update
  253. // platform or other information about the service.
  254. QueryRegistry bool
  255. }
  256. // ServiceCreateResponse contains the information returned to a client
  257. // on the creation of a new service.
  258. type ServiceCreateResponse struct {
  259. // ID is the ID of the created service.
  260. ID string
  261. // Warnings is a set of non-fatal warning messages to pass on to the user.
  262. Warnings []string `json:",omitempty"`
  263. }
  264. // Values for RegistryAuthFrom in ServiceUpdateOptions
  265. const (
  266. RegistryAuthFromSpec = "spec"
  267. RegistryAuthFromPreviousSpec = "previous-spec"
  268. )
  269. // ServiceUpdateOptions contains the options to be used for updating services.
  270. type ServiceUpdateOptions struct {
  271. // EncodedRegistryAuth is the encoded registry authorization credentials to
  272. // use when updating the service.
  273. //
  274. // This field follows the format of the X-Registry-Auth header.
  275. EncodedRegistryAuth string
  276. // TODO(stevvooe): Consider moving the version parameter of ServiceUpdate
  277. // into this field. While it does open API users up to racy writes, most
  278. // users may not need that level of consistency in practice.
  279. // RegistryAuthFrom specifies where to find the registry authorization
  280. // credentials if they are not given in EncodedRegistryAuth. Valid
  281. // values are "spec" and "previous-spec".
  282. RegistryAuthFrom string
  283. // Rollback indicates whether a server-side rollback should be
  284. // performed. When this is set, the provided spec will be ignored.
  285. // The valid values are "previous" and "none". An empty value is the
  286. // same as "none".
  287. Rollback string
  288. // QueryRegistry indicates whether the service update requires
  289. // contacting a registry. A registry may be contacted to retrieve
  290. // the image digest and manifest, which in turn can be used to update
  291. // platform or other information about the service.
  292. QueryRegistry bool
  293. }
  294. // ServiceListOptions holds parameters to list services with.
  295. type ServiceListOptions struct {
  296. Filters filters.Args
  297. }
  298. // ServiceInspectOptions holds parameters related to the "service inspect"
  299. // operation.
  300. type ServiceInspectOptions struct {
  301. InsertDefaults bool
  302. }
  303. // TaskListOptions holds parameters to list tasks with.
  304. type TaskListOptions struct {
  305. Filters filters.Args
  306. }
  307. // PluginRemoveOptions holds parameters to remove plugins.
  308. type PluginRemoveOptions struct {
  309. Force bool
  310. }
  311. // PluginEnableOptions holds parameters to enable plugins.
  312. type PluginEnableOptions struct {
  313. Timeout int
  314. }
  315. // PluginDisableOptions holds parameters to disable plugins.
  316. type PluginDisableOptions struct {
  317. Force bool
  318. }
  319. // PluginInstallOptions holds parameters to install a plugin.
  320. type PluginInstallOptions struct {
  321. Disabled bool
  322. AcceptAllPermissions bool
  323. RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry
  324. RemoteRef string // RemoteRef is the plugin name on the registry
  325. PrivilegeFunc RequestPrivilegeFunc
  326. AcceptPermissionsFunc func(PluginPrivileges) (bool, error)
  327. Args []string
  328. }
  329. // SwarmUnlockKeyResponse contains the response for Engine API:
  330. // GET /swarm/unlockkey
  331. type SwarmUnlockKeyResponse struct {
  332. // UnlockKey is the unlock key in ASCII-armored format.
  333. UnlockKey string
  334. }
  335. // PluginCreateOptions hold all options to plugin create.
  336. type PluginCreateOptions struct {
  337. RepoName string
  338. }