summaryrefslogtreecommitdiff
path: root/cloudinit/sources/DataSourceGCE.py
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit/sources/DataSourceGCE.py')
-rw-r--r--cloudinit/sources/DataSourceGCE.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/cloudinit/sources/DataSourceGCE.py b/cloudinit/sources/DataSourceGCE.py
index c96cfffd..6eb3da4d 100644
--- a/cloudinit/sources/DataSourceGCE.py
+++ b/cloudinit/sources/DataSourceGCE.py
@@ -16,19 +16,25 @@
from cloudinit import log as logging
+from cloudinit import util
from cloudinit import sources
from cloudinit import url_helper
LOG = logging.getLogger(__name__)
-MD_URL = 'http://metadata/computeMetadata/v1/'
+BUILTIN_DS_CONFIG = {
+ 'metadata_url': 'http://metadata.google.internal./computeMetadata/v1/'
+}
class DataSourceGCE(sources.DataSource):
def __init__(self, sys_cfg, distro, paths):
sources.DataSource.__init__(self, sys_cfg, distro, paths)
- self.metadata_address = MD_URL
self.metadata = {}
+ self.ds_cfg = util.mergemanydict([
+ util.get_cfg_by_path(sys_cfg, ["datasource", "GCE"], {}),
+ BUILTIN_DS_CONFIG])
+ self.metadata_address = self.ds_cfg['metadata_url']
# GCE takes sshKeys attribute in the format of '<user>:<public_key>'
# so we have to trim each key to remove the username part
@@ -51,6 +57,11 @@ class DataSourceGCE(sources.DataSource):
'local-hostname': self.metadata_address + 'instance/hostname',
}
+ # if we cannot resolve the metadata server, then no point in trying
+ if not util.is_resolvable(self.metadata_address):
+ LOG.debug("%s is not resolvable", self.metadata_address)
+ return False
+
for mkey in url_map.iterkeys():
try:
resp = url_helper.readurl(url=url_map[mkey], headers=headers)