diff options
author | Scott Moser <smoser@brickies.net> | 2017-03-27 12:43:15 -0400 |
---|---|---|
committer | Scott Moser <smoser@brickies.net> | 2017-03-27 16:43:25 -0400 |
commit | 328fe5ab399b1f5b48d1985f41fc2ef66e368922 (patch) | |
tree | 97408b3b7d18aa783d55d9f3c522026e661a326d /cloudinit/sources | |
parent | 21632972df034c200578e1fbc121a07f20bb8774 (diff) | |
download | vyos-cloud-init-328fe5ab399b1f5b48d1985f41fc2ef66e368922.tar.gz vyos-cloud-init-328fe5ab399b1f5b48d1985f41fc2ef66e368922.zip |
GCE: Search GCE in ds-identify, consider serial number in check.
While documentation indicates that the smbios product name should
contain 'Google Compute Engine', experimentation and bug reports
indicate that is not always the case. The change here is to change
the check for GCE to also consider a serial number that starts with
'GoogleCompute-'.
Also, ds-identify was not currently searching for GCE if no config of
datasource_list was found. Most images have a datasource_list defined.
So update the list to include GCE.
LP: #1674861
Diffstat (limited to 'cloudinit/sources')
-rw-r--r-- | cloudinit/sources/DataSourceGCE.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/cloudinit/sources/DataSourceGCE.py b/cloudinit/sources/DataSourceGCE.py index b1a1c8f2..637c9505 100644 --- a/cloudinit/sources/DataSourceGCE.py +++ b/cloudinit/sources/DataSourceGCE.py @@ -62,6 +62,9 @@ class DataSourceGCE(sources.DataSource): return public_key def get_data(self): + if not platform_reports_gce(): + return False + # url_map: (our-key, path, required, is_text) url_map = [ ('instance-id', ('instance/id',), True, True), @@ -144,6 +147,21 @@ class DataSourceGCE(sources.DataSource): return self.availability_zone.rsplit('-', 1)[0] +def platform_reports_gce(): + pname = util.read_dmi_data('system-product-name') or "N/A" + if pname == "Google Compute Engine": + return True + + # system-product-name is not always guaranteed (LP: #1674861) + serial = util.read_dmi_data('system-serial-number') or "N/A" + if serial.startswith("GoogleCloud-"): + return True + + LOG.debug("Not running on google cloud. product-name=%s serial=%s", + pname, serial) + return False + + # Used to match classes to dependencies datasources = [ (DataSourceGCE, (sources.DEP_FILESYSTEM, sources.DEP_NETWORK)), |