summaryrefslogtreecommitdiff
path: root/cloudinit/DataSourceEc2.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2010-05-05 10:48:48 -0400
committerScott Moser <smoser@ubuntu.com>2010-05-05 10:48:48 -0400
commitbec9d097ebcbc5e8d595990d8cbcbb30f433e2fb (patch)
treeca4445ec465d57a7151f83efea0a8869626350b4 /cloudinit/DataSourceEc2.py
parentbc0a5f24f95a47a7f846233e1fdda65bdb3d607e (diff)
downloadvyos-cloud-init-bec9d097ebcbc5e8d595990d8cbcbb30f433e2fb.tar.gz
vyos-cloud-init-bec9d097ebcbc5e8d595990d8cbcbb30f433e2fb.zip
wait considerably longer (1050 seconds) for metadata service to come up
Also - adds some debugging information when its waiting - add 'uptime' printout on initial cloud-init invocation
Diffstat (limited to 'cloudinit/DataSourceEc2.py')
-rw-r--r--cloudinit/DataSourceEc2.py40
1 files changed, 29 insertions, 11 deletions
diff --git a/cloudinit/DataSourceEc2.py b/cloudinit/DataSourceEc2.py
index aeab7d5a..750baab3 100644
--- a/cloudinit/DataSourceEc2.py
+++ b/cloudinit/DataSourceEc2.py
@@ -20,6 +20,7 @@ import cloudinit
import socket
import urllib2
import time
+import sys
import boto_utils
class DataSourceEc2(DataSource.DataSource):
@@ -100,20 +101,37 @@ class DataSourceEc2(DataSource.DataSource):
except:
return 'http://archive.ubuntu.com/ubuntu/'
- def wait_for_metadata_service(self, sleeps = 10):
+
+ def wait_for_metadata_service(self, sleeps = 100):
sleeptime = 1
+ address = '169.254.169.254'
+ starttime = time.time()
+
+ url="http://%s/%s/meta-data/instance-id" % (address,self.api_ver)
for x in range(sleeps):
- s = socket.socket()
+ # given 100 sleeps, this ends up total sleep time of 1050 sec
+ sleeptime=int(x/5)+1
+
+ reason = ""
try:
- address = '169.254.169.254'
- port = 80
- s.connect((address,port))
- s.close()
- return True
- except socket.error, e:
- print "sleeping %s" % sleeptime
- time.sleep(sleeptime)
- #timeout = timeout * 2
+ req = urllib2.Request(url)
+ resp = urllib2.urlopen(req, timeout=2)
+ if resp.read() != "": return True
+ reason = "empty data [%s]" % resp.getcode()
+ except urllib2.HTTPError, e:
+ reason = "http error [%s]" % e.code
+ except urllib2.URLError, e:
+ reason = "url error [%s]" % e.reason
+
+ if x == 0:
+ sys.stderr.write("waiting for metadata service at %s\n" % url)
+
+ sys.stderr.write(" %s [%02s/%s]: %s\n" %
+ (time.strftime("%H:%M:%S"), x+1, sleeps, reason))
+ time.sleep(sleeptime)
+
+ sys.stderr.write("giving up on md after %i seconds\n" %
+ int(time.time()-starttime))
return False
def get_public_ssh_keys(self):