mirror of
https://github.com/rancher/os.git
synced 2025-07-19 09:26:27 +00:00
Add proper vmware cloud-init datasource from guestinfo
Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
parent
e37b7c5331
commit
51aff79c7e
@ -39,6 +39,7 @@ import (
|
|||||||
"github.com/rancher/os/config/cloudinit/datasource/metadata/packet"
|
"github.com/rancher/os/config/cloudinit/datasource/metadata/packet"
|
||||||
"github.com/rancher/os/config/cloudinit/datasource/proccmdline"
|
"github.com/rancher/os/config/cloudinit/datasource/proccmdline"
|
||||||
"github.com/rancher/os/config/cloudinit/datasource/url"
|
"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/config/cloudinit/pkg"
|
||||||
"github.com/rancher/os/log"
|
"github.com/rancher/os/log"
|
||||||
"github.com/rancher/os/netconf"
|
"github.com/rancher/os/netconf"
|
||||||
@ -229,7 +230,7 @@ func getDatasources(datasources []string) []datasource.Datasource {
|
|||||||
|
|
||||||
switch parts[0] {
|
switch parts[0] {
|
||||||
case "*":
|
case "*":
|
||||||
dss = append(dss, getDatasources([]string{"configdrive", "ec2", "digitalocean", "packet", "gce"})...)
|
dss = append(dss, getDatasources([]string{"configdrive", "vmware", "ec2", "digitalocean", "packet", "gce"})...)
|
||||||
case "ec2":
|
case "ec2":
|
||||||
dss = append(dss, ec2.NewDatasource(root))
|
dss = append(dss, ec2.NewDatasource(root))
|
||||||
case "file":
|
case "file":
|
||||||
@ -256,6 +257,8 @@ func getDatasources(datasources []string) []datasource.Datasource {
|
|||||||
dss = append(dss, gce.NewDatasource(root))
|
dss = append(dss, gce.NewDatasource(root))
|
||||||
case "packet":
|
case "packet":
|
||||||
dss = append(dss, packet.NewDatasource(root))
|
dss = append(dss, packet.NewDatasource(root))
|
||||||
|
case "vmware":
|
||||||
|
dss = append(dss, vmware.NewDatasource(root))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,19 +131,19 @@ func (v VMWare) FetchMetadata() (metadata datasource.Metadata, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v VMWare) FetchUserdata() ([]byte, 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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := v.readConfig("coreos.config.data")
|
data, err := v.readConfig("cloud-init.config.data")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to fallback to url if no explicit data
|
// Try to fallback to url if no explicit data
|
||||||
if data == "" {
|
if data == "" {
|
||||||
url, err := v.readConfig("coreos.config.url")
|
url, err := v.readConfig("cloud-init.config.url")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -50,19 +50,20 @@ When this service is run, the `EXTRA_CMDLINE` will be set.
|
|||||||
|
|
||||||
Valid cloud-init datasources for RancherOS.
|
Valid cloud-init datasources for RancherOS.
|
||||||
|
|
||||||
| type | default |
|
| type | default | |
|
||||||
|---|---|--|
|
|---|---|--|
|
||||||
| ec2 | ec2's DefaultAddress |
|
| ec2 | ec2's DefaultAddress | |
|
||||||
| file | path |
|
| file | path | |
|
||||||
| cmdline | /media/config-2 |
|
| cmdline | /media/config-2 | |
|
||||||
| configdrive | |
|
| configdrive | | |
|
||||||
| digitalocean | DefaultAddress |
|
| digitalocean | DefaultAddress | |
|
||||||
| ec2 | DefaultAddress |
|
| ec2 | DefaultAddress | |
|
||||||
| file | path |
|
| file | path | |
|
||||||
| gce | |
|
| gce | | |
|
||||||
| packet | DefaultAddress |
|
| packet | DefaultAddress | |
|
||||||
| url | url |
|
| url | url | |
|
||||||
| * | This will add ["configdrive", "ec2", "digitalocean", "packet", "gce"] into the list of datasources to try |
|
| 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
|
### Cloud-Config
|
||||||
|
|
||||||
|
12
init/init.go
12
init/init.go
@ -300,6 +300,11 @@ func RunInit() error {
|
|||||||
}},
|
}},
|
||||||
config.CfgFuncData{"cloud-init", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
|
config.CfgFuncData{"cloud-init", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
|
||||||
cfg.Rancher.CloudInit.Datasources = config.LoadConfigWithPrefix(state).Rancher.CloudInit.Datasources
|
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 {
|
if err := config.Set("rancher.cloud_init.datasources", cfg.Rancher.CloudInit.Datasources); err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
@ -362,10 +367,6 @@ func RunInit() error {
|
|||||||
|
|
||||||
return cfg, nil
|
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) {
|
config.CfgFuncData{"b2d Env", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
|
||||||
|
|
||||||
if boot2DockerEnvironment {
|
if boot2DockerEnvironment {
|
||||||
@ -409,7 +410,7 @@ func RunInit() error {
|
|||||||
return pidOne()
|
return pidOne()
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkHypervisor() {
|
func checkHypervisor(cfg *config.CloudConfig) string {
|
||||||
hvtools := cpuid.CPU.HypervisorName
|
hvtools := cpuid.CPU.HypervisorName
|
||||||
if hvtools != "" {
|
if hvtools != "" {
|
||||||
log.Infof("Detected Hypervisor: %s", cpuid.CPU.HypervisorName)
|
log.Infof("Detected Hypervisor: %s", cpuid.CPU.HypervisorName)
|
||||||
@ -421,4 +422,5 @@ func checkHypervisor() {
|
|||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return cpuid.CPU.HypervisorName
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user