Carry#13921 : Expand /info: Expose OSType (GOOS), Architecture (GOARCH)
| ... | ... |
@@ -59,6 +59,8 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
|
| 59 | 59 |
|
| 60 | 60 |
ioutils.FprintfIfNotEmpty(cli.out, "Kernel Version: %s\n", info.KernelVersion) |
| 61 | 61 |
ioutils.FprintfIfNotEmpty(cli.out, "Operating System: %s\n", info.OperatingSystem) |
| 62 |
+ ioutils.FprintfIfNotEmpty(cli.out, "OSType: %s\n", info.OSType) |
|
| 63 |
+ ioutils.FprintfIfNotEmpty(cli.out, "Architecture: %s\n", info.Architecture) |
|
| 62 | 64 |
fmt.Fprintf(cli.out, "CPUs: %d\n", info.NCPU) |
| 63 | 65 |
fmt.Fprintf(cli.out, "Total Memory: %s\n", units.BytesSize(float64(info.MemTotal))) |
| 64 | 66 |
ioutils.FprintfIfNotEmpty(cli.out, "Name: %s\n", info.Name) |
| ... | ... |
@@ -11,6 +11,7 @@ import ( |
| 11 | 11 |
"github.com/docker/docker/pkg/fileutils" |
| 12 | 12 |
"github.com/docker/docker/pkg/parsers/kernel" |
| 13 | 13 |
"github.com/docker/docker/pkg/parsers/operatingsystem" |
| 14 |
+ "github.com/docker/docker/pkg/platform" |
|
| 14 | 15 |
"github.com/docker/docker/pkg/sysinfo" |
| 15 | 16 |
"github.com/docker/docker/pkg/system" |
| 16 | 17 |
"github.com/docker/docker/registry" |
| ... | ... |
@@ -77,6 +78,8 @@ func (daemon *Daemon) SystemInfo() (*types.Info, error) {
|
| 77 | 77 |
KernelVersion: kernelVersion, |
| 78 | 78 |
OperatingSystem: operatingSystem, |
| 79 | 79 |
IndexServerAddress: registry.IndexServer, |
| 80 |
+ OSType: platform.OSType, |
|
| 81 |
+ Architecture: platform.Architecture, |
|
| 80 | 82 |
RegistryConfig: daemon.RegistryService.Config, |
| 81 | 83 |
InitSha1: dockerversion.InitSHA1, |
| 82 | 84 |
InitPath: initPath, |
| ... | ... |
@@ -1884,6 +1884,7 @@ Display system-wide information |
| 1884 | 1884 |
Content-Type: application/json |
| 1885 | 1885 |
|
| 1886 | 1886 |
{
|
| 1887 |
+ "Architecture": "x86_64", |
|
| 1887 | 1888 |
"Containers": 11, |
| 1888 | 1889 |
"CpuCfsPeriod": true, |
| 1889 | 1890 |
"CpuCfsQuota": true, |
| ... | ... |
@@ -1915,6 +1916,7 @@ Display system-wide information |
| 1915 | 1915 |
"Name": "prod-server-42", |
| 1916 | 1916 |
"NoProxy": "9.81.1.160", |
| 1917 | 1917 |
"OomKillDisable": true, |
| 1918 |
+ "OSType": "linux", |
|
| 1918 | 1919 |
"OperatingSystem": "Boot2Docker", |
| 1919 | 1920 |
"RegistryConfig": {
|
| 1920 | 1921 |
"IndexConfigs": {
|
| 50 | 52 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,15 @@ |
| 0 |
+package platform |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "os/exec" |
|
| 4 |
+) |
|
| 5 |
+ |
|
| 6 |
+// GetRuntimeArchitecture get the name of the current architecture (x86, x86_64, …) |
|
| 7 |
+func GetRuntimeArchitecture() (string, error) {
|
|
| 8 |
+ cmd := exec.Command("uname", "-m")
|
|
| 9 |
+ machine, err := cmd.Output() |
|
| 10 |
+ if err != nil {
|
|
| 11 |
+ return "", err |
|
| 12 |
+ } |
|
| 13 |
+ return string(machine), nil |
|
| 14 |
+} |
| 0 | 15 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,28 @@ |
| 0 |
+// Package platform provides helper function to get the runtime architecture |
|
| 1 |
+// for different platforms. |
|
| 2 |
+package platform |
|
| 3 |
+ |
|
| 4 |
+import ( |
|
| 5 |
+ "syscall" |
|
| 6 |
+) |
|
| 7 |
+ |
|
| 8 |
+// GetRuntimeArchitecture get the name of the current architecture (x86, x86_64, …) |
|
| 9 |
+func GetRuntimeArchitecture() (string, error) {
|
|
| 10 |
+ utsname := &syscall.Utsname{}
|
|
| 11 |
+ if err := syscall.Uname(utsname); err != nil {
|
|
| 12 |
+ return "", err |
|
| 13 |
+ } |
|
| 14 |
+ return charsToString(utsname.Machine), nil |
|
| 15 |
+} |
|
| 16 |
+ |
|
| 17 |
+func charsToString(ca [65]int8) string {
|
|
| 18 |
+ s := make([]byte, len(ca)) |
|
| 19 |
+ var lens int |
|
| 20 |
+ for ; lens < len(ca); lens++ {
|
|
| 21 |
+ if ca[lens] == 0 {
|
|
| 22 |
+ break |
|
| 23 |
+ } |
|
| 24 |
+ s[lens] = uint8(ca[lens]) |
|
| 25 |
+ } |
|
| 26 |
+ return string(s[0:lens]) |
|
| 27 |
+} |
| 0 | 28 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,52 @@ |
| 0 |
+package platform |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "fmt" |
|
| 4 |
+ "syscall" |
|
| 5 |
+ "unsafe" |
|
| 6 |
+) |
|
| 7 |
+ |
|
| 8 |
+var ( |
|
| 9 |
+ modkernel32 = syscall.NewLazyDLL("kernel32.dll")
|
|
| 10 |
+ procGetSystemInfo = modkernel32.NewProc("GetSystemInfo")
|
|
| 11 |
+) |
|
| 12 |
+ |
|
| 13 |
+// see http://msdn.microsoft.com/en-us/library/windows/desktop/ms724958(v=vs.85).aspx |
|
| 14 |
+type systeminfo struct {
|
|
| 15 |
+ wProcessorArchitecture uint16 |
|
| 16 |
+ wReserved uint16 |
|
| 17 |
+ dwPageSize uint32 |
|
| 18 |
+ lpMinimumApplicationAddress uintptr |
|
| 19 |
+ lpMaximumApplicationAddress uintptr |
|
| 20 |
+ dwActiveProcessorMask uintptr |
|
| 21 |
+ dwNumberOfProcessors uint32 |
|
| 22 |
+ dwProcessorType uint32 |
|
| 23 |
+ dwAllocationGranularity uint32 |
|
| 24 |
+ wProcessorLevel uint16 |
|
| 25 |
+ wProcessorRevision uint16 |
|
| 26 |
+} |
|
| 27 |
+ |
|
| 28 |
+// Constants |
|
| 29 |
+const ( |
|
| 30 |
+ ProcessorArchitecture64 = 9 // PROCESSOR_ARCHITECTURE_AMD64 |
|
| 31 |
+ ProcessorArchitectureIA64 = 6 // PROCESSOR_ARCHITECTURE_IA64 |
|
| 32 |
+ ProcessorArchitecture32 = 0 // PROCESSOR_ARCHITECTURE_INTEL |
|
| 33 |
+ ProcessorArchitectureArm = 5 // PROCESSOR_ARCHITECTURE_ARM |
|
| 34 |
+) |
|
| 35 |
+ |
|
| 36 |
+var sysinfo systeminfo |
|
| 37 |
+ |
|
| 38 |
+// GetRuntimeArchitecture get the name of the current architecture (x86, x86_64, …) |
|
| 39 |
+func GetRuntimeArchitecture() (string, error) {
|
|
| 40 |
+ syscall.Syscall(procGetSystemInfo.Addr(), 1, uintptr(unsafe.Pointer(&sysinfo)), 0, 0) |
|
| 41 |
+ switch sysinfo.wProcessorArchitecture {
|
|
| 42 |
+ case ProcessorArchitecture64, ProcessorArchitectureIA64: |
|
| 43 |
+ return "x86_64", nil |
|
| 44 |
+ case ProcessorArchitecture32: |
|
| 45 |
+ return "i686", nil |
|
| 46 |
+ case ProcessorArchitectureArm: |
|
| 47 |
+ return "arm", nil |
|
| 48 |
+ default: |
|
| 49 |
+ return "", fmt.Errorf("Unknown processor architecture")
|
|
| 50 |
+ } |
|
| 51 |
+} |
| 0 | 52 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,23 @@ |
| 0 |
+package platform |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "runtime" |
|
| 4 |
+ |
|
| 5 |
+ "github.com/Sirupsen/logrus" |
|
| 6 |
+) |
|
| 7 |
+ |
|
| 8 |
+var ( |
|
| 9 |
+ // Architecture holds the runtime architecture of the process. |
|
| 10 |
+ Architecture string |
|
| 11 |
+ // OSType holds the runtime operating system type (Linux, …) of the process. |
|
| 12 |
+ OSType string |
|
| 13 |
+) |
|
| 14 |
+ |
|
| 15 |
+func init() {
|
|
| 16 |
+ var err error |
|
| 17 |
+ Architecture, err = GetRuntimeArchitecture() |
|
| 18 |
+ if err != nil {
|
|
| 19 |
+ logrus.Errorf("Could no read system architecture info: %v", err)
|
|
| 20 |
+ } |
|
| 21 |
+ OSType = runtime.GOOS |
|
| 22 |
+} |