types.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. package types
  2. import (
  3. "io"
  4. "os"
  5. "time"
  6. "github.com/docker/docker/api/types/container"
  7. "github.com/docker/docker/api/types/mount"
  8. "github.com/docker/docker/api/types/network"
  9. "github.com/docker/docker/api/types/registry"
  10. "github.com/docker/docker/api/types/swarm"
  11. "github.com/docker/go-connections/nat"
  12. )
  13. // ContainerChange contains response of Remote API:
  14. // GET "/containers/{name:.*}/changes"
  15. type ContainerChange struct {
  16. Kind int
  17. Path string
  18. }
  19. // ImageHistory contains response of Remote API:
  20. // GET "/images/{name:.*}/history"
  21. type ImageHistory struct {
  22. ID string `json:"Id"`
  23. Created int64
  24. CreatedBy string
  25. Tags []string
  26. Size int64
  27. Comment string
  28. }
  29. // ImageDelete contains response of Remote API:
  30. // DELETE "/images/{name:.*}"
  31. type ImageDelete struct {
  32. Untagged string `json:",omitempty"`
  33. Deleted string `json:",omitempty"`
  34. }
  35. // GraphDriverData returns Image's graph driver config info
  36. // when calling inspect command
  37. type GraphDriverData struct {
  38. Name string
  39. Data map[string]string
  40. }
  41. // RootFS returns Image's RootFS description including the layer IDs.
  42. type RootFS struct {
  43. Type string
  44. Layers []string `json:",omitempty"`
  45. BaseLayer string `json:",omitempty"`
  46. }
  47. // ImageInspect contains response of Remote API:
  48. // GET "/images/{name:.*}/json"
  49. type ImageInspect struct {
  50. ID string `json:"Id"`
  51. RepoTags []string
  52. RepoDigests []string
  53. Parent string
  54. Comment string
  55. Created string
  56. Container string
  57. ContainerConfig *container.Config
  58. DockerVersion string
  59. Author string
  60. Config *container.Config
  61. Architecture string
  62. Os string
  63. OsVersion string `json:",omitempty"`
  64. Size int64
  65. VirtualSize int64
  66. GraphDriver GraphDriverData
  67. RootFS RootFS
  68. }
  69. // Container contains response of Remote API:
  70. // GET "/containers/json"
  71. type Container struct {
  72. ID string `json:"Id"`
  73. Names []string
  74. Image string
  75. ImageID string
  76. Command string
  77. Created int64
  78. Ports []Port
  79. SizeRw int64 `json:",omitempty"`
  80. SizeRootFs int64 `json:",omitempty"`
  81. Labels map[string]string
  82. State string
  83. Status string
  84. HostConfig struct {
  85. NetworkMode string `json:",omitempty"`
  86. }
  87. NetworkSettings *SummaryNetworkSettings
  88. Mounts []MountPoint
  89. }
  90. // CopyConfig contains request body of Remote API:
  91. // POST "/containers/"+containerID+"/copy"
  92. type CopyConfig struct {
  93. Resource string
  94. }
  95. // ContainerPathStat is used to encode the header from
  96. // GET "/containers/{name:.*}/archive"
  97. // "Name" is the file or directory name.
  98. type ContainerPathStat struct {
  99. Name string `json:"name"`
  100. Size int64 `json:"size"`
  101. Mode os.FileMode `json:"mode"`
  102. Mtime time.Time `json:"mtime"`
  103. LinkTarget string `json:"linkTarget"`
  104. }
  105. // ContainerStats contains response of Remote API:
  106. // GET "/stats"
  107. type ContainerStats struct {
  108. Body io.ReadCloser `json:"body"`
  109. OSType string `json:"ostype"`
  110. }
  111. // ContainerProcessList contains response of Remote API:
  112. // GET "/containers/{name:.*}/top"
  113. type ContainerProcessList struct {
  114. Processes [][]string
  115. Titles []string
  116. }
  117. // Version contains response of Remote API:
  118. // GET "/version"
  119. type Version struct {
  120. Version string
  121. APIVersion string `json:"ApiVersion"`
  122. MinAPIVersion string `json:"MinAPIVersion,omitempty"`
  123. GitCommit string
  124. GoVersion string
  125. Os string
  126. Arch string
  127. KernelVersion string `json:",omitempty"`
  128. Experimental bool `json:",omitempty"`
  129. BuildTime string `json:",omitempty"`
  130. }
  131. // InfoBase contains the base response of Remote API:
  132. // GET "/info"
  133. type InfoBase struct {
  134. ID string
  135. Containers int
  136. ContainersRunning int
  137. ContainersPaused int
  138. ContainersStopped int
  139. Images int
  140. Driver string
  141. DriverStatus [][2]string
  142. SystemStatus [][2]string
  143. Plugins PluginsInfo
  144. MemoryLimit bool
  145. SwapLimit bool
  146. KernelMemory bool
  147. CPUCfsPeriod bool `json:"CpuCfsPeriod"`
  148. CPUCfsQuota bool `json:"CpuCfsQuota"`
  149. CPUShares bool
  150. CPUSet bool
  151. IPv4Forwarding bool
  152. BridgeNfIptables bool
  153. BridgeNfIP6tables bool `json:"BridgeNfIp6tables"`
  154. Debug bool
  155. NFd int
  156. OomKillDisable bool
  157. NGoroutines int
  158. SystemTime string
  159. LoggingDriver string
  160. CgroupDriver string
  161. NEventsListener int
  162. KernelVersion string
  163. OperatingSystem string
  164. OSType string
  165. Architecture string
  166. IndexServerAddress string
  167. RegistryConfig *registry.ServiceConfig
  168. NCPU int
  169. MemTotal int64
  170. DockerRootDir string
  171. HTTPProxy string `json:"HttpProxy"`
  172. HTTPSProxy string `json:"HttpsProxy"`
  173. NoProxy string
  174. Name string
  175. Labels []string
  176. ExperimentalBuild bool
  177. ServerVersion string
  178. ClusterStore string
  179. ClusterAdvertise string
  180. Runtimes map[string]Runtime
  181. DefaultRuntime string
  182. Swarm swarm.Info
  183. // LiveRestoreEnabled determines whether containers should be kept
  184. // running when the daemon is shutdown or upon daemon start if
  185. // running containers are detected
  186. LiveRestoreEnabled bool
  187. Isolation container.Isolation
  188. }
  189. // SecurityOpt holds key/value pair about a security option
  190. type SecurityOpt struct {
  191. Key, Value string
  192. }
  193. // Info contains response of Remote API:
  194. // GET "/info"
  195. type Info struct {
  196. *InfoBase
  197. SecurityOptions []SecurityOpt
  198. }
  199. // PluginsInfo is a temp struct holding Plugins name
  200. // registered with docker daemon. It is used by Info struct
  201. type PluginsInfo struct {
  202. // List of Volume plugins registered
  203. Volume []string
  204. // List of Network plugins registered
  205. Network []string
  206. // List of Authorization plugins registered
  207. Authorization []string
  208. }
  209. // ExecStartCheck is a temp struct used by execStart
  210. // Config fields is part of ExecConfig in runconfig package
  211. type ExecStartCheck struct {
  212. // ExecStart will first check if it's detached
  213. Detach bool
  214. // Check if there's a tty
  215. Tty bool
  216. }
  217. // HealthcheckResult stores information about a single run of a healthcheck probe
  218. type HealthcheckResult struct {
  219. Start time.Time // Start is the time this check started
  220. End time.Time // End is the time this check ended
  221. ExitCode int // ExitCode meanings: 0=healthy, 1=unhealthy, 2=reserved (considered unhealthy), else=error running probe
  222. Output string // Output from last check
  223. }
  224. // Health states
  225. const (
  226. NoHealthcheck = "none" // Indicates there is no healthcheck
  227. Starting = "starting" // Starting indicates that the container is not yet ready
  228. Healthy = "healthy" // Healthy indicates that the container is running correctly
  229. Unhealthy = "unhealthy" // Unhealthy indicates that the container has a problem
  230. )
  231. // Health stores information about the container's healthcheck results
  232. type Health struct {
  233. Status string // Status is one of Starting, Healthy or Unhealthy
  234. FailingStreak int // FailingStreak is the number of consecutive failures
  235. Log []*HealthcheckResult // Log contains the last few results (oldest first)
  236. }
  237. // ContainerState stores container's running state
  238. // it's part of ContainerJSONBase and will return by "inspect" command
  239. type ContainerState struct {
  240. Status string
  241. Running bool
  242. Paused bool
  243. Restarting bool
  244. OOMKilled bool
  245. Dead bool
  246. Pid int
  247. ExitCode int
  248. Error string
  249. StartedAt string
  250. FinishedAt string
  251. Health *Health `json:",omitempty"`
  252. }
  253. // ContainerNode stores information about the node that a container
  254. // is running on. It's only available in Docker Swarm
  255. type ContainerNode struct {
  256. ID string
  257. IPAddress string `json:"IP"`
  258. Addr string
  259. Name string
  260. Cpus int
  261. Memory int64
  262. Labels map[string]string
  263. }
  264. // ContainerJSONBase contains response of Remote API:
  265. // GET "/containers/{name:.*}/json"
  266. type ContainerJSONBase struct {
  267. ID string `json:"Id"`
  268. Created string
  269. Path string
  270. Args []string
  271. State *ContainerState
  272. Image string
  273. ResolvConfPath string
  274. HostnamePath string
  275. HostsPath string
  276. LogPath string
  277. Node *ContainerNode `json:",omitempty"`
  278. Name string
  279. RestartCount int
  280. Driver string
  281. MountLabel string
  282. ProcessLabel string
  283. AppArmorProfile string
  284. ExecIDs []string
  285. HostConfig *container.HostConfig
  286. GraphDriver GraphDriverData
  287. SizeRw *int64 `json:",omitempty"`
  288. SizeRootFs *int64 `json:",omitempty"`
  289. }
  290. // ContainerJSON is newly used struct along with MountPoint
  291. type ContainerJSON struct {
  292. *ContainerJSONBase
  293. Mounts []MountPoint
  294. Config *container.Config
  295. NetworkSettings *NetworkSettings
  296. }
  297. // NetworkSettings exposes the network settings in the api
  298. type NetworkSettings struct {
  299. NetworkSettingsBase
  300. DefaultNetworkSettings
  301. Networks map[string]*network.EndpointSettings
  302. }
  303. // SummaryNetworkSettings provides a summary of container's networks
  304. // in /containers/json
  305. type SummaryNetworkSettings struct {
  306. Networks map[string]*network.EndpointSettings
  307. }
  308. // NetworkSettingsBase holds basic information about networks
  309. type NetworkSettingsBase struct {
  310. Bridge string // Bridge is the Bridge name the network uses(e.g. `docker0`)
  311. SandboxID string // SandboxID uniquely represents a container's network stack
  312. HairpinMode bool // HairpinMode specifies if hairpin NAT should be enabled on the virtual interface
  313. LinkLocalIPv6Address string // LinkLocalIPv6Address is an IPv6 unicast address using the link-local prefix
  314. LinkLocalIPv6PrefixLen int // LinkLocalIPv6PrefixLen is the prefix length of an IPv6 unicast address
  315. Ports nat.PortMap // Ports is a collection of PortBinding indexed by Port
  316. SandboxKey string // SandboxKey identifies the sandbox
  317. SecondaryIPAddresses []network.Address
  318. SecondaryIPv6Addresses []network.Address
  319. }
  320. // DefaultNetworkSettings holds network information
  321. // during the 2 release deprecation period.
  322. // It will be removed in Docker 1.11.
  323. type DefaultNetworkSettings struct {
  324. EndpointID string // EndpointID uniquely represents a service endpoint in a Sandbox
  325. Gateway string // Gateway holds the gateway address for the network
  326. GlobalIPv6Address string // GlobalIPv6Address holds network's global IPv6 address
  327. GlobalIPv6PrefixLen int // GlobalIPv6PrefixLen represents mask length of network's global IPv6 address
  328. IPAddress string // IPAddress holds the IPv4 address for the network
  329. IPPrefixLen int // IPPrefixLen represents mask length of network's IPv4 address
  330. IPv6Gateway string // IPv6Gateway holds gateway address specific for IPv6
  331. MacAddress string // MacAddress holds the MAC address for the network
  332. }
  333. // MountPoint represents a mount point configuration inside the container.
  334. // This is used for reporting the mountpoints in use by a container.
  335. type MountPoint struct {
  336. Type mount.Type `json:",omitempty"`
  337. Name string `json:",omitempty"`
  338. Source string
  339. Destination string
  340. Driver string `json:",omitempty"`
  341. Mode string
  342. RW bool
  343. Propagation mount.Propagation
  344. }
  345. // NetworkResource is the body of the "get network" http response message
  346. type NetworkResource struct {
  347. Name string // Name is the requested name of the network
  348. ID string `json:"Id"` // ID uniquely identifies a network on a single machine
  349. Created time.Time // Created is the time the network created
  350. Scope string // Scope describes the level at which the network exists (e.g. `global` for cluster-wide or `local` for machine level)
  351. Driver string // Driver is the Driver name used to create the network (e.g. `bridge`, `overlay`)
  352. EnableIPv6 bool // EnableIPv6 represents whether to enable IPv6
  353. IPAM network.IPAM // IPAM is the network's IP Address Management
  354. Internal bool // Internal represents if the network is used internal only
  355. Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode.
  356. Containers map[string]EndpointResource // Containers contains endpoints belonging to the network
  357. Options map[string]string // Options holds the network specific options to use for when creating the network
  358. Labels map[string]string // Labels holds metadata specific to the network being created
  359. }
  360. // EndpointResource contains network resources allocated and used for a container in a network
  361. type EndpointResource struct {
  362. Name string
  363. EndpointID string
  364. MacAddress string
  365. IPv4Address string
  366. IPv6Address string
  367. }
  368. // NetworkCreate is the expected body of the "create network" http request message
  369. type NetworkCreate struct {
  370. CheckDuplicate bool
  371. Driver string
  372. EnableIPv6 bool
  373. IPAM *network.IPAM
  374. Internal bool
  375. Attachable bool
  376. Options map[string]string
  377. Labels map[string]string
  378. }
  379. // NetworkCreateRequest is the request message sent to the server for network create call.
  380. type NetworkCreateRequest struct {
  381. NetworkCreate
  382. Name string
  383. }
  384. // NetworkCreateResponse is the response message sent by the server for network create call
  385. type NetworkCreateResponse struct {
  386. ID string `json:"Id"`
  387. Warning string
  388. }
  389. // NetworkConnect represents the data to be used to connect a container to the network
  390. type NetworkConnect struct {
  391. Container string
  392. EndpointConfig *network.EndpointSettings `json:",omitempty"`
  393. }
  394. // NetworkDisconnect represents the data to be used to disconnect a container from the network
  395. type NetworkDisconnect struct {
  396. Container string
  397. Force bool
  398. }
  399. // Checkpoint represents the details of a checkpoint
  400. type Checkpoint struct {
  401. Name string // Name is the name of the checkpoint
  402. }
  403. // Runtime describes an OCI runtime
  404. type Runtime struct {
  405. Path string `json:"path"`
  406. Args []string `json:"runtimeArgs,omitempty"`
  407. }
  408. // DiskUsage contains response of Remote API:
  409. // GET "/system/df"
  410. type DiskUsage struct {
  411. LayersSize int64
  412. Images []*ImageSummary
  413. Containers []*Container
  414. Volumes []*Volume
  415. }
  416. // ImagesPruneConfig contains the configuration for Remote API:
  417. // POST "/images/prune"
  418. type ImagesPruneConfig struct {
  419. DanglingOnly bool
  420. }
  421. // ContainersPruneConfig contains the configuration for Remote API:
  422. // POST "/images/prune"
  423. type ContainersPruneConfig struct {
  424. }
  425. // VolumesPruneConfig contains the configuration for Remote API:
  426. // POST "/images/prune"
  427. type VolumesPruneConfig struct {
  428. }
  429. // NetworksPruneConfig contains the configuration for Remote API:
  430. // POST "/networks/prune"
  431. type NetworksPruneConfig struct {
  432. }
  433. // ContainersPruneReport contains the response for Remote API:
  434. // POST "/containers/prune"
  435. type ContainersPruneReport struct {
  436. ContainersDeleted []string
  437. SpaceReclaimed uint64
  438. }
  439. // VolumesPruneReport contains the response for Remote API:
  440. // POST "/volumes/prune"
  441. type VolumesPruneReport struct {
  442. VolumesDeleted []string
  443. SpaceReclaimed uint64
  444. }
  445. // ImagesPruneReport contains the response for Remote API:
  446. // POST "/images/prune"
  447. type ImagesPruneReport struct {
  448. ImagesDeleted []ImageDelete
  449. SpaceReclaimed uint64
  450. }
  451. // NetworksPruneReport contains the response for Remote API:
  452. // POST "/networks/prune"
  453. type NetworksPruneReport struct {
  454. NetworksDeleted []string
  455. }