types.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  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. GitCommit string
  123. GoVersion string
  124. Os string
  125. Arch string
  126. KernelVersion string `json:",omitempty"`
  127. Experimental bool `json:",omitempty"`
  128. BuildTime string `json:",omitempty"`
  129. }
  130. // Info contains response of Remote API:
  131. // GET "/info"
  132. type Info struct {
  133. ID string
  134. Containers int
  135. ContainersRunning int
  136. ContainersPaused int
  137. ContainersStopped int
  138. Images int
  139. Driver string
  140. DriverStatus [][2]string
  141. SystemStatus [][2]string
  142. Plugins PluginsInfo
  143. MemoryLimit bool
  144. SwapLimit bool
  145. KernelMemory bool
  146. CPUCfsPeriod bool `json:"CpuCfsPeriod"`
  147. CPUCfsQuota bool `json:"CpuCfsQuota"`
  148. CPUShares bool
  149. CPUSet bool
  150. IPv4Forwarding bool
  151. BridgeNfIptables bool
  152. BridgeNfIP6tables bool `json:"BridgeNfIp6tables"`
  153. Debug bool
  154. NFd int
  155. OomKillDisable bool
  156. NGoroutines int
  157. SystemTime string
  158. LoggingDriver string
  159. CgroupDriver string
  160. NEventsListener int
  161. KernelVersion string
  162. OperatingSystem string
  163. OSType string
  164. Architecture string
  165. IndexServerAddress string
  166. RegistryConfig *registry.ServiceConfig
  167. NCPU int
  168. MemTotal int64
  169. DockerRootDir string
  170. HTTPProxy string `json:"HttpProxy"`
  171. HTTPSProxy string `json:"HttpsProxy"`
  172. NoProxy string
  173. Name string
  174. Labels []string
  175. ExperimentalBuild bool
  176. ServerVersion string
  177. ClusterStore string
  178. ClusterAdvertise string
  179. SecurityOptions []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. // PluginsInfo is a temp struct holding Plugins name
  190. // registered with docker daemon. It is used by Info struct
  191. type PluginsInfo struct {
  192. // List of Volume plugins registered
  193. Volume []string
  194. // List of Network plugins registered
  195. Network []string
  196. // List of Authorization plugins registered
  197. Authorization []string
  198. }
  199. // ExecStartCheck is a temp struct used by execStart
  200. // Config fields is part of ExecConfig in runconfig package
  201. type ExecStartCheck struct {
  202. // ExecStart will first check if it's detached
  203. Detach bool
  204. // Check if there's a tty
  205. Tty bool
  206. }
  207. // HealthcheckResult stores information about a single run of a healthcheck probe
  208. type HealthcheckResult struct {
  209. Start time.Time // Start is the time this check started
  210. End time.Time // End is the time this check ended
  211. ExitCode int // ExitCode meanings: 0=healthy, 1=unhealthy, 2=reserved (considered unhealthy), else=error running probe
  212. Output string // Output from last check
  213. }
  214. // Health states
  215. const (
  216. NoHealthcheck = "none" // Indicates there is no healthcheck
  217. Starting = "starting" // Starting indicates that the container is not yet ready
  218. Healthy = "healthy" // Healthy indicates that the container is running correctly
  219. Unhealthy = "unhealthy" // Unhealthy indicates that the container has a problem
  220. )
  221. // Health stores information about the container's healthcheck results
  222. type Health struct {
  223. Status string // Status is one of Starting, Healthy or Unhealthy
  224. FailingStreak int // FailingStreak is the number of consecutive failures
  225. Log []*HealthcheckResult // Log contains the last few results (oldest first)
  226. }
  227. // ContainerState stores container's running state
  228. // it's part of ContainerJSONBase and will return by "inspect" command
  229. type ContainerState struct {
  230. Status string
  231. Running bool
  232. Paused bool
  233. Restarting bool
  234. OOMKilled bool
  235. Dead bool
  236. Pid int
  237. ExitCode int
  238. Error string
  239. StartedAt string
  240. FinishedAt string
  241. Health *Health `json:",omitempty"`
  242. }
  243. // ContainerNode stores information about the node that a container
  244. // is running on. It's only available in Docker Swarm
  245. type ContainerNode struct {
  246. ID string
  247. IPAddress string `json:"IP"`
  248. Addr string
  249. Name string
  250. Cpus int
  251. Memory int64
  252. Labels map[string]string
  253. }
  254. // ContainerJSONBase contains response of Remote API:
  255. // GET "/containers/{name:.*}/json"
  256. type ContainerJSONBase struct {
  257. ID string `json:"Id"`
  258. Created string
  259. Path string
  260. Args []string
  261. State *ContainerState
  262. Image string
  263. ResolvConfPath string
  264. HostnamePath string
  265. HostsPath string
  266. LogPath string
  267. Node *ContainerNode `json:",omitempty"`
  268. Name string
  269. RestartCount int
  270. Driver string
  271. MountLabel string
  272. ProcessLabel string
  273. AppArmorProfile string
  274. ExecIDs []string
  275. HostConfig *container.HostConfig
  276. GraphDriver GraphDriverData
  277. SizeRw *int64 `json:",omitempty"`
  278. SizeRootFs *int64 `json:",omitempty"`
  279. }
  280. // ContainerJSON is newly used struct along with MountPoint
  281. type ContainerJSON struct {
  282. *ContainerJSONBase
  283. Mounts []MountPoint
  284. Config *container.Config
  285. NetworkSettings *NetworkSettings
  286. }
  287. // NetworkSettings exposes the network settings in the api
  288. type NetworkSettings struct {
  289. NetworkSettingsBase
  290. DefaultNetworkSettings
  291. Networks map[string]*network.EndpointSettings
  292. }
  293. // SummaryNetworkSettings provides a summary of container's networks
  294. // in /containers/json
  295. type SummaryNetworkSettings struct {
  296. Networks map[string]*network.EndpointSettings
  297. }
  298. // NetworkSettingsBase holds basic information about networks
  299. type NetworkSettingsBase struct {
  300. Bridge string // Bridge is the Bridge name the network uses(e.g. `docker0`)
  301. SandboxID string // SandboxID uniquely represents a container's network stack
  302. HairpinMode bool // HairpinMode specifies if hairpin NAT should be enabled on the virtual interface
  303. LinkLocalIPv6Address string // LinkLocalIPv6Address is an IPv6 unicast address using the link-local prefix
  304. LinkLocalIPv6PrefixLen int // LinkLocalIPv6PrefixLen is the prefix length of an IPv6 unicast address
  305. Ports nat.PortMap // Ports is a collection of PortBinding indexed by Port
  306. SandboxKey string // SandboxKey identifies the sandbox
  307. SecondaryIPAddresses []network.Address
  308. SecondaryIPv6Addresses []network.Address
  309. }
  310. // DefaultNetworkSettings holds network information
  311. // during the 2 release deprecation period.
  312. // It will be removed in Docker 1.11.
  313. type DefaultNetworkSettings struct {
  314. EndpointID string // EndpointID uniquely represents a service endpoint in a Sandbox
  315. Gateway string // Gateway holds the gateway address for the network
  316. GlobalIPv6Address string // GlobalIPv6Address holds network's global IPv6 address
  317. GlobalIPv6PrefixLen int // GlobalIPv6PrefixLen represents mask length of network's global IPv6 address
  318. IPAddress string // IPAddress holds the IPv4 address for the network
  319. IPPrefixLen int // IPPrefixLen represents mask length of network's IPv4 address
  320. IPv6Gateway string // IPv6Gateway holds gateway address specific for IPv6
  321. MacAddress string // MacAddress holds the MAC address for the network
  322. }
  323. // MountPoint represents a mount point configuration inside the container.
  324. // This is used for reporting the mountpoints in use by a container.
  325. type MountPoint struct {
  326. Type mount.Type `json:",omitempty"`
  327. Name string `json:",omitempty"`
  328. Source string
  329. Destination string
  330. Driver string `json:",omitempty"`
  331. Mode string
  332. RW bool
  333. Propagation mount.Propagation
  334. }
  335. // NetworkResource is the body of the "get network" http response message
  336. type NetworkResource struct {
  337. Name string // Name is the requested name of the network
  338. ID string `json:"Id"` // ID uniquely identifies a network on a single machine
  339. Created time.Time // Created is the time the network created
  340. Scope string // Scope describes the level at which the network exists (e.g. `global` for cluster-wide or `local` for machine level)
  341. Driver string // Driver is the Driver name used to create the network (e.g. `bridge`, `overlay`)
  342. EnableIPv6 bool // EnableIPv6 represents whether to enable IPv6
  343. IPAM network.IPAM // IPAM is the network's IP Address Management
  344. Internal bool // Internal represents if the network is used internal only
  345. Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode.
  346. Containers map[string]EndpointResource // Containers contains endpoints belonging to the network
  347. Options map[string]string // Options holds the network specific options to use for when creating the network
  348. Labels map[string]string // Labels holds metadata specific to the network being created
  349. }
  350. // EndpointResource contains network resources allocated and used for a container in a network
  351. type EndpointResource struct {
  352. Name string
  353. EndpointID string
  354. MacAddress string
  355. IPv4Address string
  356. IPv6Address string
  357. }
  358. // NetworkCreate is the expected body of the "create network" http request message
  359. type NetworkCreate struct {
  360. CheckDuplicate bool
  361. Driver string
  362. EnableIPv6 bool
  363. IPAM *network.IPAM
  364. Internal bool
  365. Attachable bool
  366. Options map[string]string
  367. Labels map[string]string
  368. }
  369. // NetworkCreateRequest is the request message sent to the server for network create call.
  370. type NetworkCreateRequest struct {
  371. NetworkCreate
  372. Name string
  373. }
  374. // NetworkCreateResponse is the response message sent by the server for network create call
  375. type NetworkCreateResponse struct {
  376. ID string `json:"Id"`
  377. Warning string
  378. }
  379. // NetworkConnect represents the data to be used to connect a container to the network
  380. type NetworkConnect struct {
  381. Container string
  382. EndpointConfig *network.EndpointSettings `json:",omitempty"`
  383. }
  384. // NetworkDisconnect represents the data to be used to disconnect a container from the network
  385. type NetworkDisconnect struct {
  386. Container string
  387. Force bool
  388. }
  389. // Checkpoint represents the details of a checkpoint
  390. type Checkpoint struct {
  391. Name string // Name is the name of the checkpoint
  392. }
  393. // Runtime describes an OCI runtime
  394. type Runtime struct {
  395. Path string `json:"path"`
  396. Args []string `json:"runtimeArgs,omitempty"`
  397. }
  398. // DiskUsage contains response of Remote API:
  399. // GET "/system/df"
  400. type DiskUsage struct {
  401. LayersSize int64
  402. Images []*ImageSummary
  403. Containers []*Container
  404. Volumes []*Volume
  405. }
  406. // ImagesPruneConfig contains the configuration for Remote API:
  407. // POST "/images/prune"
  408. type ImagesPruneConfig struct {
  409. DanglingOnly bool
  410. }
  411. // ContainersPruneConfig contains the configuration for Remote API:
  412. // POST "/images/prune"
  413. type ContainersPruneConfig struct {
  414. }
  415. // VolumesPruneConfig contains the configuration for Remote API:
  416. // POST "/images/prune"
  417. type VolumesPruneConfig struct {
  418. }
  419. // NetworksPruneConfig contains the configuration for Remote API:
  420. // POST "/networks/prune"
  421. type NetworksPruneConfig struct {
  422. }
  423. // ContainersPruneReport contains the response for Remote API:
  424. // POST "/containers/prune"
  425. type ContainersPruneReport struct {
  426. ContainersDeleted []string
  427. SpaceReclaimed uint64
  428. }
  429. // VolumesPruneReport contains the response for Remote API:
  430. // POST "/volumes/prune"
  431. type VolumesPruneReport struct {
  432. VolumesDeleted []string
  433. SpaceReclaimed uint64
  434. }
  435. // ImagesPruneReport contains the response for Remote API:
  436. // POST "/images/prune"
  437. type ImagesPruneReport struct {
  438. ImagesDeleted []ImageDelete
  439. SpaceReclaimed uint64
  440. }
  441. // NetworksPruneReport contains the response for Remote API:
  442. // POST "/networks/prune"
  443. type NetworksPruneReport struct {
  444. NetworksDeleted []string
  445. }