diff options
author | keyz182 <keyz182@gmail.com> | 2011-05-25 11:48:41 +0100 |
---|---|---|
committer | keyz182 <keyz182@gmail.com> | 2011-05-25 11:48:41 +0100 |
commit | 25dc96dafb3ea94d4f798990bcf26825855f899b (patch) | |
tree | ab9dcb7677e13b61bb4a5531271a996a7511c5c9 | |
parent | 707a01fb1af5c8c493b021b782d73d01cd018ae4 (diff) | |
download | vyos-cloud-init-25dc96dafb3ea94d4f798990bcf26825855f899b.tar.gz vyos-cloud-init-25dc96dafb3ea94d4f798990bcf26825855f899b.zip |
Modified to reflect changes suggested by Scott Moser
-rw-r--r-- | cloudinit/DataSourceEc2.py | 18 | ||||
-rw-r--r-- | cloudinit/boto_utils.py | 8 |
2 files changed, 16 insertions, 10 deletions
diff --git a/cloudinit/DataSourceEc2.py b/cloudinit/DataSourceEc2.py index 38284463..2bf7ea8c 100644 --- a/cloudinit/DataSourceEc2.py +++ b/cloudinit/DataSourceEc2.py @@ -47,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(metadata_address,self.api_ver) - self.metadata = boto_utils.get_instance_metadata(metadata_address,self.api_ver) + self.userdata_raw = boto_utils.get_instance_userdata(self.api_ver,None,metadata_address) + self.metadata = boto_utils.get_instance_metadata(self.api_ver,metadata_address) return True except Exception as e: print e @@ -101,27 +101,33 @@ class DataSourceEc2(DataSource.DataSource): log.warn("Failed to get timeout, using %s" % timeout) sleeptime = 1 - addresslist = ['169.254.169.254', "instance-data:8773"] + addresslist = [['169.254.169.254',80], ["instance-data",8773]] starttime = time.time() for x in range(sleeps): for address in addresslist: - url="http://%s/%s/meta-data/instance-id" % (address,self.api_ver) + host="http://%s:%i/" % (address[0],address[1]) + url="%s%s/meta-data/instance-id" % (host,self.api_ver) + # given 100 sleeps, this ends up total sleep time of 1050 sec sleeptime=int(x/5)+1 - + + reason = "" try: + socket.getaddrinfo(address[0],address[1]) req = urllib2.Request(url) resp = urllib2.urlopen(req, timeout=timeout) if resp.read() != "": - metadata_address = address + metadata_address = host 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 + except socket.gaierror as e: + reason = "url error [%s]" % e if x == 0: log.warning("waiting for metadata service at %s\n" % url) diff --git a/cloudinit/boto_utils.py b/cloudinit/boto_utils.py index 8eb7a575..e60e804d 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(url='169.254.169.254',version='latest'): +def get_instance_metadata(version='latest',url='http://169.254.169.254/'): """ 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(url='169.254.169.254',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://%s/%s/meta-data/' % (url,version) + url = '%s%s/meta-data/' % (url,version) return _get_instance_metadata(url) -def get_instance_userdata(url='169.254.169.254',version='latest', sep=None): - url = 'http://%s/%s/user-data' % (url,version) +def get_instance_userdata(version='latest', sep=None,url='http://169.254.169.254/'): + url = '%s%s/user-data' % (url,version) user_data = retry_url(url, retry_on_404=False) if user_data: if sep: |