1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #17478 from vdemeester/pr-13921

Carry#13921 : Expand /info: Expose OSType (GOOS), Architecture (GOARCH)
This commit is contained in:
Michael Crosby 2015-11-17 15:44:57 -08:00
commit 104dab87ea
12 changed files with 135 additions and 0 deletions

View file

@ -59,6 +59,8 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
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)

View file

@ -208,6 +208,8 @@ type Info struct {
NEventsListener int
KernelVersion string
OperatingSystem string
OSType string
Architecture string
IndexServerAddress string
RegistryConfig *registry.ServiceConfig
InitSha1 string

View file

@ -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"
@ -77,6 +78,8 @@ func (daemon *Daemon) SystemInfo() (*types.Info, error) {
KernelVersion: kernelVersion,
OperatingSystem: operatingSystem,
IndexServerAddress: registry.IndexServer,
OSType: platform.OSType,
Architecture: platform.Architecture,
RegistryConfig: daemon.RegistryService.Config,
InitSha1: dockerversion.InitSHA1,
InitPath: initPath,

View file

@ -1884,6 +1884,7 @@ Display system-wide information
Content-Type: application/json
{
"Architecture": "x86_64",
"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": {

View file

@ -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: x86_64
Operating System: Ubuntu 15.04
CPUs: 24
Total Memory: 62.86 GiB

View file

@ -23,6 +23,8 @@ func (s *DockerSuite) TestInfoApi(c *check.C) {
"LoggingDriver",
"OperatingSystem",
"NCPU",
"OSType",
"Architecture",
"MemTotal",
"KernelVersion",
"Driver",

View file

@ -19,6 +19,8 @@ func (s *DockerSuite) TestInfoEnsureSucceeds(c *check.C) {
"Containers:",
"Images:",
"Execution Driver:",
"OSType:",
"Architecture:",
"Logging Driver:",
"Operating System:",
"CPUs:",

View file

@ -44,6 +44,8 @@ Here is a sample output:
Network: bridge null host
Kernel Version: 3.13.0-24-generic
Operating System: Ubuntu 14.04 LTS
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 2 GiB

View file

@ -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
}

View file

@ -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])
}

View file

@ -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")
}
}

23
pkg/platform/platform.go Normal file
View file

@ -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
}