From 4e8fcd40028ed09b139b6f86954e676a1839be9c Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Sat, 13 Jun 2015 09:39:19 +0200 Subject: [PATCH 1/2] /info: Add keys Architecture, OSType - introduces Swarm-relevant keys, see #13634 - docs updated Signed-off-by: Olle Jonsson --- api/client/info.go | 2 ++ api/types/types.go | 2 ++ daemon/info.go | 2 ++ docs/reference/api/docker_remote_api_v1.21.md | 2 ++ docs/reference/commandline/info.md | 2 ++ integration-cli/docker_api_info_test.go | 2 ++ integration-cli/docker_cli_info_test.go | 2 ++ man/docker-info.1.md | 2 ++ 8 files changed, 16 insertions(+) diff --git a/api/client/info.go b/api/client/info.go index 7d373e0e68..eb364dd7a9 100644 --- a/api/client/info.go +++ b/api/client/info.go @@ -46,6 +46,8 @@ func (cli *DockerCli) CmdInfo(args ...string) error { ioutils.FprintfIfNotEmpty(cli.out, "Logging Driver: %s\n", info.LoggingDriver) ioutils.FprintfIfNotEmpty(cli.out, "Kernel Version: %s\n", info.KernelVersion) ioutils.FprintfIfNotEmpty(cli.out, "Operating System: %s\n", info.OperatingSystem) + ioutils.FprintfIfNotEmpty(cli.out, "OSType: %s\n", info.OSType) + ioutils.FprintfIfNotEmpty(cli.out, "Architecture: %s\n", info.Architecture) fmt.Fprintf(cli.out, "CPUs: %d\n", info.NCPU) fmt.Fprintf(cli.out, "Total Memory: %s\n", units.BytesSize(float64(info.MemTotal))) ioutils.FprintfIfNotEmpty(cli.out, "Name: %s\n", info.Name) diff --git a/api/types/types.go b/api/types/types.go index b69bbaea6e..9098b7954a 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -207,6 +207,8 @@ type Info struct { NEventsListener int KernelVersion string OperatingSystem string + OSType string + Architecture string IndexServerAddress string RegistryConfig *registry.ServiceConfig InitSha1 string diff --git a/daemon/info.go b/daemon/info.go index 9e15f0de19..8f9f3afa97 100644 --- a/daemon/info.go +++ b/daemon/info.go @@ -75,6 +75,8 @@ func (daemon *Daemon) SystemInfo() (*types.Info, error) { KernelVersion: kernelVersion, OperatingSystem: operatingSystem, IndexServerAddress: registry.IndexServer, + OSType: runtime.GOOS, + Architecture: runtime.GOARCH, RegistryConfig: daemon.RegistryService.Config, InitSha1: dockerversion.InitSHA1, InitPath: initPath, diff --git a/docs/reference/api/docker_remote_api_v1.21.md b/docs/reference/api/docker_remote_api_v1.21.md index 1d6bfa788c..a53a6fcb80 100644 --- a/docs/reference/api/docker_remote_api_v1.21.md +++ b/docs/reference/api/docker_remote_api_v1.21.md @@ -1884,6 +1884,7 @@ Display system-wide information Content-Type: application/json { + "Architecture": "amd64", "Containers": 11, "CpuCfsPeriod": true, "CpuCfsQuota": true, @@ -1915,6 +1916,7 @@ Display system-wide information "Name": "prod-server-42", "NoProxy": "9.81.1.160", "OomKillDisable": true, + "OSType": "linux", "OperatingSystem": "Boot2Docker", "RegistryConfig": { "IndexConfigs": { diff --git a/docs/reference/commandline/info.md b/docs/reference/commandline/info.md index 1794df40b5..e23d9d6780 100644 --- a/docs/reference/commandline/info.md +++ b/docs/reference/commandline/info.md @@ -31,6 +31,8 @@ For example: Execution Driver: native-0.2 Logging Driver: json-file Kernel Version: 3.19.0-22-generic + OSType: linux + Architecture: amd64 Operating System: Ubuntu 15.04 CPUs: 24 Total Memory: 62.86 GiB diff --git a/integration-cli/docker_api_info_test.go b/integration-cli/docker_api_info_test.go index 54f5752796..b10012494e 100644 --- a/integration-cli/docker_api_info_test.go +++ b/integration-cli/docker_api_info_test.go @@ -23,6 +23,8 @@ func (s *DockerSuite) TestInfoApi(c *check.C) { "LoggingDriver", "OperatingSystem", "NCPU", + "OSType", + "Architecture", "MemTotal", "KernelVersion", "Driver", diff --git a/integration-cli/docker_cli_info_test.go b/integration-cli/docker_cli_info_test.go index 21b8e51682..5e786c4de7 100644 --- a/integration-cli/docker_cli_info_test.go +++ b/integration-cli/docker_cli_info_test.go @@ -19,6 +19,8 @@ func (s *DockerSuite) TestInfoEnsureSucceeds(c *check.C) { "Containers:", "Images:", "Execution Driver:", + "OSType:", + "Architecture:", "Logging Driver:", "Operating System:", "CPUs:", diff --git a/man/docker-info.1.md b/man/docker-info.1.md index f67a4fb00c..208d3423a3 100644 --- a/man/docker-info.1.md +++ b/man/docker-info.1.md @@ -41,6 +41,8 @@ Here is a sample output: Logging Driver: json-file Kernel Version: 3.13.0-24-generic Operating System: Ubuntu 14.04 LTS + OSType: linux + Architecture: amd64 CPUs: 1 Total Memory: 2 GiB From 49779b674af09b46c165c8dfe2e76054336b0595 Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Sat, 14 Nov 2015 23:03:02 +0100 Subject: [PATCH 2/2] Add pkg/parsers/architecture and pkg/platform Signed-off-by: Vincent Demeester --- daemon/info.go | 5 +- docs/reference/api/docker_remote_api_v1.21.md | 2 +- docs/reference/commandline/info.md | 2 +- man/docker-info.1.md | 2 +- pkg/platform/architecture_freebsd.go | 15 ++++++ pkg/platform/architecture_linux.go | 28 ++++++++++ pkg/platform/architecture_windows.go | 52 +++++++++++++++++++ pkg/platform/platform.go | 23 ++++++++ 8 files changed, 124 insertions(+), 5 deletions(-) create mode 100644 pkg/platform/architecture_freebsd.go create mode 100644 pkg/platform/architecture_linux.go create mode 100644 pkg/platform/architecture_windows.go create mode 100644 pkg/platform/platform.go diff --git a/daemon/info.go b/daemon/info.go index 8f9f3afa97..9243675463 100644 --- a/daemon/info.go +++ b/daemon/info.go @@ -11,6 +11,7 @@ import ( "github.com/docker/docker/pkg/fileutils" "github.com/docker/docker/pkg/parsers/kernel" "github.com/docker/docker/pkg/parsers/operatingsystem" + "github.com/docker/docker/pkg/platform" "github.com/docker/docker/pkg/sysinfo" "github.com/docker/docker/pkg/system" "github.com/docker/docker/registry" @@ -75,8 +76,8 @@ func (daemon *Daemon) SystemInfo() (*types.Info, error) { KernelVersion: kernelVersion, OperatingSystem: operatingSystem, IndexServerAddress: registry.IndexServer, - OSType: runtime.GOOS, - Architecture: runtime.GOARCH, + OSType: platform.OSType, + Architecture: platform.Architecture, RegistryConfig: daemon.RegistryService.Config, InitSha1: dockerversion.InitSHA1, InitPath: initPath, diff --git a/docs/reference/api/docker_remote_api_v1.21.md b/docs/reference/api/docker_remote_api_v1.21.md index a53a6fcb80..c57edc9e71 100644 --- a/docs/reference/api/docker_remote_api_v1.21.md +++ b/docs/reference/api/docker_remote_api_v1.21.md @@ -1884,7 +1884,7 @@ Display system-wide information Content-Type: application/json { - "Architecture": "amd64", + "Architecture": "x86_64", "Containers": 11, "CpuCfsPeriod": true, "CpuCfsQuota": true, diff --git a/docs/reference/commandline/info.md b/docs/reference/commandline/info.md index e23d9d6780..c1f208418b 100644 --- a/docs/reference/commandline/info.md +++ b/docs/reference/commandline/info.md @@ -32,7 +32,7 @@ For example: Logging Driver: json-file Kernel Version: 3.19.0-22-generic OSType: linux - Architecture: amd64 + Architecture: x86_64 Operating System: Ubuntu 15.04 CPUs: 24 Total Memory: 62.86 GiB diff --git a/man/docker-info.1.md b/man/docker-info.1.md index 208d3423a3..4e451a3b3d 100644 --- a/man/docker-info.1.md +++ b/man/docker-info.1.md @@ -42,7 +42,7 @@ Here is a sample output: Kernel Version: 3.13.0-24-generic Operating System: Ubuntu 14.04 LTS OSType: linux - Architecture: amd64 + Architecture: x86_64 CPUs: 1 Total Memory: 2 GiB diff --git a/pkg/platform/architecture_freebsd.go b/pkg/platform/architecture_freebsd.go new file mode 100644 index 0000000000..e8bf398fa5 --- /dev/null +++ b/pkg/platform/architecture_freebsd.go @@ -0,0 +1,15 @@ +package platform + +import ( + "os/exec" +) + +// GetRuntimeArchitecture get the name of the current architecture (x86, x86_64, …) +func GetRuntimeArchitecture() (string, error) { + cmd := exec.Command("uname", "-m") + machine, err := cmd.Output() + if err != nil { + return "", err + } + return string(machine), nil +} diff --git a/pkg/platform/architecture_linux.go b/pkg/platform/architecture_linux.go new file mode 100644 index 0000000000..e732534f33 --- /dev/null +++ b/pkg/platform/architecture_linux.go @@ -0,0 +1,28 @@ +// Package platform provides helper function to get the runtime architecture +// for different platforms. +package platform + +import ( + "syscall" +) + +// GetRuntimeArchitecture get the name of the current architecture (x86, x86_64, …) +func GetRuntimeArchitecture() (string, error) { + utsname := &syscall.Utsname{} + if err := syscall.Uname(utsname); err != nil { + return "", err + } + return charsToString(utsname.Machine), nil +} + +func charsToString(ca [65]int8) string { + s := make([]byte, len(ca)) + var lens int + for ; lens < len(ca); lens++ { + if ca[lens] == 0 { + break + } + s[lens] = uint8(ca[lens]) + } + return string(s[0:lens]) +} diff --git a/pkg/platform/architecture_windows.go b/pkg/platform/architecture_windows.go new file mode 100644 index 0000000000..19717c9349 --- /dev/null +++ b/pkg/platform/architecture_windows.go @@ -0,0 +1,52 @@ +package platform + +import ( + "fmt" + "syscall" + "unsafe" +) + +var ( + modkernel32 = syscall.NewLazyDLL("kernel32.dll") + procGetSystemInfo = modkernel32.NewProc("GetSystemInfo") +) + +// see http://msdn.microsoft.com/en-us/library/windows/desktop/ms724958(v=vs.85).aspx +type systeminfo struct { + wProcessorArchitecture uint16 + wReserved uint16 + dwPageSize uint32 + lpMinimumApplicationAddress uintptr + lpMaximumApplicationAddress uintptr + dwActiveProcessorMask uintptr + dwNumberOfProcessors uint32 + dwProcessorType uint32 + dwAllocationGranularity uint32 + wProcessorLevel uint16 + wProcessorRevision uint16 +} + +// Constants +const ( + ProcessorArchitecture64 = 9 // PROCESSOR_ARCHITECTURE_AMD64 + ProcessorArchitectureIA64 = 6 // PROCESSOR_ARCHITECTURE_IA64 + ProcessorArchitecture32 = 0 // PROCESSOR_ARCHITECTURE_INTEL + ProcessorArchitectureArm = 5 // PROCESSOR_ARCHITECTURE_ARM +) + +var sysinfo systeminfo + +// GetRuntimeArchitecture get the name of the current architecture (x86, x86_64, …) +func GetRuntimeArchitecture() (string, error) { + syscall.Syscall(procGetSystemInfo.Addr(), 1, uintptr(unsafe.Pointer(&sysinfo)), 0, 0) + switch sysinfo.wProcessorArchitecture { + case ProcessorArchitecture64, ProcessorArchitectureIA64: + return "x86_64", nil + case ProcessorArchitecture32: + return "i686", nil + case ProcessorArchitectureArm: + return "arm", nil + default: + return "", fmt.Errorf("Unknown processor architecture") + } +} diff --git a/pkg/platform/platform.go b/pkg/platform/platform.go new file mode 100644 index 0000000000..d84c4f59de --- /dev/null +++ b/pkg/platform/platform.go @@ -0,0 +1,23 @@ +package platform + +import ( + "runtime" + + "github.com/Sirupsen/logrus" +) + +var ( + // Architecture holds the runtime architecture of the process. + Architecture string + // OSType holds the runtime operating system type (Linux, …) of the process. + OSType string +) + +func init() { + var err error + Architecture, err = GetRuntimeArchitecture() + if err != nil { + logrus.Errorf("Could no read system architecture info: %v", err) + } + OSType = runtime.GOOS +}