misc.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // Copyright 2015 go-dockerclient authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package docker
  5. import (
  6. "encoding/json"
  7. "strings"
  8. )
  9. // Version returns version information about the docker server.
  10. //
  11. // See https://goo.gl/ND9R8L for more details.
  12. func (c *Client) Version() (*Env, error) {
  13. resp, err := c.do("GET", "/version", doOptions{})
  14. if err != nil {
  15. return nil, err
  16. }
  17. defer resp.Body.Close()
  18. var env Env
  19. if err := env.Decode(resp.Body); err != nil {
  20. return nil, err
  21. }
  22. return &env, nil
  23. }
  24. // DockerInfo contains information about the Docker server
  25. //
  26. // See https://goo.gl/bHUoz9 for more details.
  27. type DockerInfo struct {
  28. ID string
  29. Containers int
  30. ContainersRunning int
  31. ContainersPaused int
  32. ContainersStopped int
  33. Images int
  34. Driver string
  35. DriverStatus [][2]string
  36. SystemStatus [][2]string
  37. Plugins PluginsInfo
  38. MemoryLimit bool
  39. SwapLimit bool
  40. KernelMemory bool
  41. CPUCfsPeriod bool `json:"CpuCfsPeriod"`
  42. CPUCfsQuota bool `json:"CpuCfsQuota"`
  43. CPUShares bool
  44. CPUSet bool
  45. IPv4Forwarding bool
  46. BridgeNfIptables bool
  47. BridgeNfIP6tables bool `json:"BridgeNfIp6tables"`
  48. Debug bool
  49. NFd int
  50. OomKillDisable bool
  51. NGoroutines int
  52. SystemTime string
  53. ExecutionDriver string
  54. LoggingDriver string
  55. CgroupDriver string
  56. NEventsListener int
  57. KernelVersion string
  58. OperatingSystem string
  59. OSType string
  60. Architecture string
  61. IndexServerAddress string
  62. NCPU int
  63. MemTotal int64
  64. DockerRootDir string
  65. HTTPProxy string `json:"HttpProxy"`
  66. HTTPSProxy string `json:"HttpsProxy"`
  67. NoProxy string
  68. Name string
  69. Labels []string
  70. ExperimentalBuild bool
  71. ServerVersion string
  72. ClusterStore string
  73. ClusterAdvertise string
  74. }
  75. // PluginsInfo is a struct with the plugins registered with the docker daemon
  76. //
  77. // for more information, see: https://goo.gl/bHUoz9
  78. type PluginsInfo struct {
  79. // List of Volume plugins registered
  80. Volume []string
  81. // List of Network plugins registered
  82. Network []string
  83. // List of Authorization plugins registered
  84. Authorization []string
  85. }
  86. // Info returns system-wide information about the Docker server.
  87. //
  88. // See https://goo.gl/ElTHi2 for more details.
  89. func (c *Client) Info() (*DockerInfo, error) {
  90. resp, err := c.do("GET", "/info", doOptions{})
  91. if err != nil {
  92. return nil, err
  93. }
  94. defer resp.Body.Close()
  95. var info DockerInfo
  96. if err := json.NewDecoder(resp.Body).Decode(&info); err != nil {
  97. return nil, err
  98. }
  99. return &info, nil
  100. }
  101. // ParseRepositoryTag gets the name of the repository and returns it splitted
  102. // in two parts: the repository and the tag.
  103. //
  104. // Some examples:
  105. //
  106. // localhost.localdomain:5000/samalba/hipache:latest -> localhost.localdomain:5000/samalba/hipache, latest
  107. // localhost.localdomain:5000/samalba/hipache -> localhost.localdomain:5000/samalba/hipache, ""
  108. func ParseRepositoryTag(repoTag string) (repository string, tag string) {
  109. n := strings.LastIndex(repoTag, ":")
  110. if n < 0 {
  111. return repoTag, ""
  112. }
  113. if tag := repoTag[n+1:]; !strings.Contains(tag, "/") {
  114. return repoTag[:n], tag
  115. }
  116. return repoTag, ""
  117. }