diff --git a/config/cloudinit/datasource/vmware/vmware_amd64.go b/config/cloudinit/datasource/vmware/vmware_amd64.go index a0b71c27..41cfc8dd 100644 --- a/config/cloudinit/datasource/vmware/vmware_amd64.go +++ b/config/cloudinit/datasource/vmware/vmware_amd64.go @@ -78,9 +78,14 @@ func (v VMWare) IsAvailable() bool { } if v.ovfFileName != "" { _, v.lastError = os.Stat(v.ovfFileName) - return !os.IsNotExist(v.lastError) + if !os.IsNotExist(v.lastError) { + // when GuestInfo is empty, the DataSource should not be available. + return v.checkGuestInfo() + } + return false } - return vmcheck.IsVirtualWorld() + // when GuestInfo is empty, the DataSource should not be available. + return vmcheck.IsVirtualWorld() && v.checkGuestInfo() } func readConfig(key string) (string, error) { @@ -107,3 +112,23 @@ func urlDownload(url string) ([]byte, error) { client := pkg.NewHTTPClient() return client.GetRetry(url) } + +func (v VMWare) checkGuestInfo() bool { + userData, err := v.FetchUserdata() + if err == nil && string(userData) != "" { + return true + } + metadata, err := v.FetchMetadata() + if err == nil { + if metadata.Hostname != "" { + return true + } + if len(metadata.NetworkConfig.DNS.Nameservers) > 0 || len(metadata.NetworkConfig.DNS.Search) > 0 { + return true + } + if len(metadata.NetworkConfig.Interfaces) > 0 { + return true + } + } + return false +}