1
0
mirror of https://github.com/rancher/os.git synced 2025-07-19 17:39:04 +00:00

Add proper vmware cloud-init datasource from guestinfo

Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
Sven Dowideit 2017-06-17 22:56:25 +10:00
parent e37b7c5331
commit 51aff79c7e
4 changed files with 27 additions and 21 deletions

View File

@ -39,6 +39,7 @@ import (
"github.com/rancher/os/config/cloudinit/datasource/metadata/packet"
"github.com/rancher/os/config/cloudinit/datasource/proccmdline"
"github.com/rancher/os/config/cloudinit/datasource/url"
"github.com/rancher/os/config/cloudinit/datasource/vmware"
"github.com/rancher/os/config/cloudinit/pkg"
"github.com/rancher/os/log"
"github.com/rancher/os/netconf"
@ -229,7 +230,7 @@ func getDatasources(datasources []string) []datasource.Datasource {
switch parts[0] {
case "*":
dss = append(dss, getDatasources([]string{"configdrive", "ec2", "digitalocean", "packet", "gce"})...)
dss = append(dss, getDatasources([]string{"configdrive", "vmware", "ec2", "digitalocean", "packet", "gce"})...)
case "ec2":
dss = append(dss, ec2.NewDatasource(root))
case "file":
@ -256,6 +257,8 @@ func getDatasources(datasources []string) []datasource.Datasource {
dss = append(dss, gce.NewDatasource(root))
case "packet":
dss = append(dss, packet.NewDatasource(root))
case "vmware":
dss = append(dss, vmware.NewDatasource(root))
}
}

View File

@ -131,19 +131,19 @@ func (v VMWare) FetchMetadata() (metadata datasource.Metadata, err error) {
}
func (v VMWare) FetchUserdata() ([]byte, error) {
encoding, err := v.readConfig("coreos.config.data.encoding")
encoding, err := v.readConfig("cloud-init.data.encoding")
if err != nil {
return nil, err
}
data, err := v.readConfig("coreos.config.data")
data, err := v.readConfig("cloud-init.config.data")
if err != nil {
return nil, err
}
// Try to fallback to url if no explicit data
if data == "" {
url, err := v.readConfig("coreos.config.url")
url, err := v.readConfig("cloud-init.config.url")
if err != nil {
return nil, err
}

View File

@ -50,19 +50,20 @@ When this service is run, the `EXTRA_CMDLINE` will be set.
Valid cloud-init datasources for RancherOS.
| type | default |
| type | default | |
|---|---|--|
| ec2 | ec2's DefaultAddress |
| file | path |
| cmdline | /media/config-2 |
| configdrive | |
| digitalocean | DefaultAddress |
| ec2 | DefaultAddress |
| file | path |
| gce | |
| packet | DefaultAddress |
| url | url |
| * | This will add ["configdrive", "ec2", "digitalocean", "packet", "gce"] into the list of datasources to try |
| ec2 | ec2's DefaultAddress | |
| file | path | |
| cmdline | /media/config-2 | |
| configdrive | | |
| digitalocean | DefaultAddress | |
| ec2 | DefaultAddress | |
| file | path | |
| gce | | |
| packet | DefaultAddress | |
| url | url | |
| vmware | | set `guestinfo.cloud-init.data.data`, `guestinfo.cloud-init.data.encoding`, or `guestinfo.cloud-init.data.url` |
| * | This will add ["configdrive", "vmware", "ec2", "digitalocean", "packet", "gce"] into the list of datasources to try | |
### Cloud-Config

View File

@ -300,6 +300,11 @@ func RunInit() error {
}},
config.CfgFuncData{"cloud-init", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
cfg.Rancher.CloudInit.Datasources = config.LoadConfigWithPrefix(state).Rancher.CloudInit.Datasources
hypervisor := checkHypervisor(cfg)
if hypervisor == "vmware" {
// add vmware to the end - we don't want to over-ride an choices the user has made
cfg.Rancher.CloudInit.Datasources = append(cfg.Rancher.CloudInit.Datasources, hypervisor)
}
if err := config.Set("rancher.cloud_init.datasources", cfg.Rancher.CloudInit.Datasources); err != nil {
log.Error(err)
}
@ -362,10 +367,6 @@ func RunInit() error {
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 {
@ -409,7 +410,7 @@ func RunInit() error {
return pidOne()
}
func checkHypervisor() {
func checkHypervisor(cfg *config.CloudConfig) string {
hvtools := cpuid.CPU.HypervisorName
if hvtools != "" {
log.Infof("Detected Hypervisor: %s", cpuid.CPU.HypervisorName)
@ -421,4 +422,5 @@ func checkHypervisor() {
log.Error(err)
}
}
return cpuid.CPU.HypervisorName
}