fix detect host info

This commit is contained in:
wanyaoqi
2020-01-16 16:48:15 +08:00
parent 352800c78d
commit bd560a07b6
2 changed files with 7 additions and 6 deletions

View File

@@ -484,18 +484,19 @@ func (h *SHostInfo) detectNestSupport() {
}
func (h *SHostInfo) detectiveOsDist() {
files, err := procutils.NewCommand("sh", "-c", "ls /etc/*elease").Output()
files, err := procutils.NewRemoteCommandAsFarAsPossible("sh", "-c", "ls /etc/*elease").Output()
if err != nil {
log.Errorln(err)
return
}
re := regexp.MustCompile(`(.+) release ([\d.]+)[^(]*(?:\((.+)\))?`)
for _, file := range strings.Split(string(files), "\n") {
content, err := fileutils2.FileGetContents(file)
content, err := procutils.NewRemoteCommandAsFarAsPossible("cat", file).Output()
if err != nil {
log.Errorln(err)
continue
}
m := re.FindStringSubmatch(content)
m := re.FindStringSubmatch(string(content))
if len(m) == 4 {
h.sysinfo.OsDistribution = m[1]
h.sysinfo.OsVersion = m[2]

View File

@@ -96,9 +96,7 @@ func detectiveKVMModuleSupport() string {
func ModprobeKvmModule(name string, remove, nest bool) bool {
var params = []string{"modprobe"}
if remove {
if err := procutils.NewRemoteCommandAsFarAsPossible("rmmod", name).Run(); err != nil {
log.Errorf("rmmod failed %s: %s", name, err)
}
params = append(params, "-r")
}
params = append(params, name)
if nest {
@@ -127,10 +125,12 @@ func detectNestSupport() string {
nestStatus := HOST_NEST_UNSUPPORT
if moduleName != KVM_MODULE_UNSUPPORT && isNestSupport(moduleName) {
log.Infof("Host is support kvm nest ...")
nestStatus = HOST_NEST_SUPPORT
}
if nestStatus == HOST_NEST_SUPPORT && loadKvmModuleWithNest(moduleName) {
log.Infof("Host kvm nest is enabled ...")
nestStatus = HOST_NEST_ENABLE
}
return nestStatus