Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Canread
Gopsutil
提交
76866feb
G
Gopsutil
项目概览
Canread
/
Gopsutil
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gopsutil
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
76866feb
编写于
5月 27, 2014
作者:
W
WAKAYAMA Shirou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
implement redhatishVersion and platform on Linux.
上级
710c0290
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
91 addition
and
14 deletion
+91
-14
cpu_test.go
cpu_test.go
+0
-1
host_linux.go
host_linux.go
+30
-13
host_linux_test.go
host_linux_test.go
+61
-0
未找到文件。
cpu_test.go
浏览文件 @
76866feb
...
...
@@ -3,7 +3,6 @@ package gopsutil
import
(
"fmt"
"testing"
)
func
TestCpu_times
(
t
*
testing
.
T
)
{
...
...
host_linux.go
浏览文件 @
76866feb
...
...
@@ -8,6 +8,7 @@ import (
"io/ioutil"
"os"
"os/exec"
"regexp"
"runtime"
"strings"
"syscall"
...
...
@@ -156,21 +157,21 @@ func GetPlatformInformation() (string, string, string, error) {
version
:=
""
lsb
,
err
:=
getLSB
()
if
err
!=
nil
{
lsb
=
LSB
{}
if
err
!=
nil
{
lsb
=
&
LSB
{}
}
if
pathExists
(
"/etc/oracle-release"
)
{
platform
=
"oracle"
contents
,
err
:=
readLines
(
"/etc/oracle-release"
)
if
err
==
nil
{
version
,
_
=
getRedhatishVersion
(
contents
)
version
=
getRedhatishVersion
(
contents
)
}
}
else
if
pathExists
(
"/etc/enterprise-release"
)
{
platform
=
"oracle"
contents
,
err
:=
readLines
(
"/etc/enterprise-release"
)
if
err
==
nil
{
version
,
_
=
getRedhatishVersion
(
contents
)
version
=
getRedhatishVersion
(
contents
)
}
}
else
if
pathExists
(
"/etc/debian_version"
)
{
if
lsb
.
ID
==
"Ubuntu"
{
...
...
@@ -193,20 +194,20 @@ func GetPlatformInformation() (string, string, string, error) {
}
else
if
pathExists
(
"/etc/redhat-release"
)
{
contents
,
err
:=
readLines
(
"/etc/redhat-release"
)
if
err
==
nil
{
version
,
_
=
getRedhatishVersion
(
contents
)
platform
,
_
=
getRedhatishPlatform
(
contents
)
version
=
getRedhatishVersion
(
contents
)
platform
=
getRedhatishPlatform
(
contents
)
}
}
else
if
pathExists
(
"/etc/system-release"
)
{
contents
,
err
:=
readLines
(
"/etc/system-release"
)
if
err
==
nil
{
version
,
_
=
getRedhatishVersion
(
contents
)
platform
,
_
=
getRedhatishPlatform
(
contents
)
version
=
getRedhatishVersion
(
contents
)
platform
=
getRedhatishPlatform
(
contents
)
}
}
else
if
pathExists
(
"/etc/gentoo-release"
)
{
platform
=
"gentoo"
contents
,
err
:=
readLines
(
"/etc/gentoo-release"
)
if
err
==
nil
{
version
,
_
=
getRedhatishVersion
(
contents
)
version
=
getRedhatishVersion
(
contents
)
}
// TODO: suse detection
// TODO: slackware detecion
...
...
@@ -253,12 +254,28 @@ func GetPlatformInformation() (string, string, string, error) {
}
func
getRedhatishVersion
(
contents
[]
string
)
(
string
,
error
)
{
return
""
,
nil
func
getRedhatishVersion
(
contents
[]
string
)
string
{
c
:=
strings
.
ToLower
(
strings
.
Join
(
contents
,
""
))
if
strings
.
Contains
(
c
,
"rawhide"
)
{
return
"rawhide"
}
if
matches
:=
regexp
.
MustCompile
(
`release (\d[\d.]*)`
)
.
FindStringSubmatch
(
c
);
matches
!=
nil
{
return
matches
[
1
]
}
else
{
return
""
}
}
func
getRedhatishPlatform
(
contents
[]
string
)
(
string
,
error
)
{
return
""
,
nil
func
getRedhatishPlatform
(
contents
[]
string
)
string
{
c
:=
strings
.
ToLower
(
strings
.
Join
(
contents
,
""
))
if
strings
.
Contains
(
c
,
"red hat"
)
{
return
"redhat"
}
f
:=
strings
.
Split
(
c
,
" "
)
return
f
[
0
]
}
func
GetVirtualization
()
(
string
,
string
,
error
)
{
...
...
host_linux_test.go
0 → 100644
浏览文件 @
76866feb
// +build linux
package
gopsutil
import
(
"testing"
)
func
TestGetRedhatishVersion
(
t
*
testing
.
T
)
{
var
ret
string
c
:=
[]
string
{
"Rawhide"
}
ret
=
getRedhatishVersion
(
c
)
if
ret
!=
"rawhide"
{
t
.
Errorf
(
"Could not get version rawhide: %v"
,
ret
)
}
c
=
[]
string
{
"Fedora release 15 (Lovelock)"
}
ret
=
getRedhatishVersion
(
c
)
if
ret
!=
"15"
{
t
.
Errorf
(
"Could not get version fedora: %v"
,
ret
)
}
c
=
[]
string
{
"Enterprise Linux Server release 5.5 (Carthage)"
}
ret
=
getRedhatishVersion
(
c
)
if
ret
!=
"5.5"
{
t
.
Errorf
(
"Could not get version redhat enterprise: %v"
,
ret
)
}
c
=
[]
string
{
""
}
ret
=
getRedhatishVersion
(
c
)
if
ret
!=
""
{
t
.
Errorf
(
"Could not get version with no value: %v"
,
ret
)
}
}
func
TestGetRedhatishPlatform
(
t
*
testing
.
T
)
{
var
ret
string
c
:=
[]
string
{
"red hat"
}
ret
=
getRedhatishPlatform
(
c
)
if
ret
!=
"redhat"
{
t
.
Errorf
(
"Could not get platform redhat: %v"
,
ret
)
}
c
=
[]
string
{
"Fedora release 15 (Lovelock)"
}
ret
=
getRedhatishPlatform
(
c
)
if
ret
!=
"fedora"
{
t
.
Errorf
(
"Could not get platform fedora: %v"
,
ret
)
}
c
=
[]
string
{
"Enterprise Linux Server release 5.5 (Carthage)"
}
ret
=
getRedhatishPlatform
(
c
)
if
ret
!=
"enterprise"
{
t
.
Errorf
(
"Could not get platform redhat enterprise: %v"
,
ret
)
}
c
=
[]
string
{
""
}
ret
=
getRedhatishPlatform
(
c
)
if
ret
!=
""
{
t
.
Errorf
(
"Could not get platform with no value: %v"
,
ret
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录