mirror of
https://github.com/rancher/os.git
synced 2025-07-16 08:05:51 +00:00
Make it work consistently for kvm too
Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
parent
60ac78b816
commit
e37b7c5331
@ -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)
|
||||
}
|
||||
|
28
init/init.go
28
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
`)
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
10
vendor/github.com/SvenDowideit/cpuid/cpuid.go
generated
vendored
10
vendor/github.com/SvenDowideit/cpuid/cpuid.go
generated
vendored
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user