types.go 15 KB

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