diff options
author | Scott Moser <smoser@ubuntu.com> | 2011-02-07 13:09:42 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2011-02-07 13:09:42 -0500 |
commit | 48564dc9cab705a675cc4751db13af158507e358 (patch) | |
tree | 91003a8a5ac173b4d50310521469a98bbe8464a3 | |
parent | 53173904c3bf539097efa4a7d88223e75dd8d103 (diff) | |
download | vyos-cloud-init-48564dc9cab705a675cc4751db13af158507e358.tar.gz vyos-cloud-init-48564dc9cab705a675cc4751db13af158507e358.zip |
make DataSourceEc2 configurable (timeout, retries), lower default retries
This lowers the default retries from 100 to 30 (1050 seconds to 105 seconds)
-rw-r--r-- | cloudinit/DataSourceEc2.py | 22 | ||||
-rw-r--r-- | doc/examples/cloud-config-datasources.txt | 10 |
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 |