Skip to content

Commit e8b6c69

Browse files
rancher-sy-botniusmallnan
authored andcommitted
ignore vmware datasource when guestinfo is empty
1 parent ab4e0e5 commit e8b6c69

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

config/cloudinit/datasource/vmware/vmware_amd64.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,14 @@ func (v VMWare) IsAvailable() bool {
7878
}
7979
if v.ovfFileName != "" {
8080
_, v.lastError = os.Stat(v.ovfFileName)
81-
return !os.IsNotExist(v.lastError)
81+
if !os.IsNotExist(v.lastError) {
82+
// when GuestInfo is empty, the DataSource should not be available.
83+
return v.checkGuestInfo()
84+
}
85+
return false
8286
}
83-
return vmcheck.IsVirtualWorld()
87+
// when GuestInfo is empty, the DataSource should not be available.
88+
return vmcheck.IsVirtualWorld() && v.checkGuestInfo()
8489
}
8590

8691
func readConfig(key string) (string, error) {
@@ -107,3 +112,23 @@ func urlDownload(url string) ([]byte, error) {
107112
client := pkg.NewHTTPClient()
108113
return client.GetRetry(url)
109114
}
115+
116+
func (v VMWare) checkGuestInfo() bool {
117+
userData, err := v.FetchUserdata()
118+
if err == nil && string(userData) != "" {
119+
return true
120+
}
121+
metadata, err := v.FetchMetadata()
122+
if err == nil {
123+
if metadata.Hostname != "" {
124+
return true
125+
}
126+
if len(metadata.NetworkConfig.DNS.Nameservers) > 0 || len(metadata.NetworkConfig.DNS.Search) > 0 {
127+
return true
128+
}
129+
if len(metadata.NetworkConfig.Interfaces) > 0 {
130+
return true
131+
}
132+
}
133+
return false
134+
}

0 commit comments

Comments
 (0)