summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorkeyz182 <keyz182@gmail.com>2011-05-24 12:46:34 +0100
committerkeyz182 <keyz182@gmail.com>2011-05-24 12:46:34 +0100
commit2c20e675de5c7f840b75f023bf65802fa010fd37 (patch)
tree818f2ca7ff2c7fa59154986a38b09b06cb183d40 /cloudinit
parentf613aba32e7652a27f744d27c2d000831723023c (diff)
downloadvyos-cloud-init-2c20e675de5c7f840b75f023bf65802fa010fd37.tar.gz
vyos-cloud-init-2c20e675de5c7f840b75f023bf65802fa010fd37.zip
Modified cloudinit/DataSourceEc2.py and cloudinit/boto_utils.py to check both http://169.254.169.254 and http://instance-data:8773 for meta data service.
LP: #761847
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/DataSourceEc2.py48
-rw-r--r--cloudinit/boto_utils.py8
2 files changed, 30 insertions, 26 deletions
diff --git a/cloudinit/DataSourceEc2.py b/cloudinit/DataSourceEc2.py
index 9f1cf840..289fa425 100644
--- a/cloudinit/DataSourceEc2.py
+++ b/cloudinit/DataSourceEc2.py
@@ -31,6 +31,7 @@ import errno
class DataSourceEc2(DataSource.DataSource):
api_ver = '2009-04-04'
seeddir = seeddir + '/ec2'
+ metadata_address = "169.254.169.254"
def __str__(self):
return("DataSourceEc2")
@@ -46,8 +47,8 @@ class DataSourceEc2(DataSource.DataSource):
try:
if not self.wait_for_metadata_service():
return False
- self.userdata_raw = boto_utils.get_instance_userdata(self.api_ver)
- self.metadata = boto_utils.get_instance_metadata(self.api_ver)
+ self.userdata_raw = boto_utils.get_instance_userdata(metadata_address,self.api_ver)
+ self.metadata = boto_utils.get_instance_metadata(metadata_address,self.api_ver)
return True
except Exception as e:
print e
@@ -100,30 +101,33 @@ class DataSourceEc2(DataSource.DataSource):
log.warn("Failed to get timeout, using %s" % timeout)
sleeptime = 1
- address = '169.254.169.254'
+ addresslist = ['169.254.169.254', "instance-data"]
starttime = time.time()
- url="http://%s/%s/meta-data/instance-id" % (address,self.api_ver)
for x in range(sleeps):
- # given 100 sleeps, this ends up total sleep time of 1050 sec
- sleeptime=int(x/5)+1
-
- reason = ""
- try:
- req = urllib2.Request(url)
- resp = urllib2.urlopen(req, timeout=timeout)
- if resp.read() != "": return True
- reason = "empty data [%s]" % resp.getcode()
- except urllib2.HTTPError as e:
- reason = "http error [%s]" % e.code
- except urllib2.URLError as e:
- reason = "url error [%s]" % e.reason
-
- if x == 0:
- log.warning("waiting for metadata service at %s\n" % url)
+ for address in addresslist:
+ url="http://%s/%s/meta-data/instance-id" % (address,self.api_ver)
+ # given 100 sleeps, this ends up total sleep time of 1050 sec
+ sleeptime=int(x/5)+1
+
+ reason = ""
+ try:
+ req = urllib2.Request(url)
+ resp = urllib2.urlopen(req, timeout=timeout)
+ if resp.read() != "":
+ metadata_address = address
+ return True
+ reason = "empty data [%s]" % resp.getcode()
+ except urllib2.HTTPError as e:
+ reason = "http error [%s]" % e.code
+ except urllib2.URLError as e:
+ reason = "url error [%s]" % e.reason
+
+ if x == 0:
+ log.warning("waiting for metadata service at %s\n" % url)
- log.warning(" %s [%02s/%s]: %s\n" %
- (time.strftime("%H:%M:%S",time.gmtime()), x+1, sleeps, reason))
+ log.warning(" %s [%02s/%s]: %s\n" %
+ (time.strftime("%H:%M:%S",time.gmtime()), x+1, sleeps, reason))
time.sleep(sleeptime)
log.critical("giving up on md after %i seconds\n" %
diff --git a/cloudinit/boto_utils.py b/cloudinit/boto_utils.py
index b38483fa..8eb7a575 100644
--- a/cloudinit/boto_utils.py
+++ b/cloudinit/boto_utils.py
@@ -60,7 +60,7 @@ def retry_url(url, retry_on_404=True):
sys.stderr.write('Caught exception reading instance data, giving up\n')
return ''
-def get_instance_metadata(version='latest'):
+def get_instance_metadata(url='169.254.169.254',version='latest'):
"""
Returns the instance metadata as a nested Python dictionary.
Simple values (e.g. local_hostname, hostname, etc.) will be
@@ -68,11 +68,11 @@ def get_instance_metadata(version='latest'):
be stored in the dict as a list of string values. More complex
fields such as public-keys and will be stored as nested dicts.
"""
- url = 'http://169.254.169.254/%s/meta-data/' % version
+ url = 'http://%s/%s/meta-data/' % (url,version)
return _get_instance_metadata(url)
-def get_instance_userdata(version='latest', sep=None):
- url = 'http://169.254.169.254/%s/user-data' % version
+def get_instance_userdata(url='169.254.169.254',version='latest', sep=None):
+ url = 'http://%s/%s/user-data' % (url,version)
user_data = retry_url(url, retry_on_404=False)
if user_data:
if sep: