File tree Expand file tree Collapse file tree 1 file changed +27
-2
lines changed
config/cloudinit/datasource/vmware Expand file tree Collapse file tree 1 file changed +27
-2
lines changed Original file line number Diff line number Diff 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
8691func 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+ }
You can’t perform that action at this time.
0 commit comments