Skip to content

Commit

Permalink
[system] 'Version' and 'Distribution' info removed from 'SystemInfo'
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Feb 5, 2023
1 parent 2351920 commit 985d3b1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 86 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

### 12.58.0

* `[system]` Added system arch name to SystemInfo
* `[system]` Added system arch name to `SystemInfo`
* `[system]` `Version` and `Distribution` info removed from `SystemInfo` (_use `OSInfo` instead_)

### 12.57.1

Expand Down
30 changes: 6 additions & 24 deletions system/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,6 @@ import (

// ////////////////////////////////////////////////////////////////////////////////// //

// OS names
const (
LINUX_ARCH = "Arch"
LINUX_CENTOS = "CentOS"
LINUX_DEBIAN = "Debian"
LINUX_FEDORA = "Fedora"
LINUX_GENTOO = "Gentoo"
LINUX_RHEL = "RHEL"
LINUX_SUSE = "SuSe"
LINUX_OPEN_SUSE = "openSUSE"
LINUX_UBUNTU = "Ubuntu"
DARWIN_OSX = "OSX"
)

// ////////////////////////////////////////////////////////////////////////////////// //

// LoadAvg contains information about average system load
type LoadAvg struct {
Min1 float64 `json:"min1"` // LA in last 1 minute
Expand Down Expand Up @@ -138,14 +122,12 @@ type InterfaceStats struct {

// SystemInfo contains info about a system (hostname, OS, arch...)
type SystemInfo struct {
Hostname string `json:"hostname"` // Hostname
OS string `json:"os"` // OS name
Distribution string `json:"distribution"` // OS distribution
Version string `json:"version"` // OS version
Kernel string `json:"kernel"` // Kernel version
Arch string `json:"arch"` // System architecture (i386/i686/x86_64/etc…)
ArchName string `json:"arch_name"` // System architecture (386/686/amd64/etc…)
ArchBits int `json:"arch_bits"` // Architecture bits (32/64)
Hostname string `json:"hostname"` // Hostname
OS string `json:"os"` // OS name
Kernel string `json:"kernel"` // Kernel version
Arch string `json:"arch"` // System architecture (i386/i686/x86_64/etc…)
ArchName string `json:"arch_name"` // System architecture (386/686/amd64/etc…)
ArchBits int `json:"arch_bits"` // Architecture bits (32/64)
}

// OSInfo contains info about OS
Expand Down
46 changes: 6 additions & 40 deletions system/info_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,15 @@ func GetSystemInfo() (*SystemInfo, error) {
return nil, err
}

osInfo, err := GetOSInfo()

if err != nil {
return nil, err
}

arch := byteSliceToString(info.Machine)

return &SystemInfo{
Hostname: byteSliceToString(info.Nodename),
OS: byteSliceToString(info.Sysname),
Distribution: formatDistName(osInfo.Name),
Version: osInfo.VersionID,
Kernel: byteSliceToString(info.Release),
Arch: arch,
ArchName: getArchName(arch),
ArchBits: getCPUArchBits(),
Hostname: byteSliceToString(info.Nodename),
OS: byteSliceToString(info.Sysname),
Kernel: byteSliceToString(info.Release),
Arch: arch,
ArchName: getArchName(arch),
ArchBits: getCPUArchBits(),
}, nil
}

Expand Down Expand Up @@ -129,32 +121,6 @@ func applyOSInfo(info *OSInfo, name, value string) {
}
}

// formatDistName formats distribution name
func formatDistName(name string) string {
switch strings.ToUpper(name) {
case strings.ToUpper(LINUX_ARCH):
return LINUX_ARCH
case strings.ToUpper(LINUX_CENTOS):
return LINUX_CENTOS
case strings.ToUpper(LINUX_DEBIAN):
return LINUX_DEBIAN
case strings.ToUpper(LINUX_FEDORA):
return LINUX_FEDORA
case strings.ToUpper(LINUX_GENTOO):
return LINUX_GENTOO
case strings.ToUpper(LINUX_RHEL):
return LINUX_RHEL
case strings.ToUpper(LINUX_SUSE):
return LINUX_SUSE
case strings.ToUpper(LINUX_OPEN_SUSE):
return LINUX_OPEN_SUSE
case strings.ToUpper(LINUX_UBUNTU):
return LINUX_UBUNTU
}

return name
}

// getArchName returns name for given arch
func getArchName(arch string) string {
switch arch {
Expand Down
28 changes: 7 additions & 21 deletions system/info_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,13 +612,15 @@ func (s *SystemSuite) TestUser(c *C) {
func (s *SystemSuite) TestGetInfo(c *C) {
origOsReleaseFile := osReleaseFile

osReleaseFile = "/_UNKNOWN_"

sysInfo, err := GetSystemInfo()
c.Assert(err, IsNil)
c.Assert(sysInfo, NotNil)

osReleaseFile = "/_UNKNOWN_"
osInfo, err := GetOSInfo()
c.Assert(err, NotNil)
c.Assert(err, ErrorMatches, `open /_UNKNOWN_: no such file or directory`)
c.Assert(sysInfo, IsNil)
c.Assert(osInfo, IsNil)

osReleaseFile = s.CreateTestFile(c, `NAME="Ubuntu"
VERSION="20.10 (Groovy Gorilla)"
Expand All @@ -641,14 +643,9 @@ REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
`)

sysInfo, err = GetSystemInfo()
osInfo, err = GetOSInfo()

c.Assert(err, IsNil)
c.Assert(sysInfo, NotNil)

osInfo, err := GetOSInfo()

c.Assert(osInfo.Name, Equals, LINUX_UBUNTU)
c.Assert(osInfo.Name, Equals, "Ubuntu")
c.Assert(osInfo.PrettyName, Equals, "Ubuntu 20.10")
c.Assert(osInfo.Version, Equals, "20.10 (Groovy Gorilla)")
c.Assert(osInfo.VersionID, Equals, "20.10")
Expand All @@ -667,17 +664,6 @@ REDHAT_SUPPORT_PRODUCT_VERSION="7"
c.Assert(osInfo.SupportProduct, Equals, "centos")
c.Assert(osInfo.SupportProductVersion, Equals, "7")

c.Assert(formatDistName("arch"), Equals, LINUX_ARCH)
c.Assert(formatDistName("centos"), Equals, LINUX_CENTOS)
c.Assert(formatDistName("debian"), Equals, LINUX_DEBIAN)
c.Assert(formatDistName("fedora"), Equals, LINUX_FEDORA)
c.Assert(formatDistName("gentoo"), Equals, LINUX_GENTOO)
c.Assert(formatDistName("rhel"), Equals, LINUX_RHEL)
c.Assert(formatDistName("suse"), Equals, LINUX_SUSE)
c.Assert(formatDistName("opensuse"), Equals, LINUX_OPEN_SUSE)
c.Assert(formatDistName("ubuntu"), Equals, LINUX_UBUNTU)
c.Assert(formatDistName("SuppaLinux"), Equals, "SuppaLinux")

c.Assert(getArchName("i386"), Equals, "386")
c.Assert(getArchName("i586"), Equals, "586")
c.Assert(getArchName("i686"), Equals, "686")
Expand Down

0 comments on commit 985d3b1

Please sign in to comment.