types.go 17 KB

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