summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cloudinit/DataSourceEc2.py22
-rw-r--r--doc/examples/cloud-config-datasources.txt10
2 files changed, 30 insertions, 2 deletions
diff --git a/cloudinit/DataSourceEc2.py b/cloudinit/DataSourceEc2.py
index 9c385c6c..9f1cf840 100644
--- a/cloudinit/DataSourceEc2.py
+++ b/cloudinit/DataSourceEc2.py
@@ -80,7 +80,25 @@ class DataSourceEc2(DataSource.DataSource):
return fallback
- def wait_for_metadata_service(self, sleeps = 100):
+ def wait_for_metadata_service(self, sleeps = None):
+ mcfg = self.ds_cfg
+ if sleeps is None:
+ sleeps = 30
+ try:
+ sleeps = int(mcfg.get("retries",sleeps))
+ except Exception as e:
+ util.logexc(log)
+ log.warn("Failed to get number of sleeps, using %s" % sleeps)
+
+ if sleeps == 0: return False
+
+ timeout=2
+ try:
+ timeout = int(mcfg.get("timeout",timeout))
+ except Exception as e:
+ util.logexc(log)
+ log.warn("Failed to get timeout, using %s" % timeout)
+
sleeptime = 1
address = '169.254.169.254'
starttime = time.time()
@@ -93,7 +111,7 @@ class DataSourceEc2(DataSource.DataSource):
reason = ""
try:
req = urllib2.Request(url)
- resp = urllib2.urlopen(req, timeout=2)
+ resp = urllib2.urlopen(req, timeout=timeout)
if resp.read() != "": return True
reason = "empty data [%s]" % resp.getcode()
except urllib2.HTTPError as e:
diff --git a/doc/examples/cloud-config-datasources.txt b/doc/examples/cloud-config-datasources.txt
new file mode 100644
index 00000000..3333792e
--- /dev/null
+++ b/doc/examples/cloud-config-datasources.txt
@@ -0,0 +1,10 @@
+# Documentation on data sources configuration options
+datasource:
+ # Ec2
+ Ec2:
+ # timeout: the timeout value for attempt at metadata service
+ timeout : 2
+ # the number of tries that should be attempted at the metadata service
+ # after each try, a sleep of int(try_number/5)+1 is done
+ # default sleep is 30
+ retries : 30