From e37b7c5331ca58aac052d5aa55d6c5541d567895 Mon Sep 17 00:00:00 2001 From: Sven Dowideit Date: Thu, 15 Jun 2017 23:37:44 +1000 Subject: [PATCH] Make it work consistently for kvm too Signed-off-by: Sven Dowideit --- cmd/control/console_init.go | 3 +- init/init.go | 28 +++++++++++++------ tests/ros_config_test.go | 6 ++++ trash.conf | 2 +- vendor/github.com/SvenDowideit/cpuid/cpuid.go | 10 ++++--- 5 files changed, 35 insertions(+), 14 deletions(-) diff --git a/cmd/control/console_init.go b/cmd/control/console_init.go index 392406a8..18f54257 100644 --- a/cmd/control/console_init.go +++ b/cmd/control/console_init.go @@ -11,6 +11,7 @@ import ( "strings" "syscall" + "github.com/SvenDowideit/cpuid" "github.com/codegangsta/cli" "github.com/rancher/os/cmd/cloudinitexecute" "github.com/rancher/os/config" @@ -117,7 +118,7 @@ func consoleInitFunc() error { | | | | \\_| \\_\\__,_|_| |_|\\___|_| |_|\\___|_| \\___/\\____/ \\___/ \\___/ \s \r - RancherOS `+config.Version+` \n \l + RancherOS `+config.Version+` \n \l `+cpuid.CPU.HypervisorName+` `), 0644); err != nil { log.Error(err) } diff --git a/init/init.go b/init/init.go index d27541e9..cd580413 100755 --- a/init/init.go +++ b/init/init.go @@ -299,19 +299,11 @@ func RunInit() error { return cfg, nil }}, config.CfgFuncData{"cloud-init", func(cfg *config.CloudConfig) (*config.CloudConfig, error) { - cfg.Rancher.CloudInit.Datasources = config.LoadConfigWithPrefix(state).Rancher.CloudInit.Datasources if err := config.Set("rancher.cloud_init.datasources", cfg.Rancher.CloudInit.Datasources); err != nil { log.Error(err) } - log.Infof("Hypervisor vendor: %s", cpuid.CPU.HypervisorName) - if cpuid.CPU.HypervisorName == "vmware" { - if err := config.Set("rancher.services_include.open-vm-tools", "true"); err != nil { - log.Error(err) - } - } - log.Debug("init, runCloudInitServices()") if err := runCloudInitServices(cfg); err != nil { log.Error(err) @@ -367,9 +359,15 @@ func RunInit() error { if err := os.Chmod(config.VarRancherDir, os.ModeDir|0755); err != nil { log.Error(err) } + return cfg, nil }}, + config.CfgFuncData{"detect hypervisor", func(cfg *config.CloudConfig) (*config.CloudConfig, error) { + checkHypervisor() + return config.LoadConfig(), nil + }}, config.CfgFuncData{"b2d Env", func(cfg *config.CloudConfig) (*config.CloudConfig, error) { + if boot2DockerEnvironment { if err := config.Set("rancher.state.dev", cfg.Rancher.State.Dev); err != nil { log.Errorf("Failed to update rancher.state.dev: %v", err) @@ -410,3 +408,17 @@ func RunInit() error { return pidOne() } + +func checkHypervisor() { + hvtools := cpuid.CPU.HypervisorName + if hvtools != "" { + log.Infof("Detected Hypervisor: %s", cpuid.CPU.HypervisorName) + if hvtools == "vmware" { + hvtools = "open" + } + log.Infof("Setting rancher.services_include." + hvtools + "-vm-tools=true") + if err := config.Set("rancher.services_include."+hvtools+"-vm-tools", "true"); err != nil { + log.Error(err) + } + } +} diff --git a/tests/ros_config_test.go b/tests/ros_config_test.go index 92cb2974..367d480f 100644 --- a/tests/ros_config_test.go +++ b/tests/ros_config_test.go @@ -83,4 +83,10 @@ sudo ros config export --private --full | grep "ntp" sudo ros config export --full | grep "labels" sudo ros config export --private --full | grep "PRIVATE KEY"`) + + s.CheckCall(c, ` +set -x -e +sudo ros config get rancher.services_include | grep kvm-vm-tools +`) + } diff --git a/trash.conf b/trash.conf index 3ec2e2c5..54f82832 100644 --- a/trash.conf +++ b/trash.conf @@ -53,7 +53,7 @@ github.com/vishvananda/netns 54f0e4339ce73702a0607f49922aaa1e749b418d github.com/xeipuuv/gojsonpointer e0fe6f68307607d540ed8eac07a342c33fa1b54a github.com/xeipuuv/gojsonreference e02fc20de94c78484cd5ffb007f8af96be030a45 github.com/xeipuuv/gojsonschema ac452913faa25c08bb78810d3e6f88b8a39f8f25 -github.com/SvenDowideit/cpuid 96209a5b78b1c60a696fab3833d9ac02c74cbd39 +github.com/SvenDowideit/cpuid 399bf479aea1edfbfe0b686c514631b511f44641 golang.org/x/crypto 2f3083f6163ef51179ad42ed523a18c9a1141467 golang.org/x/net 991d3e32f76f19ee6d9caadb3a22eae8d23315f7 https://github.com/golang/net.git golang.org/x/sys eb2c74142fd19a79b3f237334c7384d5167b1b46 https://github.com/golang/sys.git diff --git a/vendor/github.com/SvenDowideit/cpuid/cpuid.go b/vendor/github.com/SvenDowideit/cpuid/cpuid.go index 04d3e66d..91ea9763 100644 --- a/vendor/github.com/SvenDowideit/cpuid/cpuid.go +++ b/vendor/github.com/SvenDowideit/cpuid/cpuid.go @@ -567,7 +567,8 @@ func isHypervisorActive() bool { func getHypervisorCpuid(ax uint32) string { a, b, c, d := cpuid(ax) var info [4]uint32 = [4]uint32{a, b, c, d} - return strings.TrimRight(string((*[12]byte)(unsafe.Pointer(&info[1]))[:]), "\000") + name := strings.TrimRight(string((*[12]byte)(unsafe.Pointer(&info[1]))[:]), "\000") + return name } // see https://people.redhat.com/~rjones/virt-what/ for how full coverage is done @@ -578,9 +579,10 @@ func hypervisorName() string { } // KVM has been caught to move its real signature to this leaf, and put something completely different in the // standard location. So this leaf must be checked first. - if hv := getHypervisorCpuid(0x40000100); hv != "" { - return hv - } + // Sven removed it - in one test system, this leaf returns garbage :( + //if hv := getHypervisorCpuid(0x40000100); hv != "" { + // return hv + //} if hv := getHypervisorCpuid(0x40000000); hv != "" { return hv