summaryrefslogtreecommitdiff
path: root/cloudinit/sources/DataSourceGCE.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2014-02-12 19:58:38 -0500
committerScott Moser <smoser@ubuntu.com>2014-02-12 19:58:38 -0500
commit065287bd56fe7f63a8dc41fa1457be4439f20efd (patch)
tree393943d68f45d7da8ae4ca6303dac13ee16ffbb3 /cloudinit/sources/DataSourceGCE.py
parentaa1d0328da6ae1ace03e327feafabcf84f91b2b5 (diff)
downloadvyos-cloud-init-065287bd56fe7f63a8dc41fa1457be4439f20efd.tar.gz
vyos-cloud-init-065287bd56fe7f63a8dc41fa1457be4439f20efd.zip
support configuration of MD_URL, disable if not resolvable.
this allows the metadata url to be configured by setting: datasource: GCE: metadata_url: <value> Then also, if its not resolvable, we just deactivate the datasource quickly.
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)