client.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. package types
  2. import (
  3. "bufio"
  4. "io"
  5. "net"
  6. "os"
  7. "github.com/docker/docker/api/types/container"
  8. "github.com/docker/docker/api/types/filters"
  9. "github.com/docker/go-units"
  10. )
  11. // CheckpointCreateOptions holds parameters to create a checkpoint from a container
  12. type CheckpointCreateOptions struct {
  13. CheckpointID string
  14. CheckpointDir string
  15. Exit bool
  16. }
  17. // CheckpointListOptions holds parameters to list checkpoints for a container
  18. type CheckpointListOptions struct {
  19. CheckpointDir string
  20. }
  21. // CheckpointDeleteOptions holds parameters to delete a checkpoint from a container
  22. type CheckpointDeleteOptions struct {
  23. CheckpointID string
  24. CheckpointDir string
  25. }
  26. // ContainerAttachOptions holds parameters to attach to a container.
  27. type ContainerAttachOptions struct {
  28. Stream bool
  29. Stdin bool
  30. Stdout bool
  31. Stderr bool
  32. DetachKeys string
  33. Logs bool
  34. }
  35. // ContainerCommitOptions holds parameters to commit changes into a container.
  36. type ContainerCommitOptions struct {
  37. Reference string
  38. Comment string
  39. Author string
  40. Changes []string
  41. Pause bool
  42. Config *container.Config
  43. }
  44. // ContainerExecInspect holds information returned by exec inspect.
  45. type ContainerExecInspect struct {
  46. ExecID string
  47. ContainerID string
  48. Running bool
  49. ExitCode int
  50. Pid int
  51. }
  52. // ContainerListOptions holds parameters to list containers with.
  53. type ContainerListOptions struct {
  54. Quiet bool
  55. Size bool
  56. All bool
  57. Latest bool
  58. Since string
  59. Before string
  60. Limit int
  61. Filters filters.Args
  62. }
  63. // ContainerLogsOptions holds parameters to filter logs with.
  64. type ContainerLogsOptions struct {
  65. ShowStdout bool
  66. ShowStderr bool
  67. Since 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. }
  89. // EventsOptions holds parameters to filter events with.
  90. type EventsOptions struct {
  91. Since string
  92. Until string
  93. Filters filters.Args
  94. }
  95. // NetworkListOptions holds parameters to filter the list of networks with.
  96. type NetworkListOptions struct {
  97. Filters filters.Args
  98. }
  99. // HijackedResponse holds connection information for a hijacked request.
  100. type HijackedResponse struct {
  101. Conn net.Conn
  102. Reader *bufio.Reader
  103. }
  104. // Close closes the hijacked connection and reader.
  105. func (h *HijackedResponse) Close() {
  106. h.Conn.Close()
  107. }
  108. // CloseWriter is an interface that implements structs
  109. // that close input streams to prevent from writing.
  110. type CloseWriter interface {
  111. CloseWrite() error
  112. }
  113. // CloseWrite closes a readWriter for writing.
  114. func (h *HijackedResponse) CloseWrite() error {
  115. if conn, ok := h.Conn.(CloseWriter); ok {
  116. return conn.CloseWrite()
  117. }
  118. return nil
  119. }
  120. // ImageBuildOptions holds the information
  121. // necessary to build images.
  122. type ImageBuildOptions struct {
  123. Tags []string
  124. SuppressOutput bool
  125. RemoteContext string
  126. NoCache bool
  127. Remove bool
  128. ForceRemove bool
  129. PullParent bool
  130. Isolation container.Isolation
  131. CPUSetCPUs string
  132. CPUSetMems string
  133. CPUShares int64
  134. CPUQuota int64
  135. CPUPeriod int64
  136. Memory int64
  137. MemorySwap int64
  138. CgroupParent string
  139. NetworkMode string
  140. ShmSize int64
  141. Dockerfile string
  142. Ulimits []*units.Ulimit
  143. // See the parsing of buildArgs in api/server/router/build/build_routes.go
  144. // for an explaination of why BuildArgs needs to use *string instead of
  145. // just a string
  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. }
  159. // ImageBuildResponse holds information
  160. // returned by a server after building
  161. // an image.
  162. type ImageBuildResponse struct {
  163. Body io.ReadCloser
  164. OSType string
  165. }
  166. // ImageCreateOptions holds information to create images.
  167. type ImageCreateOptions struct {
  168. RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry
  169. }
  170. // ImageImportSource holds source information for ImageImport
  171. type ImageImportSource struct {
  172. Source io.Reader // Source is the data to send to the server to create this image from (mutually exclusive with SourceName)
  173. SourceName string // SourceName is the name of the image to pull (mutually exclusive with Source)
  174. }
  175. // ImageImportOptions holds information to import images from the client host.
  176. type ImageImportOptions struct {
  177. Tag string // Tag is the name to tag this image with. This attribute is deprecated.
  178. Message string // Message is the message to tag the image with
  179. Changes []string // Changes are the raw changes to apply to this image
  180. }
  181. // ImageListOptions holds parameters to filter the list of images with.
  182. type ImageListOptions struct {
  183. All bool
  184. Filters filters.Args
  185. }
  186. // ImageLoadResponse returns information to the client about a load process.
  187. type ImageLoadResponse struct {
  188. // Body must be closed to avoid a resource leak
  189. Body io.ReadCloser
  190. JSON bool
  191. }
  192. // ImagePullOptions holds information to pull images.
  193. type ImagePullOptions struct {
  194. All bool
  195. RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry
  196. PrivilegeFunc RequestPrivilegeFunc
  197. }
  198. // RequestPrivilegeFunc is a function interface that
  199. // clients can supply to retry operations after
  200. // getting an authorization error.
  201. // This function returns the registry authentication
  202. // header value in base 64 format, or an error
  203. // if the privilege request fails.
  204. type RequestPrivilegeFunc func() (string, error)
  205. //ImagePushOptions holds information to push images.
  206. type ImagePushOptions ImagePullOptions
  207. // ImageRemoveOptions holds parameters to remove images.
  208. type ImageRemoveOptions struct {
  209. Force bool
  210. PruneChildren bool
  211. }
  212. // ImageSearchOptions holds parameters to search images with.
  213. type ImageSearchOptions struct {
  214. RegistryAuth string
  215. PrivilegeFunc RequestPrivilegeFunc
  216. Filters filters.Args
  217. Limit int
  218. }
  219. // ResizeOptions holds parameters to resize a tty.
  220. // It can be used to resize container ttys and
  221. // exec process ttys too.
  222. type ResizeOptions struct {
  223. Height uint
  224. Width uint
  225. }
  226. // VersionResponse holds version information for the client and the server
  227. type VersionResponse struct {
  228. Client *Version
  229. Server *Version
  230. }
  231. // ServerOK returns true when the client could connect to the docker server
  232. // and parse the information received. It returns false otherwise.
  233. func (v VersionResponse) ServerOK() bool {
  234. return v.Server != nil
  235. }
  236. // NodeListOptions holds parameters to list nodes with.
  237. type NodeListOptions struct {
  238. Filters filters.Args
  239. }
  240. // NodeRemoveOptions holds parameters to remove nodes with.
  241. type NodeRemoveOptions struct {
  242. Force bool
  243. }
  244. // ServiceCreateOptions contains the options to use when creating a service.
  245. type ServiceCreateOptions struct {
  246. // EncodedRegistryAuth is the encoded registry authorization credentials to
  247. // use when updating the service.
  248. //
  249. // This field follows the format of the X-Registry-Auth header.
  250. EncodedRegistryAuth string
  251. }
  252. // ServiceCreateResponse contains the information returned to a client
  253. // on the creation of a new service.
  254. type ServiceCreateResponse struct {
  255. // ID is the ID of the created service.
  256. ID string
  257. // Warnings is a set of non-fatal warning messages to pass on to the user.
  258. Warnings []string `json:",omitempty"`
  259. }
  260. // Values for RegistryAuthFrom in ServiceUpdateOptions
  261. const (
  262. RegistryAuthFromSpec = "spec"
  263. RegistryAuthFromPreviousSpec = "previous-spec"
  264. )
  265. // ServiceUpdateOptions contains the options to be used for updating services.
  266. type ServiceUpdateOptions struct {
  267. // EncodedRegistryAuth is the encoded registry authorization credentials to
  268. // use when updating the service.
  269. //
  270. // This field follows the format of the X-Registry-Auth header.
  271. EncodedRegistryAuth string
  272. // TODO(stevvooe): Consider moving the version parameter of ServiceUpdate
  273. // into this field. While it does open API users up to racy writes, most
  274. // users may not need that level of consistency in practice.
  275. // RegistryAuthFrom specifies where to find the registry authorization
  276. // credentials if they are not given in EncodedRegistryAuth. Valid
  277. // values are "spec" and "previous-spec".
  278. RegistryAuthFrom string
  279. }
  280. // ServiceListOptions holds parameters to list services with.
  281. type ServiceListOptions struct {
  282. Filters filters.Args
  283. }
  284. // TaskListOptions holds parameters to list tasks with.
  285. type TaskListOptions struct {
  286. Filters filters.Args
  287. }
  288. // PluginRemoveOptions holds parameters to remove plugins.
  289. type PluginRemoveOptions struct {
  290. Force bool
  291. }
  292. // PluginEnableOptions holds parameters to enable plugins.
  293. type PluginEnableOptions struct {
  294. Timeout int
  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. PrivilegeFunc RequestPrivilegeFunc
  302. AcceptPermissionsFunc func(PluginPrivileges) (bool, error)
  303. Args []string
  304. }
  305. // SecretRequestOption is a type for requesting secrets
  306. type SecretRequestOption struct {
  307. Source string
  308. Target string
  309. UID string
  310. GID string
  311. Mode os.FileMode
  312. }
  313. // SwarmUnlockKeyResponse contains the response for Engine API:
  314. // GET /swarm/unlockkey
  315. type SwarmUnlockKeyResponse struct {
  316. // UnlockKey is the unlock key in ASCII-armored format.
  317. UnlockKey string
  318. }
  319. // PluginCreateOptions hold all options to plugin create.
  320. type PluginCreateOptions struct {
  321. RepoName string
  322. }