client.go 10 KB

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